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
12 changes: 12 additions & 0 deletions so3/kernel/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,24 @@ extern uint32_t __get_syscall_stack_arg(uint32_t nr);

extern void test_malloc(int test_no);

static long __sys_empty(syscall_args_t *args);

static const syscall_fn_t syscall_table[NR_SYSCALLS] = {
[0 ... NR_SYSCALLS - 1] = NULL,
/* Generated file with table element matching number to functions. */
#include <generated/syscall_table.h.in>
};

/**
* Callback for syscalls with empty implementation to remove the unhandled message for them.
* This is useful as MUSL will use some syscalls that aren't implemented in SO3 due to simplification
* over Linux.
*/
static long __sys_empty(syscall_args_t *args)
{
return -ENOSYS;
}

/*
* Process syscalls according to the syscall number passed in r7 on ARM and x8 on ARM64.
* According to SO3 ABI, the syscall arguments are passed in r0-r5 on ARM and x0-x5 on ARM64.
Expand Down
15 changes: 11 additions & 4 deletions so3/scripts/syscall_gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
# - syscall.tbl: Declares all syscalls available on SO3 without taking into
# account the CPU arch. This also provides configuration
# requirement for a given syscall.
# Requirement can be set to EMPTY_IMPLEMENTATION, which will
# set a default function returning -ENOSYS for syscalls that
# are intentionally not implemented.
# - syscall.h.in: Contains all syscall number which are necessary implemented
# in SO3. This is a copy of the same file from musl library.
#
Expand Down Expand Up @@ -81,9 +84,13 @@ file_header "__SYSCALL_TABLE_H__" > "$outfile_table"
valid_syscalls="$(grep -E "^[^#]" "$infile_table")"
while read name requirement; do
sys_cond["$name"]="$requirement"

echo "#ifdef SYSCALL_$name"
echo -e "\t[SYSCALL_$name] = &__sys_$name,"
if [ "$requirement" = "EMPTY_IMPLEMENTATION" ]; then
echo -e "\t[SYSCALL_$name] = &__sys_empty,"
else
echo -e "\t[SYSCALL_$name] = &__sys_$name,"
fi
echo "#endif"
done < <(echo "$valid_syscalls") >> "$outfile_table"

Expand All @@ -100,13 +107,13 @@ grep -E "^#define " "$infile_number" | sed "s/^#define __NR_//" | {
continue
fi

if [ -n "${sys_cond[$name]}" ]; then
if [ -n "${sys_cond[$name]}" -a "${sys_cond[$name]}" != "EMPTY_IMPLEMENTATION" ]; then
echo "#ifdef CONFIG_${sys_cond[$name]}"
fi

echo "#define SYSCALL_$name $number"

if [ -n "${sys_cond[$name]}" ]; then
if [ -n "${sys_cond[$name]}" -a "${sys_cond[$name]}" != "EMPTY_IMPLEMENTATION" ]; then
echo "#endif"
fi
done
Expand Down
6 changes: 6 additions & 0 deletions so3/syscall.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,9 @@ send NET
sendto NET
setsockopt NET
brk PROC_ENV

# TODO: implement. Heavily used in MUSL, so remove warning about it for now.
munmap EMPTY_IMPLEMENTATION

# mprotect allows to set memory protection (read/write/execute), which isn't supported.
mprotect EMPTY_IMPLEMENTATION