Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions fuzzing/mock/custom/mocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,10 @@ void mainExit(int exitCode)
{
(void) exitCode;
}

unsigned int os_sched_current_task(void);

unsigned int os_sched_current_task(void)
{
return TASK_USER;
}
Binary file modified fuzzing/shared_libs/libnbgl_shared_apex_p.a
Binary file not shown.
Binary file modified fuzzing/shared_libs/libnbgl_shared_flex.a
Binary file not shown.
Binary file modified fuzzing/shared_libs/libnbgl_shared_nanosp.a
Binary file not shown.
Binary file modified fuzzing/shared_libs/libnbgl_shared_nanox.a
Binary file not shown.
Binary file modified fuzzing/shared_libs/libnbgl_shared_stax.a
Binary file not shown.
62 changes: 3 additions & 59 deletions include/os_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,9 @@ typedef unsigned char bolos_task_status_t;
enum task_unsecure_id_e {
TASK_BOLOS = 0, // can call os
TASK_SYSCALL, // can call os
TASK_USERTASKS_START,
// disabled for now // TASK_USER_UX, // must call syscalls to reach os, locked in ux ram
TASK_USER = TASK_USERTASKS_START, // must call syscalls to reach os, locked in app ram
TASK_SUBTASKS_START,
TASK_SUBTASK_0 = TASK_SUBTASKS_START,
#ifdef TARGET_NANOX
TASK_SUBTASK_1,
TASK_SUBTASK_2,
TASK_SUBTASK_3,
#endif // TARGET_NANOX
TASK_BOLOS_UX,
TASK_MAXCOUNT, // must be last in the structure
TASK_USER, // must call syscalls to reach os, locked in app ram
TASK_BOLOS_UX, // must call syscalls to reach os
TASK_MAXCOUNT // must be last in the structure
};

// exit the current task
Expand All @@ -31,54 +22,7 @@ SYSCALL void os_sched_exit(bolos_task_status_t exit_code);
SYSCALL void __attribute__((noreturn)) os_sched_exit(bolos_task_status_t exit_code);
#endif

// returns true when the given task is running, false else.
SYSCALL bolos_bool_t os_sched_is_running(unsigned int task_idx);

/**
* Retrieve the last status issued by a task using either yield or exit.
*/
SUDOCALL bolos_task_status_t os_sched_last_status(unsigned int task_idx);

/**
* Current task is yielding the process to another task.
* Meta call for task_switch with 'the enxt' task idx.
* @param status is the current task status
*/
SUDOCALL TASKSWITCH void os_sched_yield(bolos_task_status_t status);

/**
* Perform task switching
* @param task_idx is the task index to switch to
* @param status of the currently executed task
* @return the status of the previously running task
*/
SUDOCALL TASKSWITCH void os_sched_switch(unsigned int task_idx, bolos_task_status_t status);

/**
* Function that returns the currently running task identifier.
*/
SUDOCALL unsigned int os_sched_current_task(void);

/**
* Create a new task with the given parameters and return its task identifier.
* The newly created task is chrooted in the given nvram/ram1/ram2 segments
* and its task pointer is set at the end of ram1 segment.
* The task is bound to the currently running application.
* The task identifiers are not guaranteed to be the same after a power cycle.
* At least valid main, nvram segment, ram0 segment and stack segment must be provided with.
* @param main The main function address to start the task with.
* @param nvram The nvram segment address start
* @param nvram_length The nvram segment length
* @param ram0 /ram0_length the first RAM segment description
* @param stack /stack_length the task's stack RAM segment description
*/
SYSCALL unsigned int os_sched_create(void *main PLENGTH(4),
void *nvram PLENGTH(nvram_length),
unsigned int nvram_length,
void *ram0 PLENGTH(ram0_length),
unsigned int ram0_length,
void *stack PLENGTH(stack_length),
unsigned int stack_length);

// kill a task
SYSCALL void os_sched_kill(unsigned int taskidx);
2 changes: 0 additions & 2 deletions include/os_ux.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ void bolos_test_ux_apdu(void);
// is not processed. when returning !0 the application must send a general status (or continue its
// command flow)
SYSCALL TASKSWITCH unsigned int os_ux(bolos_ux_params_t *params PLENGTH(sizeof(bolos_ux_params_t)));
// read parameters back from the UX app. useful to read keyboard type or such
SYSCALL void os_ux_result(bolos_ux_params_t *params PLENGTH(sizeof(bolos_ux_params_t)));

