MOS Source Code
Loading...
Searching...
No Matches
usermode.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2// Usermode syscall wrappers
3// This file was generated by scripts/gen_syscall.py
4
5#pragma once
6
8#include <mos/io/io_types.h>
9#include <mos/mos_global.h>
11#include <mos/types.h>
12#include <sys/poll.h>
13#include <sys/select.h>
14#include <sys/uio.h>
15
16// platform syscall header
17#include <mos/platform_syscall.h>
18#include <mos/syscall/number.h>
19
20#ifdef __MOS_KERNEL__
21#error "This file should not be included in the kernel!"
22#endif
23
24should_inline fd_t syscall_vfs_openat(fd_t dirfd, const char *file_path, open_flags flags)
25{
26 return (fd_t) platform_syscall3(SYSCALL_vfs_openat, (reg_t) dirfd, (reg_t) file_path, (reg_t) flags);
27}
28
29should_inline long syscall_vfs_fstatat(fd_t dirfd, const char *file_path, file_stat_t *stat_buf, fstatat_flags flags)
30{
31 return (long) platform_syscall4(SYSCALL_vfs_fstatat, (reg_t) dirfd, (reg_t) file_path, (reg_t) stat_buf, (reg_t) flags);
32}
33
34should_inline size_t syscall_io_read(fd_t fd, void *buffer, size_t size)
35{
36 return (size_t) platform_syscall3(SYSCALL_io_read, (reg_t) fd, (reg_t) buffer, (reg_t) size);
37}
38
39should_inline size_t syscall_io_write(fd_t fd, const void *buffer, size_t size)
40{
41 return (size_t) platform_syscall3(SYSCALL_io_write, (reg_t) fd, (reg_t) buffer, (reg_t) size);
42}
43
48
49should_inline __attribute__((__noreturn__)) void syscall_exit(u32 exit_code)
50{
52 __builtin_unreachable();
53}
54
59
64
69
74
75should_inline pid_t syscall_spawn(const char *file_path, const char *const *argv, const char *const *envp)
76{
77 return (pid_t) platform_syscall3(SYSCALL_spawn, (reg_t) file_path, (reg_t) argv, (reg_t) envp);
78}
79
80should_inline tid_t syscall_create_thread(const char *name, thread_entry_t entry, void *arg, size_t stack_size, void *stack)
81{
82 return (tid_t) platform_syscall5(SYSCALL_create_thread, (reg_t) name, (reg_t) entry, (reg_t) arg, (reg_t) stack_size, (reg_t) stack);
83}
84
89
90should_inline __attribute__((__noreturn__)) void syscall_thread_exit(void)
91{
93 __builtin_unreachable();
94}
95
100
102{
103 return (bool) platform_syscall2(SYSCALL_futex_wait, (reg_t) futex, (reg_t) val);
104}
105
107{
108 return (bool) platform_syscall2(SYSCALL_futex_wake, (reg_t) futex, (reg_t) count);
109}
110
111should_inline fd_t syscall_ipc_create(const char *name, size_t max_pending_connections)
112{
113 return (fd_t) platform_syscall2(SYSCALL_ipc_create, (reg_t) name, (reg_t) max_pending_connections);
114}
115
120
121should_inline fd_t syscall_ipc_connect(const char *name, size_t buffer_size)
122{
123 return (fd_t) platform_syscall2(SYSCALL_ipc_connect, (reg_t) name, (reg_t) buffer_size);
124}
125
133{
134 return (u64) platform_syscall5(SYSCALL_arch_syscall, (reg_t) nr, (reg_t) arg1, (reg_t) arg2, (reg_t) arg3, (reg_t) arg4);
135}
136
137should_inline long syscall_vfs_mount(const char *device, const char *mount_point, const char *fs_type, const char *options)
138{
139 return (long) platform_syscall4(SYSCALL_vfs_mount, (reg_t) device, (reg_t) mount_point, (reg_t) fs_type, (reg_t) options);
140}
141
142should_inline ssize_t syscall_vfs_readlinkat(fd_t dirfd, const char *path, char *buf, size_t buf_size)
143{
144 return (ssize_t) platform_syscall4(SYSCALL_vfs_readlinkat, (reg_t) dirfd, (reg_t) path, (reg_t) buf, (reg_t) buf_size);
145}
146
147should_inline long syscall_vfs_unlinkat(fd_t dirfd, const char *path)
148{
149 return (long) platform_syscall2(SYSCALL_vfs_unlinkat, (reg_t) dirfd, (reg_t) path);
150}
151
152should_inline long syscall_vfs_symlink(const char *link_path, const char *target)
153{
154 return (long) platform_syscall2(SYSCALL_vfs_symlink, (reg_t) link_path, (reg_t) target);
155}
156
157should_inline long syscall_vfs_mkdir(const char *path)
158{
159 return (long) platform_syscall1(SYSCALL_vfs_mkdir, (reg_t) path);
160}
161
162should_inline size_t syscall_vfs_list_dir(fd_t fd, char *buffer, size_t buffer_size)
163{
164 return (size_t) platform_syscall3(SYSCALL_vfs_list_dir, (reg_t) fd, (reg_t) buffer, (reg_t) buffer_size);
165}
166
168{
169 return (long) platform_syscall3(SYSCALL_fd_manipulate, (reg_t) fd, (reg_t) cmd, (reg_t) arg);
170}
171
173{
174 return (void *) platform_syscall4(SYSCALL_mmap_anonymous, (reg_t) hint_addr, (reg_t) size, (reg_t) perm, (reg_t) flags);
175}
176
177should_inline void *syscall_mmap_file(ptr_t hint_addr, size_t size, mem_perm_t perm, mmap_flags_t flags, fd_t fd, off_t offset)
178{
179 return (void *) platform_syscall6(SYSCALL_mmap_file, (reg_t) hint_addr, (reg_t) size, (reg_t) perm, (reg_t) flags, (reg_t) fd, (reg_t) offset);
180}
181
183{
184 return (pid_t) platform_syscall3(SYSCALL_wait_for_process, (reg_t) pid, (reg_t) exit_code, (reg_t) flags);
185}
186
187should_inline bool syscall_munmap(void *addr, size_t size)
188{
189 return (bool) platform_syscall2(SYSCALL_munmap, (reg_t) addr, (reg_t) size);
190}
191
192should_inline long syscall_vfs_chdirat(fd_t dirfd, const char *path)
193{
194 return (long) platform_syscall2(SYSCALL_vfs_chdirat, (reg_t) dirfd, (reg_t) path);
195}
196
197should_inline ssize_t syscall_vfs_getcwd(char *buf, size_t buf_size)
198{
199 return (ssize_t) platform_syscall2(SYSCALL_vfs_getcwd, (reg_t) buf, (reg_t) buf_size);
200}
201
203{
204 return (off_t) platform_syscall3(SYSCALL_io_seek, (reg_t) fd, (reg_t) offset, (reg_t) whence);
205}
206
211
213{
214 return (bool) platform_syscall2(SYSCALL_signal_register, (reg_t) signum, (reg_t) action);
215}
216
223{
224 return (long) platform_syscall2(SYSCALL_signal_process, (reg_t) pid, (reg_t) signum);
225}
226
232{
233 return (long) platform_syscall2(SYSCALL_signal_thread, (reg_t) tid, (reg_t) signum);
234}
235
236should_inline void syscall_poweroff(bool reboot, u32 magic)
237{
238 platform_syscall2(SYSCALL_poweroff, (reg_t) reboot, (reg_t) magic);
239}
240
241should_inline __attribute__((__noreturn__)) void syscall_signal_return(void *sp)
242{
244 __builtin_unreachable();
245}
246
247should_inline bool syscall_vm_protect(void *addr, size_t size, mem_perm_t perm)
248{
249 return (bool) platform_syscall3(SYSCALL_vm_protect, (reg_t) addr, (reg_t) size, (reg_t) perm);
250}
251
252should_inline int syscall_io_poll(struct pollfd *fds, nfds_t nfds, int timeout)
253{
254 return (int) platform_syscall3(SYSCALL_io_poll, (reg_t) fds, (reg_t) nfds, (reg_t) timeout);
255}
256
257should_inline int syscall_io_pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask)
258{
259 return (int) platform_syscall6(SYSCALL_io_pselect, (reg_t) nfds, (reg_t) readfds, (reg_t) writefds, (reg_t) exceptfds, (reg_t) timeout, (reg_t) sigmask);
260}
261
262should_inline long syscall_execveat(fd_t dirfd, const char *file_path, const char *const *argv, const char *const *envp, u32 flags)
263{
264 return (long) platform_syscall5(SYSCALL_execveat, (reg_t) dirfd, (reg_t) file_path, (reg_t) argv, (reg_t) envp, (reg_t) flags);
265}
266
271
276
278{
279 return (fd_t) platform_syscall2(SYSCALL_io_dup2, (reg_t) old_fd, (reg_t) new_fd);
280}
281
287should_inline bool syscall_dmabuf_alloc(size_t n_pages, ptr_t *out_paddr, ptr_t *out_vaddr)
288{
289 return (bool) platform_syscall3(SYSCALL_dmabuf_alloc, (reg_t) n_pages, (reg_t) out_paddr, (reg_t) out_vaddr);
290}
291
299{
300 return (bool) platform_syscall2(SYSCALL_dmabuf_free, (reg_t) vaddr, (reg_t) paddr);
301}
302
308should_inline bool syscall_dmabuf_share(void *buf, size_t bufsize, ptr_t *out_paddr)
309{
310 return (bool) platform_syscall3(SYSCALL_dmabuf_share, (reg_t) buf, (reg_t) bufsize, (reg_t) out_paddr);
311}
312
319should_inline bool syscall_dmabuf_unshare(ptr_t paddr, size_t size, void *vaddr)
320{
321 return (bool) platform_syscall3(SYSCALL_dmabuf_unshare, (reg_t) paddr, (reg_t) size, (reg_t) vaddr);
322}
323
324should_inline long syscall_pipe(fd_t *out_read_fd, fd_t *out_write_fd, fd_flags_t flags)
325{
326 return (long) platform_syscall3(SYSCALL_pipe, (reg_t) out_read_fd, (reg_t) out_write_fd, (reg_t) flags);
327}
328
329should_inline ssize_t syscall_io_readv(fd_t fd, const struct iovec *iov, int iov_count)
330{
331 return (ssize_t) platform_syscall3(SYSCALL_io_readv, (reg_t) fd, (reg_t) iov, (reg_t) iov_count);
332}
333
334should_inline long syscall_vfs_unmount(const char *mount_point)
335{
336 return (long) platform_syscall1(SYSCALL_vfs_unmount, (reg_t) mount_point);
337}
338
340{
342}
343
345{
347}
348
349should_inline ssize_t syscall_thread_getname(tid_t tid, char *buf, size_t buf_size)
350{
351 return (ssize_t) platform_syscall3(SYSCALL_thread_getname, (reg_t) tid, (reg_t) buf, (reg_t) buf_size);
352}
353
354should_inline long syscall_vfs_fchmodat(fd_t dirfd, const char *path, int mode, int flags)
355{
356 return (long) platform_syscall4(SYSCALL_vfs_fchmodat, (reg_t) dirfd, (reg_t) path, (reg_t) mode, (reg_t) flags);
357}
358
359should_inline long syscall_io_pread(fd_t fd, void *buf, size_t count, off_t offset)
360{
361 return (long) platform_syscall4(SYSCALL_io_pread, (reg_t) fd, (reg_t) buf, (reg_t) count, (reg_t) offset);
362}
363
368
369should_inline long syscall_signal_mask_op(int how, const sigset_t *set, sigset_t *oldset)
370{
371 return (long) platform_syscall3(SYSCALL_signal_mask_op, (reg_t) how, (reg_t) set, (reg_t) oldset);
372}
373
379should_inline long syscall_vfs_fsync(fd_t fd, bool data_only)
380{
381 return (long) platform_syscall2(SYSCALL_vfs_fsync, (reg_t) fd, (reg_t) data_only);
382}
383
fstatat_flags
Definition fs_types.h:40
fd_flags_t
Definition fs_types.h:47
open_flags
Definition fs_types.h:26
io_seek_whence_t
Definition io_types.h:6
const char ** argv
Definition kmain.c:44
mem_perm_t
Definition mm_types.h:7
mmap_flags_t
Definition mm_types.h:15
#define should_inline
Definition mos_global.h:37
#define SYSCALL_dmabuf_alloc
Definition number.h:154
#define SYSCALL_poweroff
Definition number.h:127
#define SYSCALL_vfs_mount
Definition number.h:73
#define SYSCALL_mmap_file
Definition number.h:97
#define SYSCALL_dmabuf_share
Definition number.h:160
#define SYSCALL_io_readv
Definition number.h:169
#define SYSCALL_get_pid
Definition number.h:34
#define SYSCALL_vfs_fsync
Definition number.h:196
#define SYSCALL_exit
Definition number.h:25
#define SYSCALL_fd_manipulate
Definition number.h:91
#define SYSCALL_yield_cpu
Definition number.h:28
#define SYSCALL_vm_protect
Definition number.h:133
#define SYSCALL_signal_register
Definition number.h:118
#define SYSCALL_vfs_unlinkat
Definition number.h:79
#define SYSCALL_io_dup
Definition number.h:148
#define SYSCALL_ipc_accept
Definition number.h:64
#define SYSCALL_execveat
Definition number.h:142
#define SYSCALL_io_poll
Definition number.h:136
#define SYSCALL_io_close
Definition number.h:22
#define SYSCALL_get_tid
Definition number.h:46
#define SYSCALL_wait_for_thread
Definition number.h:52
#define SYSCALL_wait_for_process
Definition number.h:100
#define SYSCALL_io_tell
Definition number.h:115
#define SYSCALL_fork
Definition number.h:31
#define SYSCALL_vfs_readlinkat
Definition number.h:76
#define SYSCALL_thread_getname
Definition number.h:181
#define SYSCALL_memfd_create
Definition number.h:190
#define SYSCALL_futex_wake
Definition number.h:58
#define SYSCALL_arch_syscall
Definition number.h:70
#define SYSCALL_signal_thread
Definition number.h:124
#define SYSCALL_clock_msleep
Definition number.h:145
#define SYSCALL_dmabuf_unshare
Definition number.h:163
#define SYSCALL_vfs_unmount
Definition number.h:172
#define SYSCALL_io_dup2
Definition number.h:151
#define SYSCALL_io_write
Definition number.h:19
#define SYSCALL_ipc_connect
Definition number.h:67
#define SYSCALL_vfs_fstatat
Definition number.h:13
#define SYSCALL_thread_exit
Definition number.h:49
#define SYSCALL_thread_setname
Definition number.h:178
#define SYSCALL_mmap_anonymous
Definition number.h:94
#define SYSCALL_signal_mask_op
Definition number.h:193
#define SYSCALL_io_seek
Definition number.h:112
#define SYSCALL_signal_process
Definition number.h:121
#define SYSCALL_vfs_list_dir
Definition number.h:88
#define SYSCALL_futex_wait
Definition number.h:55
#define SYSCALL_clock_gettimeofday
Definition number.h:175
#define SYSCALL_vfs_fchmodat
Definition number.h:184
#define SYSCALL_io_pread
Definition number.h:187
#define SYSCALL_io_pselect
Definition number.h:139
#define SYSCALL_spawn
Definition number.h:40
#define SYSCALL_dmabuf_free
Definition number.h:157
#define SYSCALL_create_thread
Definition number.h:43
#define SYSCALL_vfs_openat
Definition number.h:10
#define SYSCALL_vfs_mkdir
Definition number.h:85
#define SYSCALL_ipc_create
Definition number.h:61
#define SYSCALL_vfs_getcwd
Definition number.h:109
#define SYSCALL_vfs_chdirat
Definition number.h:106
#define SYSCALL_munmap
Definition number.h:103
#define SYSCALL_get_parent_pid
Definition number.h:37
#define SYSCALL_signal_return
Definition number.h:130
#define SYSCALL_io_read
Definition number.h:16
#define SYSCALL_vfs_symlink
Definition number.h:82
#define SYSCALL_pipe
Definition number.h:166
should_inline reg_t platform_syscall4(long n, long a, long b, long c, long d)
should_inline reg_t platform_syscall6(long n, long a, long b, long c, long d, long e, long f)
should_inline reg_t platform_syscall2(long n, long a, long b)
should_inline reg_t platform_syscall0(long n)
should_inline reg_t platform_syscall1(long n, long a)
should_inline reg_t platform_syscall5(long n, long a, long b, long c, long d, long e)
should_inline reg_t platform_syscall3(long n, long a, long b, long c)
int signal_t
Definition signal_types.h:9
size_t size
Definition slab.c:30
const char * name
Definition slab.c:31
static char buffer[2048]
Definition test_printf.c:7
uintn reg_t
Definition types.h:51
unsigned int u32
Definition types.h:21
s32 futex_word_t
Definition types.h:99
ssize_t off_t
Definition types.h:84
void(* thread_entry_t)(void *arg)
Definition types.h:109
s32 fd_t
Definition types.h:81
s32 tid_t
Definition types.h:79
s32 pid_t
Definition types.h:78
unsigned long ptr_t
Definition types.h:25
unsigned long long u64
Definition types.h:23
signed long ssize_t
Definition types.h:83
should_inline fd_t syscall_ipc_create(const char *name, size_t max_pending_connections)
Definition usermode.h:111
should_inline void syscall_yield_cpu(void)
Definition usermode.h:55
should_inline bool syscall_dmabuf_share(void *buf, size_t bufsize, ptr_t *out_paddr)
Definition usermode.h:308
should_inline ssize_t syscall_io_readv(fd_t fd, const struct iovec *iov, int iov_count)
Definition usermode.h:329
should_inline __attribute__((__noreturn__)) void syscall_exit(u32 exit_code)
Definition usermode.h:49
should_inline long syscall_vfs_unlinkat(fd_t dirfd, const char *path)
Definition usermode.h:147
should_inline void syscall_poweroff(bool reboot, u32 magic)
Definition usermode.h:236
should_inline long syscall_fd_manipulate(fd_t fd, u64 cmd, void *arg)
Definition usermode.h:167
should_inline fd_t syscall_ipc_connect(const char *name, size_t buffer_size)
Definition usermode.h:121
should_inline u64 syscall_arch_syscall(u64 nr, u64 arg1, u64 arg2, u64 arg3, u64 arg4)
Definition usermode.h:132
should_inline long syscall_clock_msleep(u64 ms)
Definition usermode.h:267
should_inline long syscall_vfs_fsync(fd_t fd, bool data_only)
Definition usermode.h:379
should_inline pid_t syscall_get_parent_pid(void)
Definition usermode.h:70
should_inline pid_t syscall_get_pid(void)
Definition usermode.h:65
should_inline bool syscall_dmabuf_alloc(size_t n_pages, ptr_t *out_paddr, ptr_t *out_vaddr)
Definition usermode.h:287
should_inline long syscall_vfs_chdirat(fd_t dirfd, const char *path)
Definition usermode.h:192
should_inline long syscall_io_pread(fd_t fd, void *buf, size_t count, off_t offset)
Definition usermode.h:359
should_inline tid_t syscall_create_thread(const char *name, thread_entry_t entry, void *arg, size_t stack_size, void *stack)
Definition usermode.h:80
should_inline bool syscall_io_close(fd_t fd)
Definition usermode.h:44
should_inline off_t syscall_io_tell(fd_t fd)
Definition usermode.h:207
should_inline bool syscall_dmabuf_unshare(ptr_t paddr, size_t size, void *vaddr)
Definition usermode.h:319
should_inline pid_t syscall_spawn(const char *file_path, const char *const *argv, const char *const *envp)
Definition usermode.h:75
should_inline long syscall_vfs_symlink(const char *link_path, const char *target)
Definition usermode.h:152
should_inline long syscall_execveat(fd_t dirfd, const char *file_path, const char *const *argv, const char *const *envp, u32 flags)
Definition usermode.h:262
should_inline size_t syscall_io_read(fd_t fd, void *buffer, size_t size)
Definition usermode.h:34
should_inline long syscall_vfs_mkdir(const char *path)
Definition usermode.h:157
should_inline bool syscall_dmabuf_free(ptr_t vaddr, ptr_t paddr)
Definition usermode.h:298
should_inline int syscall_io_poll(struct pollfd *fds, nfds_t nfds, int timeout)
Definition usermode.h:252
should_inline tid_t syscall_get_tid(void)
Definition usermode.h:85
should_inline fd_t syscall_io_dup(fd_t fd)
Definition usermode.h:272
should_inline bool syscall_futex_wait(futex_word_t *futex, u32 val)
Definition usermode.h:101
should_inline long syscall_signal_mask_op(int how, const sigset_t *set, sigset_t *oldset)
Definition usermode.h:369
should_inline bool syscall_futex_wake(futex_word_t *futex, size_t count)
Definition usermode.h:106
should_inline pid_t syscall_fork(void)
Definition usermode.h:60
should_inline long syscall_vfs_fstatat(fd_t dirfd, const char *file_path, file_stat_t *stat_buf, fstatat_flags flags)
Definition usermode.h:29
should_inline bool syscall_signal_register(signal_t signum, const sigaction_t *action)
Definition usermode.h:212
should_inline void * syscall_mmap_anonymous(ptr_t hint_addr, size_t size, mem_perm_t perm, mmap_flags_t flags)
Definition usermode.h:172
should_inline long syscall_pipe(fd_t *out_read_fd, fd_t *out_write_fd, fd_flags_t flags)
Definition usermode.h:324
should_inline long syscall_signal_process(pid_t pid, signal_t signum)
Definition usermode.h:222
should_inline pid_t syscall_wait_for_process(pid_t pid, u32 *exit_code, u32 flags)
Definition usermode.h:182
should_inline long syscall_clock_gettimeofday(struct timespec *tv)
Definition usermode.h:339
should_inline fd_t syscall_vfs_openat(fd_t dirfd, const char *file_path, open_flags flags)
Definition usermode.h:24
should_inline fd_t syscall_ipc_accept(fd_t fd)
Definition usermode.h:116
should_inline void * syscall_mmap_file(ptr_t hint_addr, size_t size, mem_perm_t perm, mmap_flags_t flags, fd_t fd, off_t offset)
Definition usermode.h:177
should_inline fd_t syscall_io_dup2(fd_t old_fd, fd_t new_fd)
Definition usermode.h:277
should_inline long syscall_signal_thread(tid_t tid, signal_t signum)
Definition usermode.h:231
should_inline bool syscall_vm_protect(void *addr, size_t size, mem_perm_t perm)
Definition usermode.h:247
should_inline long syscall_vfs_unmount(const char *mount_point)
Definition usermode.h:334
should_inline size_t syscall_vfs_list_dir(fd_t fd, char *buffer, size_t buffer_size)
Definition usermode.h:162
should_inline bool syscall_wait_for_thread(tid_t tid)
Definition usermode.h:96
should_inline off_t syscall_io_seek(fd_t fd, off_t offset, io_seek_whence_t whence)
Definition usermode.h:202
should_inline ssize_t syscall_vfs_readlinkat(fd_t dirfd, const char *path, char *buf, size_t buf_size)
Definition usermode.h:142
should_inline ssize_t syscall_thread_getname(tid_t tid, char *buf, size_t buf_size)
Definition usermode.h:349
should_inline long syscall_thread_setname(tid_t tid, const char *name)
Definition usermode.h:344
should_inline long syscall_vfs_mount(const char *device, const char *mount_point, const char *fs_type, const char *options)
Definition usermode.h:137
should_inline int syscall_io_pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask)
Definition usermode.h:257
should_inline fd_t syscall_memfd_create(const char *name, u32 flags)
Definition usermode.h:364
should_inline size_t syscall_io_write(fd_t fd, const void *buffer, size_t size)
Definition usermode.h:39
should_inline ssize_t syscall_vfs_getcwd(char *buf, size_t buf_size)
Definition usermode.h:197
should_inline bool syscall_munmap(void *addr, size_t size)
Definition usermode.h:187
should_inline long syscall_vfs_fchmodat(fd_t dirfd, const char *path, int mode, int flags)
Definition usermode.h:354