akaros/kern/include/ros/syscall.h
<<
>>
Prefs
   1#pragma once
   2
   3#include <ros/bits/syscall.h>
   4#include <ros/arch/syscall.h>
   5#include <ros/event.h>
   6#include <ros/atomic.h>
   7
   8/* Flags for an individual syscall. */
   9#define SC_DONE                 0x0001  /* SC is done */
  10#define SC_PROGRESS             0x0002  /* SC made progress */
  11#define SC_UEVENT               0x0004  /* user has an ev_q */
  12#define SC_K_LOCK               0x0008  /* kernel locked sysc */
  13#define SC_ABORT                0x0010  /* syscall abort attempted */
  14
  15#define MAX_ERRSTR_LEN          128
  16#define SYSTR_BUF_SZ            PGSIZE
  17
  18struct syscall {
  19        unsigned int                    num;
  20        int                             err;            /* errno */
  21        long                            retval;
  22        atomic_t                        flags;
  23        struct event_queue              *ev_q;
  24        void                            *u_data;
  25        long                            arg0;
  26        long                            arg1;
  27        long                            arg2;
  28        long                            arg3;
  29        long                            arg4;
  30        long                            arg5;
  31        char                            errstr[MAX_ERRSTR_LEN];
  32};
  33
  34static inline bool syscall_retval_is_error(unsigned int sysc_nr, long retval)
  35{
  36        switch (sysc_nr) {
  37        case SYS_getpcoreid:
  38        case SYS_getvcoreid:
  39        case SYS_reboot:
  40        case SYS_proc_yield:
  41        case SYS_vc_entry:
  42        case SYS_umask:
  43        case SYS_init_arsc:
  44                return false;
  45        case SYS_abort_sysc:
  46        case SYS_abort_sysc_fd:
  47                /* These two are a little weird */
  48                return false;
  49        case SYS_null:
  50        case SYS_block:
  51        case SYS_nanosleep:
  52        case SYS_cache_invalidate:
  53        case SYS_proc_run:
  54        case SYS_proc_destroy:
  55        case SYS_exec:
  56        case SYS_munmap:
  57        case SYS_mprotect:
  58        case SYS_notify:
  59        case SYS_self_notify:
  60        case SYS_send_event:
  61        case SYS_halt_core:
  62        case SYS_pop_ctx:
  63        case SYS_vmm_poke_guest:
  64        case SYS_poke_ksched:
  65        case SYS_llseek:
  66        case SYS_close:
  67        case SYS_fstat:
  68        case SYS_stat:
  69        case SYS_lstat:
  70        case SYS_access:
  71        case SYS_link:
  72        case SYS_unlink:
  73        case SYS_symlink:
  74        case SYS_chdir:
  75        case SYS_fchdir:
  76        case SYS_mkdir:
  77        case SYS_rmdir:
  78        case SYS_tcgetattr:
  79        case SYS_tcsetattr:
  80        case SYS_setuid:
  81        case SYS_setgid:
  82        case SYS_rename:
  83        case SYS_nunmount:
  84        case SYS_fd2path:
  85                return retval != 0;
  86        case SYS_proc_create:
  87        case SYS_change_vcore:
  88        case SYS_fork:
  89        case SYS_waitpid:
  90        case SYS_shared_page_alloc:
  91        case SYS_shared_page_free:
  92        case SYS_provision:
  93        case SYS_change_to_m:
  94        case SYS_vmm_ctl:
  95        case SYS_read:
  96        case SYS_write:
  97        case SYS_openat:
  98        case SYS_fcntl:
  99        case SYS_readlink:
 100        case SYS_getcwd:
 101        case SYS_nbind:
 102        case SYS_nmount:
 103        case SYS_wstat:
 104        case SYS_fwstat:
 105                return retval < 0;
 106        case SYS_mmap:
 107                return retval == -1; /* MAP_FAILED */
 108        case SYS_vmm_add_gpcs:
 109        case SYS_populate_va:
 110        case SYS_dup_fds_to:
 111        case SYS_tap_fds:
 112                return retval <= 0;
 113        };
 114        return true;
 115}
 116
 117struct childfdmap {
 118        unsigned int                    parentfd;
 119        unsigned int                    childfd;
 120        int                             ok;
 121};
 122
 123struct argenv {
 124        size_t argc;
 125        size_t envc;
 126        char buf[];
 127        /* The buf array is laid out as follows:
 128         * buf {
 129         *   char *argv[argc]; // Offset of arg relative to &argbuf[0]
 130         *   char *envp[envc]; // Offset of envvar relative to &argbuf[0]
 131         *   char argbuf[sum(map(strlen + 1, argv + envp))];
 132         * }
 133         */
 134};
 135
 136#ifndef ROS_KERNEL
 137
 138/* Temp hack, til the rest of glibc/userspace uses sys/syscall.h */
 139#include <sys/syscall.h>
 140#endif /* ifndef ROS_KERNEL */
 141