Skip to content

Commit 5b86137

Browse files
fixup! pkg/xipfs: add MPU memory isolation to file execution
1 parent 451bd5a commit 5b86137

File tree

5 files changed

+27
-25
lines changed

5 files changed

+27
-25
lines changed

cpu/cortexm_common/include/vectors_cortexm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ void hard_fault_default(void);
9494
/**
9595
* @brief Default memory manager behavior callback (weak function)
9696
*
97-
* @retval 1 when the memory fault has been handled,
98-
* @retval 0 otherwise.
97+
* @retval >=0 when the memory fault has been handled,
98+
* @retval < 0 otherwise.
9999
*/
100100
int mem_manage_handler(void);
101101

cpu/cortexm_common/thread_arch.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
*/
8989

9090
#include <stdio.h>
91+
#include <errno.h>
9192

9293
#include "sched.h"
9394
#include "thread.h"
@@ -493,12 +494,12 @@ void __attribute__((naked)) __attribute__((used)) isr_svc(void)
493494
#endif
494495
}
495496

496-
__attribute__((weak))int
497+
__attribute__((weak)) int
497498
svc_dispatch_handler(unsigned int svc_number, unsigned int *svc_args)
498499
{
499500
(void)svc_number;
500501
(void)svc_args;
501-
return 0;
502+
return -ENOTSUP;
502503
}
503504

504505
static void __attribute__((used)) _svc_dispatch(unsigned int *svc_args)

cpu/cortexm_common/vectors_cortexm.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <stdint.h>
2323
#include <stdio.h>
2424
#include <inttypes.h>
25+
#include <errno.h>
2526

2627
#include "cpu.h"
2728
#include "periph_cpu.h"
@@ -473,14 +474,14 @@ void hard_fault_default(void)
473474
defined(CPU_CORE_CORTEX_M4) || defined(CPU_CORE_CORTEX_M4F) || \
474475
defined(CPU_CORE_CORTEX_M7)
475476

476-
__attribute__((weak))int mem_manage_handler(void)
477+
__attribute__((weak)) int mem_manage_handler(void)
477478
{
478-
return 0;
479+
return -ENOTSUP;
479480
}
480481

481482
void mem_manage_default(void)
482483
{
483-
if (mem_manage_handler() == 1) {
484+
if (mem_manage_handler() >= 0) {
484485
return;
485486
}
486487
core_panic(PANIC_MEM_MANAGE, "MEM MANAGE HANDLER");

examples/advanced/xipfs/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2025 Université de Lille
2+
* Copyright (C) 2024-2025 Université de Lille
33
*
44
* This file is subject to the terms and conditions of the GNU Lesser
55
* General Public License v2.1. See the file LICENSE in the top level
@@ -99,7 +99,7 @@ static int drop_file(const file_to_drop_t *file_to_drop) {
9999
int file_handle = vfs_open(file_to_drop->filename, O_RDONLY, 0);
100100
if (file_handle < 0) {
101101

102-
/** There's no executable file yet, let's drop one */
102+
/* There's no executable file yet, let's drop one */
103103
int ret = xipfs_extended_driver_new_file(
104104
file_to_drop->filename, file_to_drop->bytesize, file_to_drop->is_executable
105105
);
@@ -109,7 +109,7 @@ static int drop_file(const file_to_drop_t *file_to_drop) {
109109
return EXIT_FAILURE;
110110
}
111111

112-
/**
112+
/*
113113
* Fill it with data
114114
* Take care : vfs does not support O_APPEND with vfs_write, only O_WRONLY or O_RDWR
115115
*/

pkg/xipfs/fs/xipfs_fs.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -739,28 +739,28 @@ int mem_manage_handler(void)
739739
uint32_t cfsr = SCB->CFSR;
740740
uintptr_t psp = __get_PSP();
741741
if (xipfs_mem_manage_handler((void *)psp, mmfar, cfsr) == 0) {
742-
return 1;
742+
return 0;
743743
}
744744

745-
return 0;
745+
return -EINVAL;
746746
}
747747

748748
int svc_dispatch_handler(unsigned int svc_number, unsigned int *svc_args)
749749
{
750750
switch (svc_number) {
751-
case XIPFS_ENTER_SVC_NUMBER: {
752-
void *crt0_ctx = (void *)svc_args[0];
753-
void *entry_point = (void *)svc_args[1];
754-
void *stack_top = (void *)svc_args[2];
755-
xipfs_safe_exec_enter(crt0_ctx, entry_point, stack_top);
756-
return 0;
757-
}
758-
case XIPFS_SYSCALL_SVC_NUMBER: {
759-
xipfs_syscall_dispatcher(svc_args);
760-
return 0;
761-
}
762-
default:
763-
return -ENOTSUP;
751+
case XIPFS_ENTER_SVC_NUMBER: {
752+
void *crt0_ctx = (void *)svc_args[0];
753+
void *entry_point = (void *)svc_args[1];
754+
void *stack_top = (void *)svc_args[2];
755+
xipfs_safe_exec_enter(crt0_ctx, entry_point, stack_top);
756+
return 0;
757+
}
758+
case XIPFS_SYSCALL_SVC_NUMBER: {
759+
xipfs_syscall_dispatcher(svc_args);
760+
return 0;
761+
}
762+
default:
763+
return -ENOTSUP;
764764
}
765765
}
766766

0 commit comments

Comments
 (0)