// process all possible messages while waiting for a ux to finish,
// unprocessed messages are replied with a generic general status
Expand Down
8 changes: 3 additions & 5 deletions include/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@
#define SYSCALL_RESERVED_6_ID 0x00000125
#define SYSCALL_RESERVED_34_ID 0x01000126
#define SYSCALL_os_sched_exit_ID 0x0100009a
#define SYSCALL_os_sched_is_running_ID 0x0100009b
#define SYSCALL_os_sched_create_ID 0x0700011b
#define SYSCALL_os_sched_kill_ID 0x01000078
#define SYSCALL_RESERVED_36_ID 0x0100009b
#define SYSCALL_os_io_seph_tx_ID 0x03000082
#define SYSCALL_os_io_seph_se_rx_event_ID 0x05000083
#define SYSCALL_os_io_init_ID 0x01000084
Expand All @@ -197,9 +195,9 @@
#define SYSCALL_try_context_get_ID 0x00000087
#define SYSCALL_try_context_set_ID 0x0100010b
#define SYSCALL_os_sched_last_status_ID 0x0100009c
#define SYSCALL_os_sched_yield_ID 0x0100009d
#define SYSCALL_RESERVED_38_ID 0x0100009d
#define SYSCALL_os_sched_switch_ID 0x0200009e
#define SYSCALL_os_sched_current_task_ID 0x0000008b
#define SYSCALL_RESERVED_37_ID 0x0000008b
#define SYSCALL_os_allow_protected_flash_ID 0x0000008e
#define SYSCALL_os_deny_protected_flash_ID 0x00000091
#define SYSCALL_os_allow_protected_ram_ID 0x00000092
Expand Down
61 changes: 0 additions & 61 deletions src/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1533,42 +1533,6 @@ void __attribute__((noreturn)) os_sched_exit(bolos_task_status_t exit_code)
__builtin_unreachable();
}

bolos_bool_t os_sched_is_running(unsigned int task_idx)
{
unsigned int parameters[2];
parameters[0] = (unsigned int) task_idx;
parameters[1] = 0;
return (bolos_bool_t) SVC_Call(SYSCALL_os_sched_is_running_ID, parameters);
}

unsigned int os_sched_create(void *main,
void *nvram,
unsigned int nvram_length,
void *ram0,
unsigned int ram0_length,
void *stack,
unsigned int stack_length)
{
unsigned int parameters[7];
parameters[0] = (unsigned int) main;
parameters[1] = (unsigned int) nvram;
parameters[2] = (unsigned int) nvram_length;
parameters[3] = (unsigned int) ram0;
parameters[4] = (unsigned int) ram0_length;
parameters[5] = (unsigned int) stack;
parameters[6] = (unsigned int) stack_length;
return (unsigned int) SVC_Call(SYSCALL_os_sched_create_ID, parameters);
}

void os_sched_kill(unsigned int taskidx)
{
unsigned int parameters[2];
parameters[0] = (unsigned int) taskidx;
parameters[1] = 0;
SVC_Call(SYSCALL_os_sched_kill_ID, parameters);
return;
}

int os_io_seph_tx(const unsigned char *buffer, unsigned short length, unsigned int *timeout_ms)
{
unsigned int parameters[3];
Expand Down Expand Up @@ -1680,31 +1644,6 @@ bolos_task_status_t os_sched_last_status(unsigned int task_idx)
return (bolos_task_status_t) SVC_Call(SYSCALL_os_sched_last_status_ID, parameters);
}

void os_sched_yield(bolos_task_status_t status)
{
unsigned int parameters[2];
parameters[0] = (unsigned int) status;
parameters[1] = 0;
SVC_Call(SYSCALL_os_sched_yield_ID, parameters);
return;
}

void os_sched_switch(unsigned int task_idx, bolos_task_status_t status)
{
unsigned int parameters[2];
parameters[0] = (unsigned int) task_idx;
parameters[1] = (unsigned int) status;
SVC_Call(SYSCALL_os_sched_switch_ID, parameters);
return;
}

unsigned int os_sched_current_task(void)
{
unsigned int parameters[2];
parameters[1] = 0;
return (unsigned int) SVC_Call(SYSCALL_os_sched_current_task_ID, parameters);
}

unsigned int os_allow_protected_ram(void)
{
unsigned int parameters[2];
Expand Down
Binary file not shown.
Binary file modified tests/screenshots/shared_libs/libnbgl_shared_screenshots_flex.a
Binary file not shown.
Binary file modified tests/screenshots/shared_libs/libnbgl_shared_screenshots_nanosp.a
Binary file not shown.
Binary file modified tests/screenshots/shared_libs/libnbgl_shared_screenshots_nanox.a
Binary file not shown.
Binary file modified tests/screenshots/shared_libs/libnbgl_shared_screenshots_stax.a
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/screenshots/src/main/stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ void os_sched_exit(bolos_task_status_t status_code)
exit(-1);
}

unsigned int os_sched_current_task(void);

unsigned int os_sched_current_task(void)
{
return TASK_USER;
Expand Down