MOS Source Code
Loading...
Searching...
No Matches
ksyscall.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include "mos/device/timer.h"
4#include "mos/ipc/ipc_io.h"
5#include "mos/ipc/memfd.h"
6#include "mos/ipc/pipe.h"
7#include "mos/misc/power.h"
8#include "mos/mm/dma.h"
9#include "mos/tasks/signal.h"
10
11#include <bits/posix/iovec.h>
12#include <errno.h>
13#include <fcntl.h>
15#include <mos/filesystem/vfs.h>
16#include <mos/io/io.h>
17#include <mos/locks/futex.h>
18#include <mos/mm/mmap.h>
21#include <mos/syscall/decl.h>
22#include <mos/syscall/number.h>
23#include <mos/syslog/printk.h>
24#include <mos/tasks/elf.h>
25#include <mos/tasks/process.h>
26#include <mos/tasks/schedule.h>
28#include <mos/tasks/thread.h>
29#include <mos/types.h>
30#include <mos_stdlib.h>
31#include <mos_string.h>
32#include <sys/poll.h>
33
34#define DEFINE_SYSCALL(ret, name) \
35 MOS_STATIC_ASSERT(SYSCALL_DEFINED(name)); \
36 ret define_syscall(name)
37
38DEFINE_SYSCALL(void, poweroff)(bool reboot, u32 magic)
39{
40#define POWEROFF_MAGIC MOS_FOURCC('G', 'B', 'y', 'e')
41 if (magic != POWEROFF_MAGIC)
42 {
43 mos_warn("poweroff syscall called with wrong magic number (0x%x)", magic);
44 return;
45 }
46
47 if (!reboot)
48 {
49 pr_info("Meow, see ya~ :3");
51 }
52 else
53 {
54 mos_warn("reboot is not implemented yet");
55 }
56}
57
58DEFINE_SYSCALL(fd_t, vfs_openat)(fd_t dirfd, const char *path, open_flags flags)
59{
60 if (path == NULL)
61 return -1;
62
63 file_t *f = vfs_openat(dirfd, path, flags);
64 if (IS_ERR(f))
65 return PTR_ERR(f);
67}
68
69DEFINE_SYSCALL(long, vfs_fstatat)(fd_t fd, const char *path, file_stat_t *stat_buf, fstatat_flags flags)
70{
71 return vfs_fstatat(fd, path, stat_buf, flags);
72}
73
74DEFINE_SYSCALL(size_t, io_read)(fd_t fd, void *buf, size_t count)
75{
76 if (buf == NULL)
77 return -EFAULT;
78
80 if (!io)
81 return -EBADF;
82
83 return io_read(io, buf, count);
84}
85
86DEFINE_SYSCALL(size_t, io_write)(fd_t fd, const void *buf, size_t count)
87{
88 if (buf == NULL)
89 {
90 pr_warn("io_write called with invalid arguments (fd=%d, buf=%p, count=%zd)", fd, buf, count);
91 return -EFAULT;
92 }
93
95 if (!io)
96 {
97 pr_warn("io_write called with invalid fd %d", fd);
98 return -EBADF;
99 }
100
101 return io_write(io, buf, count);
102}
103
105{
107 return true;
108}
109
110DEFINE_SYSCALL([[noreturn]] void, exit)(u32 exit_code)
111{
112 // only use the lower 8 bits
113 exit_code &= 0xff;
114 process_exit(current_process, exit_code, 0);
115}
116
118{
119 spinlock_acquire(&current_thread->state_lock);
120 reschedule();
121}
122
124{
125 process_t *parent = current_process;
126 process_t *child = process_do_fork(parent);
127 if (unlikely(child == NULL))
128 return -1;
129 return child->pid; // return 0 for child, pid for parent
130}
131
133{
134 return current_process->pid;
135}
136
138{
139 return current_process->parent->pid;
140}
141
142DEFINE_SYSCALL(pid_t, spawn)(const char *path, const char *const argv[], const char *const envp[])
143{
144 const stdio_t stdio = current_stdio();
145 process_t *process = elf_create_process(path, current_process, argv, envp, &stdio);
146
147 if (process == NULL)
148 return -1;
149
150 return process->pid;
151}
152
153DEFINE_SYSCALL(tid_t, create_thread)(const char *name, thread_entry_t entry, void *arg, size_t stack_size, void *stack)
154{
155 thread_t *thread = thread_new(current_process, THREAD_MODE_USER, name, stack_size, stack);
156 if (thread == NULL)
157 return -1;
158
159 platform_context_setup_child_thread(thread, entry, arg);
160 thread_complete_init(thread);
161 scheduler_add_thread(thread);
162 return thread->tid;
163}
164
166{
167 return current_thread->tid;
168}
169
170DEFINE_SYSCALL([[noreturn]] void, thread_exit)(void)
171{
173}
174
176{
177 return thread_wait_for_tid(tid);
178}
179
181{
182 return futex_wait(futex, val);
183}
184
185DEFINE_SYSCALL(bool, futex_wake)(futex_word_t *futex, size_t count)
186{
187 return futex_wake(futex, count);
188}
189
190DEFINE_SYSCALL(fd_t, ipc_create)(const char *name, size_t max_pending_connections)
191{
192 io_t *io = ipc_create(name, max_pending_connections);
193 if (IS_ERR(io))
194 return PTR_ERR(io);
196}
197
199{
200 io_t *server = process_get_fd(current_process, listen_fd);
201 if (server == NULL)
202 return -1;
203
204 io_t *client_io = ipc_accept(server);
205 if (IS_ERR(client_io))
206 return PTR_ERR(client_io);
207
209}
210
211DEFINE_SYSCALL(fd_t, ipc_connect)(const char *server, size_t buffer_size)
212{
213 io_t *io = ipc_connect(server, buffer_size);
214 if (IS_ERR(io))
215 return PTR_ERR(io);
217}
218
219DEFINE_SYSCALL(u64, arch_syscall)(u64 syscall, u64 arg1, u64 arg2, u64 arg3, u64 arg4)
220{
221 return platform_arch_syscall(syscall, arg1, arg2, arg3, arg4);
222}
223
224DEFINE_SYSCALL(long, vfs_mount)(const char *device, const char *mountpoint, const char *fs_type, const char *options)
225{
226 return vfs_mount(device, mountpoint, fs_type, options);
227}
228
229DEFINE_SYSCALL(ssize_t, vfs_readlinkat)(fd_t dirfd, const char *path, char *buf, size_t buflen)
230{
231 return vfs_readlinkat(dirfd, path, buf, buflen);
232}
233
234DEFINE_SYSCALL(long, vfs_unlinkat)(fd_t dirfd, const char *path)
235{
236 return vfs_unlinkat(dirfd, path);
237}
238
239DEFINE_SYSCALL(long, vfs_symlink)(const char *target, const char *linkpath)
240{
241 return vfs_symlink(target, linkpath);
242}
243
244DEFINE_SYSCALL(long, vfs_mkdir)(const char *path)
245{
246 return vfs_mkdir(path);
247}
248
249DEFINE_SYSCALL(size_t, vfs_list_dir)(fd_t fd, char *buffer, size_t buffer_size)
250{
252 if (io == NULL)
253 return false;
254 return vfs_list_dir(io, buffer, buffer_size);
255}
256
257DEFINE_SYSCALL(long, fd_manipulate)(fd_t fd, u64 op, void *arg)
258{
259 fd_type *fdt = &current_process->files[fd];
260 if (fdt->io == NULL)
261 return -EBADF;
262
263 switch (op)
264 {
265 case F_DUPFD:
266 {
268 return fd2;
269 }
270 case F_DUPFD_CLOEXEC:
271 {
273 return fd2;
274 }
275 case F_GETFD:
276 {
277 return fdt->flags;
278 }
279 case F_SETFD:
280 {
281 // test if arg is a valid flag
282 u64 flags = (u64) arg;
283 if (flags & ~FD_FLAGS_CLOEXEC)
284 return -EINVAL;
285 fdt->flags = flags;
286 return 0;
287 }
288 case F_GETFL:
289 case F_SETFL:
290 {
291 return -ENOSYS; // not implemented
292 }
293 case F_GETLK:
294 case F_SETLK:
295 case F_SETLKW:
296 {
297 return -ENOSYS; // not implemented
298 }
299 case F_GETOWN:
300 case F_SETOWN:
301 case F_GETOWN_EX:
302 case F_SETOWN_EX:
303 case F_GETSIG:
304 case F_SETSIG:
305 case F_GETOWNER_UIDS:
306 case F_ADD_SEALS:
307 case F_GET_SEALS:
308 {
309 return -ENOSYS; // not implemented
310 }
311 }
312
313 return -EINVAL;
314}
315
316DEFINE_SYSCALL(void *, mmap_anonymous)(ptr_t hint_addr, size_t size, mem_perm_t perm, mmap_flags_t flags)
317{
318 const vm_flags vmflags = VM_USER | (vm_flags) perm; // vm_flags shares the same values as mem_perm_t
319 const size_t n_pages = ALIGN_UP_TO_PAGE(size) / MOS_PAGE_SIZE;
320
321 ptr_t result = mmap_anonymous(current_mm, hint_addr, flags, vmflags, n_pages);
322 return (void *) result;
323}
324
325DEFINE_SYSCALL(void *, mmap_file)(ptr_t hint_addr, size_t size, mem_perm_t perm, mmap_flags_t mmap_flags, fd_t fd, off_t offset)
326{
327 const vm_flags vmflags = VM_USER | (vm_flags) perm; // vm_flags shares the same values as mem_perm_t
328 const size_t n_pages = ALIGN_UP_TO_PAGE(size) / MOS_PAGE_SIZE;
329
331 if (io == NULL)
332 return NULL;
333
334 ptr_t result = mmap_file(current_mm, hint_addr, mmap_flags, vmflags, n_pages, io, offset);
335 return (void *) result;
336}
337
339{
340 return process_wait_for_pid(pid, exit_code, flags);
341}
342
343DEFINE_SYSCALL(bool, munmap)(void *addr, size_t size)
344{
345 return munmap((ptr_t) addr, size);
346}
347
348DEFINE_SYSCALL(long, vfs_chdirat)(fd_t dirfd, const char *path)
349{
350 return vfs_chdirat(dirfd, path);
351}
352
354{
355 return vfs_getcwd(buf, size);
356}
357
359{
361 if (io == NULL)
362 return -1;
363 return io_seek(io, offset, whence);
364}
365
367{
369 if (io == NULL)
370 return -1;
371 return io_tell(io);
372}
373
375{
377}
378
380{
381 process_t *process = process_get(pid);
382 if (!process)
383 return -ESRCH;
384 return signal_send_to_process(process, sig);
385}
386
388{
389 thread_t *thread = thread_get(tid);
390 if (thread == NULL)
391 return -ESRCH;
392 return signal_send_to_thread(thread, sig);
393}
394
395DEFINE_SYSCALL([[noreturn]] void, signal_return)(void *sp)
396{
398}
399
400DEFINE_SYSCALL(bool, vm_protect)(void *addr, size_t size, mem_perm_t perm)
401{
402 return vm_protect(current_mm, (ptr_t) addr, size, (vm_flags) perm);
403}
404
405DEFINE_SYSCALL(int, io_poll)(struct pollfd *fds, nfds_t nfds, int timeout)
406{
407 if (timeout == 0) // poll with timeout 0 is just a check
408 return 0;
409
410 if (!fds || nfds == 0)
411 return -1;
412
413 for (nfds_t i = 0; i < nfds; i++)
414 {
415 if (fds[i].fd < 0)
416 fds[i].revents = 0;
417 pr_info2("io_poll: fd=%d, events=%d", fds[i].fd, fds[i].events);
418 }
419
420 pr_emerg("io_poll is not implemented yet\n");
421 signal_send_to_thread(current_thread, SIGKILL); // unimplemented
422 return 0;
423}
424
425#ifndef FD_CLR
426#define FD_CLR(__fd, __set) (__set->fds_bits[__fd / 8] &= ~(1 << (__fd % 8)))
427#endif
428
429#ifndef FD_ISSET
430#define FD_ISSET(__fd, __set) (__set->fds_bits[__fd / 8] & (1 << (__fd % 8)))
431#endif
432
433#ifndef FD_SET
434#define FD_SET(__fd, __set) (__set->fds_bits[__fd / 8] |= 1 << (__fd % 8))
435#endif
436
437#ifndef FD_ZERO
438#define FD_ZERO(__set) memset(__set->fds_bits, 0, sizeof(fd_set))
439#endif
440
441DEFINE_SYSCALL(int, io_pselect)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask)
442{
443 MOS_UNUSED(timeout);
444 MOS_UNUSED(sigmask);
445
446 for (int i = 0; i < nfds; i++)
447 {
448 if (readfds && FD_ISSET(i, readfds))
449 {
450 // pr_info2("io_pselect: fd=%d, read", i);
451 }
452 if (writefds && FD_ISSET(i, writefds))
453 {
454 // pr_info2("io_pselect: fd=%d, write", i);
455 }
456 if (exceptfds && FD_ISSET(i, exceptfds))
457 {
458 // pr_info2("io_pselect: fd=%d, except", i);
459 }
460 }
461
462 return 1; // stub
463}
464
465DEFINE_SYSCALL(long, execveat)(fd_t dirfd, const char *path, const char *const argv[], const char *const envp[], u32 flags)
466{
467 return process_do_execveat(current_process, dirfd, path, argv, envp, flags);
468}
469
471{
472 timer_msleep(ms);
473 return 0;
474}
475
477{
479 if (io == NULL)
480 return -EBADF; // fd is not a valid file descriptor
482}
483
485{
486 fd_type *old = &current_process->files[oldfd];
487 if (old->io == NULL)
488 return -EBADF; // oldfd is not a valid file descriptor
489
490 if (oldfd == newfd)
491 return newfd;
492
494
495 current_process->files[newfd].io = io_ref(old->io);
496 current_process->files[newfd].flags = old->flags;
497 return newfd;
498}
499
500DEFINE_SYSCALL(bool, dmabuf_alloc)(size_t n_pages, ptr_t *phys, ptr_t *virt)
501{
502 pfn_t pfn = dmabuf_allocate(n_pages, virt);
503 *phys = pfn * MOS_PAGE_SIZE;
504 return !IS_ERR_VALUE(pfn);
505}
506
508{
509 return dmabuf_free(vaddr, paddr);
510}
511
512DEFINE_SYSCALL(bool, dmabuf_share)(void *buffer, size_t size, ptr_t *phyaddr)
513{
515
516 if (IS_ERR_VALUE(pfn))
517 return false;
518
519 *phyaddr = pfn * MOS_PAGE_SIZE;
520 return true;
521}
522
523DEFINE_SYSCALL(bool, dmabuf_unshare)(ptr_t phys, size_t size, void *buf)
524{
525 return dmabuf_unshare(phys, size, buf);
526}
527
528DEFINE_SYSCALL(long, pipe)(fd_t *reader, fd_t *writer, fd_flags_t flags)
529{
531 if (IS_ERR(pipe))
532 return PTR_ERR(pipe);
533
534 pipeio_t *pipeio = pipeio_create(pipe);
535 *reader = process_attach_ref_fd(current_process, &pipeio->io_r, flags);
536 *writer = process_attach_ref_fd(current_process, &pipeio->io_w, flags);
537 return 0;
538}
539
540DEFINE_SYSCALL(ssize_t, io_readv)(fd_t fd, const struct iovec *iov, int iovcnt)
541{
542 if (fd < 0)
543 return -EBADF;
544
545 if (iov == NULL)
546 return -EFAULT;
547
549 if (!io)
550 return -EBADF;
551
552 for (int i = 0; i < iovcnt; i++)
553 {
554 if (iov[i].iov_base == NULL)
555 return -EFAULT;
556 }
557
558 ssize_t bytes_read = 0;
559
560 for (int i = 0; i < iovcnt; i++)
561 {
562 size_t ret = io_read(io, iov[i].iov_base, iov[i].iov_len);
563 if (IS_ERR_VALUE(ret))
564 return ret;
565
566 bytes_read += ret;
567
568 if (ret != iov[i].iov_len)
569 break; // short read, leave
570 }
571
572 return bytes_read;
573}
574
575DEFINE_SYSCALL(long, vfs_unmount)(const char *path)
576{
577 return vfs_unmount(path);
578}
579
580DEFINE_SYSCALL(long, clock_gettimeofday)(struct timespec *ts)
581{
582 timeval_t tv;
584 ts->tv_sec = tv.hour * 3600 + tv.minute * 60 + tv.second;
585 ts->tv_nsec = 0;
586 return 0;
587}
588
589DEFINE_SYSCALL(long, thread_setname)(tid_t tid, const char *name)
590{
591 thread_t *thread = thread_get(tid);
592 if (thread == NULL)
593 return -ESRCH;
594
595 if (thread->name)
596 kfree(thread->name);
597
598 thread->name = strdup(name);
599 return true;
600}
601
602DEFINE_SYSCALL(ssize_t, thread_getname)(tid_t tid, char *buf, size_t buflen)
603{
604 thread_t *thread = thread_get(tid);
605
606 if (thread == NULL)
607 return -ESRCH;
608
609 char *end = strncpy(buf, thread->name, buflen);
610 return end - buf;
611}
612
613DEFINE_SYSCALL(long, vfs_fchmodat)(fd_t dirfd, const char *path, int mode, int flags)
614{
615 return vfs_fchmodat(dirfd, path, mode, flags);
616}
617
618DEFINE_SYSCALL(long, io_pread)(fd_t fd, void *buf, size_t count, off_t offset)
619{
620 if (fd < 0)
621 return -EBADF;
622
623 if (buf == NULL)
624 return -EFAULT;
625
627 if (!io)
628 return -EBADF;
629
630 return io_pread(io, buf, count, offset);
631}
632
634{
635 io_t *io = memfd_create(name);
636 if (IS_ERR(io))
637 return PTR_ERR(io);
638
639 return process_attach_ref_fd(current_process, io, flags);
640}
641
642DEFINE_SYSCALL(long, signal_mask_op)(int how, const sigset_t *set, sigset_t *oldset)
643{
644 if (oldset)
645 *oldset = current_thread->signal_info.mask;
646
647 if (set)
648 {
649 switch (how)
650 {
651 case SIG_SETMASK: current_thread->signal_info.mask = *set; break;
652 case SIG_BLOCK:
653 {
654 char *ptr = (char *) set;
655 char *mask = (char *) &current_thread->signal_info.mask;
656 for (size_t i = 0; i < sizeof(sigset_t); i++)
657 mask[i] |= ptr[i];
658 break;
659 }
660 case SIG_UNBLOCK:
661 {
662 char *ptr = (char *) set;
663 char *mask = (char *) &current_thread->signal_info.mask;
664 for (size_t i = 0; i < sizeof(sigset_t); i++)
665 mask[i] &= ~ptr[i];
666 break;
667 }
668 default: return -EINVAL;
669 }
670 }
671
672 return 0;
673}
674
675DEFINE_SYSCALL(long, vfs_fsync)(fd_t fd, bool data_only)
676{
678 if (!io)
679 return -EBADF;
680
681 if (io->type != IO_FILE)
682 return -EBADF;
683
684 return vfs_fsync(io, data_only, 0, (off_t) -1);
685}
#define mos_warn(fmt,...)
Definition assert.h:23
#define MOS_PAGE_SIZE
Definition autoconf.h:6
pfn_t dmabuf_allocate(size_t n_pages, ptr_t *pages)
Allocate DMA pages.
Definition dma.c:24
process_t * elf_create_process(const char *path, process_t *parent, const char *const argv[], const char *const envp[], const stdio_t *ios)
Definition elf.c:408
fstatat_flags
Definition fs_types.h:40
fd_flags_t
Definition fs_types.h:47
@ FD_FLAGS_CLOEXEC
Definition fs_types.h:49
@ FD_FLAGS_NONE
Definition fs_types.h:48
open_flags
Definition fs_types.h:26
long signal_send_to_process(process_t *target, signal_t signal)
Send a signal to a process, an arbitrary thread will be chosen to receive the signal.
Definition signal.c:126
long signal_send_to_thread(thread_t *target, signal_t signal)
Send a signal to a thread.
Definition signal.c:92
MOSAPI char * strdup(const char *src)
MOSAPI char * strncpy(char *__restrict dest, const char *__restrict src, size_t n)
Definition mos_string.c:202
MOSAPI void(1, 2) fatal_abort(const char *fmt
@ THREAD_MODE_USER
Definition task_types.h:22
long define_syscall vfs_chdirat(fd_t dirfd, const char *path)
Change the current working directory.
Definition ksyscall.c:348
long define_syscall vfs_symlink(const char *target, const char *linkpath)
Create a symbolic link.
Definition ksyscall.c:239
long define_syscall vfs_unmount(const char *path)
Unmount a filesystem at a given path.
Definition ksyscall.c:575
ssize_t define_syscall vfs_getcwd(char *buf, size_t size)
Get the current working directory.
Definition ksyscall.c:353
long define_syscall vfs_unlinkat(fd_t dirfd, const char *path)
Remove the name of a file, and possibly the file itself.
Definition ksyscall.c:234
long define_syscall vfs_mount(const char *device, const char *mountpoint, const char *fs_type, const char *options)
Mount a filesystem at a given existing path.
Definition ksyscall.c:224
long define_syscall vfs_mkdir(const char *path)
Create a directory.
Definition ksyscall.c:244
long define_syscall vfs_fchmodat(fd_t dirfd, const char *path, int mode, int flags)
Change the permissions of a file.
Definition ksyscall.c:613
ssize_t define_syscall vfs_readlinkat(fd_t dirfd, const char *path, char *buf, size_t buflen)
Read a symbolic link.
Definition ksyscall.c:229
io_t * io_ref(io_t *io)
Definition io.c:73
@ IO_FILE
Definition io.h:17
io_seek_whence_t
Definition io_types.h:6
const char ** argv
Definition kmain.c:44
bool define_syscall vm_protect(void *addr, size_t size, mem_perm_t perm)
Definition ksyscall.c:400
long define_syscall vfs_fsync(fd_t fd, bool data_only)
Definition ksyscall.c:675
void *define_syscall mmap_anonymous(ptr_t hint_addr, size_t size, mem_perm_t perm, mmap_flags_t flags)
Definition ksyscall.c:316
ssize_t define_syscall thread_getname(tid_t tid, char *buf, size_t buflen)
Definition ksyscall.c:602
long define_syscall vfs_fstatat(fd_t fd, const char *path, file_stat_t *stat_buf, fstatat_flags flags)
Definition ksyscall.c:69
bool define_syscall signal_register(signal_t sig, const sigaction_t *action)
Definition ksyscall.c:374
fd_t define_syscall memfd_create(const char *name, u32 flags)
Definition ksyscall.c:633
#define FD_ISSET(__fd, __set)
Definition ksyscall.c:430
fd_t define_syscall io_dup(fd_t fd)
Definition ksyscall.c:476
off_t define_syscall io_seek(fd_t fd, off_t offset, io_seek_whence_t whence)
Definition ksyscall.c:358
fd_t define_syscall ipc_accept(fd_t listen_fd)
Definition ksyscall.c:198
fd_t define_syscall io_dup2(fd_t oldfd, fd_t newfd)
Definition ksyscall.c:484
long define_syscall clock_msleep(u64 ms)
Definition ksyscall.c:470
long define_syscall signal_thread(tid_t tid, signal_t sig)
Definition ksyscall.c:387
pid_t define_syscall wait_for_process(pid_t pid, u32 *exit_code, u32 flags)
Definition ksyscall.c:338
long define_syscall signal_process(pid_t pid, signal_t sig)
Definition ksyscall.c:379
off_t define_syscall io_tell(fd_t fd)
Definition ksyscall.c:366
void define_syscall thread_exit(void)
Definition ksyscall.c:170
void define_syscall poweroff(bool reboot, u32 magic)
Definition ksyscall.c:38
pid_t define_syscall get_parent_pid(void)
Definition ksyscall.c:137
long define_syscall fd_manipulate(fd_t fd, u64 op, void *arg)
Definition ksyscall.c:257
int define_syscall io_pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask)
Definition ksyscall.c:441
#define POWEROFF_MAGIC
bool define_syscall munmap(void *addr, size_t size)
Definition ksyscall.c:343
fd_t define_syscall ipc_connect(const char *server, size_t buffer_size)
Connect to an IPC servers.
Definition ksyscall.c:211
bool define_syscall dmabuf_free(ptr_t vaddr, ptr_t paddr)
Definition ksyscall.c:507
void define_syscall exit(u32 exit_code)
Definition ksyscall.c:110
void define_syscall yield_cpu(void)
Definition ksyscall.c:117
bool define_syscall wait_for_thread(tid_t tid)
Definition ksyscall.c:175
long define_syscall io_pread(fd_t fd, void *buf, size_t count, off_t offset)
Definition ksyscall.c:618
long define_syscall signal_mask_op(int how, const sigset_t *set, sigset_t *oldset)
Definition ksyscall.c:642
size_t define_syscall vfs_list_dir(fd_t fd, char *buffer, size_t buffer_size)
Definition ksyscall.c:249
size_t define_syscall io_read(fd_t fd, void *buf, size_t count)
Definition ksyscall.c:74
ssize_t define_syscall io_readv(fd_t fd, const struct iovec *iov, int iovcnt)
Definition ksyscall.c:540
void *define_syscall mmap_file(ptr_t hint_addr, size_t size, mem_perm_t perm, mmap_flags_t mmap_flags, fd_t fd, off_t offset)
Definition ksyscall.c:325
bool define_syscall dmabuf_alloc(size_t n_pages, ptr_t *phys, ptr_t *virt)
Definition ksyscall.c:500
bool define_syscall dmabuf_unshare(ptr_t phys, size_t size, void *buf)
Definition ksyscall.c:523
long define_syscall pipe(fd_t *reader, fd_t *writer, fd_flags_t flags)
Definition ksyscall.c:528
pid_t define_syscall get_pid(void)
Definition ksyscall.c:132
u64 define_syscall arch_syscall(u64 syscall, u64 arg1, u64 arg2, u64 arg3, u64 arg4)
Definition ksyscall.c:219
pid_t define_syscall spawn(const char *path, const char *const argv[], const char *const envp[])
Definition ksyscall.c:142
int define_syscall io_poll(struct pollfd *fds, nfds_t nfds, int timeout)
Definition ksyscall.c:405
fd_t define_syscall vfs_openat(fd_t dirfd, const char *path, open_flags flags)
Definition ksyscall.c:58
long define_syscall execveat(fd_t dirfd, const char *path, const char *const argv[], const char *const envp[], u32 flags)
Definition ksyscall.c:465
tid_t define_syscall get_tid(void)
Definition ksyscall.c:165
fd_t define_syscall ipc_create(const char *name, size_t max_pending_connections)
Create a new IPC server.
Definition ksyscall.c:190
tid_t define_syscall create_thread(const char *name, thread_entry_t entry, void *arg, size_t stack_size, void *stack)
Definition ksyscall.c:153
void define_syscall signal_return(void *sp)
Definition ksyscall.c:395
#define DEFINE_SYSCALL(ret, name)
Definition ksyscall.c:34
size_t define_syscall io_write(fd_t fd, const void *buf, size_t count)
Definition ksyscall.c:86
bool define_syscall dmabuf_share(void *buffer, size_t size, ptr_t *phyaddr)
Definition ksyscall.c:512
long define_syscall thread_setname(tid_t tid, const char *name)
Definition ksyscall.c:589
long define_syscall clock_gettimeofday(struct timespec *ts)
Definition ksyscall.c:580
bool define_syscall io_close(fd_t fd)
Definition ksyscall.c:104
pid_t define_syscall fork(void)
Definition ksyscall.c:123
mem_perm_t
Definition mm_types.h:7
mmap_flags_t
Definition mm_types.h:15
#define ALIGN_UP_TO_PAGE(addr)
Definition mos_global.h:75
#define MOS_UNUSED(x)
Definition mos_global.h:64
#define IS_ERR_VALUE(x)
Definition mos_global.h:126
#define unlikely(x)
Definition mos_global.h:40
#define futex_wake(futex, val)
Definition mutex.c:10
#define futex_wait(futex, val)
Definition mutex.c:9
#define NULL
Definition pb_syshdr.h:46
pipeio_t * pipeio_create(pipe_t *pipe)
Definition pipe.c:228
pipe_t * pipe_create(size_t bufsize)
Definition pipe.c:174
#define current_thread
Definition platform.h:30
vm_flags
Definition platform.h:40
@ VM_USER
Definition platform.h:45
#define current_mm
Definition platform.h:32
#define current_process
Definition platform.h:31
void power_shutdown(void)
Shutdown the system.
Definition power.c:33
#define pr_info2(fmt,...)
Definition printk.h:36
#define pr_warn(fmt,...)
Definition printk.h:38
#define pr_emerg(fmt,...)
Definition printk.h:39
#define pr_info(fmt,...)
Definition printk.h:35
fd_t process_attach_ref_fd(process_t *process, io_t *file, fd_flags_t flags)
Definition process.c:171
pid_t process_wait_for_pid(pid_t pid, u32 *exit_code, u32 flags)
Definition process.c:215
bool process_register_signal_handler(process_t *process, signal_t sig, const sigaction_t *sigaction)
Definition process.c:380
long process_do_execveat(process_t *process, fd_t dirfd, const char *path, const char *const argv[], const char *const envp[], int flags)
Definition execve.c:18
process_t * process_get(pid_t pid)
Definition process.c:162
should_inline stdio_t current_stdio(void)
Definition process.h:28
void process_exit(process_t *process, u8 exit_code, signal_t signal)
Definition process.c:281
io_t * process_get_fd(process_t *process, fd_t fd)
Definition process.c:192
process_t * process_do_fork(process_t *process)
Definition fork.c:26
bool process_detach_fd(process_t *process, fd_t fd)
Definition process.c:200
void platform_context_setup_child_thread(thread_t *thread, thread_entry_t entry, void *arg)
u64 platform_arch_syscall(u64 syscall, u64 arg1, u64 arg2, u64 arg3, u64 arg4)
void platform_restore_from_signal_handler(void *sp)
void reschedule(void)
reschedule.
Definition schedule.c:107
void scheduler_add_thread(thread_t *thread)
Add a thread to the scheduler, so that it can be scheduled.
Definition schedule.c:78
int signal_t
Definition signal_types.h:9
size_t size
Definition slab.c:30
const char * name
Definition slab.c:31
#define spinlock_acquire(lock)
Definition spinlock.h:61
fd_flags_t flags
Definition task_types.h:37
io_t * io
Definition task_types.h:36
io_t io
Definition vfs_types.h:199
Definition io.h:46
io_type_t type
Definition io.h:50
io_flags_t flags
Definition io.h:49
Definition pipe.h:11
io_t io_w
Definition pipe.h:35
io_t io_r
Definition pipe.h:35
pid_t pid
Definition task_types.h:45
A wrapper type for the standard I/O streams.
Definition process.h:17
const char * name
Definition task_types.h:78
tid_t tid
Definition task_types.h:77
static char buffer[2048]
Definition test_printf.c:7
thread_t * thread_get(tid_t id)
Definition thread.c:166
bool thread_wait_for_tid(tid_t tid)
Definition thread.c:175
thread_t * thread_complete_init(thread_t *thread)
Definition thread.c:156
thread_t * thread_new(process_t *owner, thread_mode mode, const char *name, size_t stack_size, void *stack)
Definition thread.c:77
long timer_msleep(u64 ms)
Definition timer.c:39
unsigned int u32
Definition types.h:21
s32 futex_word_t
Definition types.h:99
unsigned long long pfn_t
Definition types.h:41
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
void platform_get_time(timeval_t *time)