1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include "mos/ksyscall_entry.h"
4
5#include "mos/misc/profiling.h"
6#include "mos/tasks/signal.h"
7
8#include <mos/syscall/dispatcher.h>
9#include <mos/syscall/table.h>
10#include <mos/types.h>
11#include <mos_stdio.h>
12
13reg_t ksyscall_enter(reg_t number, reg_t arg1, reg_t arg2, reg_t arg3, reg_t arg4, reg_t arg5, reg_t arg6)
14{
15 const pf_point_t ev = profile_enter();
16 const reg_t ret = dispatch_syscall(number, arg1, arg2, arg3, arg4, arg5, arg6);
17 profile_leave(ev, "syscall.%lu.%s", number, syscall_names[number]);
18
19 if (IS_ERR_VALUE(ret))
20 {
21 // handle -EFAULT by sending SIGSEGV to the current thread
22 if (ret == (reg_t) -EFAULT)
23 signal_send_to_thread(current_thread, SIGSEGV);
24 }
25
26 MOS_ASSERT_X(current_thread->state == THREAD_STATE_RUNNING, "thread %pt is not in 'running' state", (void *) current_thread);
27 return ret;
28}
29