akaros/tools/syscall_server/syscall_server.h
<<
>>
Prefs
   1#ifndef SERIAL_SERVER_H
   2#define SERIAL_SERVER_H
   3
   4#include <stdint.h>
   5#include <sys/stat.h>
   6#include <newlib_trans.h>
   7
   8#define SANDBOX_DIR "sandbox/"
   9
  10#define OPEN_ID                 0
  11#define CLOSE_ID                1
  12#define READ_ID                 2
  13#define WRITE_ID                3
  14#define LINK_ID                 4
  15#define UNLINK_ID               5
  16#define LSEEK_ID                6
  17#define FSTAT_ID                7
  18#define ISATTY_ID               8
  19#define STAT_ID                 9
  20#define NUM_SYSCALLS    10
  21
  22typedef uint32_t syscall_id_t;
  23
  24typedef struct open_subheader {
  25        uint32_t flags;
  26        uint32_t mode;
  27        uint32_t len;
  28} open_subheader_t;
  29
  30typedef struct close_subheader {
  31        uint32_t fd;
  32        uint32_t FILL1;
  33        uint32_t FILL2;
  34} close_subheader_t;
  35
  36typedef struct read_subheader {
  37        uint32_t fd;
  38        uint32_t len;
  39        uint32_t FILL1;
  40} read_subheader_t;
  41
  42typedef struct write_subheader {
  43        uint32_t fd;
  44        uint32_t len;
  45        uint32_t FILL1;
  46} write_subheader_t;
  47
  48typedef struct lseek_subheader {
  49        uint32_t fd;
  50        uint32_t ptr;
  51        uint32_t dir;
  52} lseek_subheader_t;
  53
  54typedef struct isatty_subheader {
  55        uint32_t fd;
  56        uint32_t FILL1;
  57        uint32_t FILL2;
  58} isatty_subheader_t;
  59
  60typedef struct link_subheader {
  61        uint32_t old_len;
  62        uint32_t new_len;
  63        uint32_t FILL1;
  64} link_subheader_t;
  65
  66typedef struct unlink_subheader {
  67        uint32_t len;
  68        uint32_t FILL1;
  69        uint32_t FILL2;
  70} unlink_subheader_t;
  71
  72typedef struct fstat_subheader {
  73        uint32_t fd;
  74        uint32_t FILL1;
  75        uint32_t FILL2;
  76} fstat_subheader_t;
  77
  78typedef struct stat_subheader {
  79        uint32_t len;
  80        uint32_t FILL1;
  81        uint32_t FILL2;
  82} stat_subheader_t;
  83
  84typedef struct syscall_req_header {
  85        syscall_id_t id;
  86        union {
  87                open_subheader_t open;
  88                close_subheader_t close;
  89                read_subheader_t read;
  90                write_subheader_t write;
  91                lseek_subheader_t lseek;
  92                isatty_subheader_t isatty;
  93                link_subheader_t link;
  94                unlink_subheader_t unlink;
  95                fstat_subheader_t fstat;
  96                stat_subheader_t stat;  
  97        } subheader;
  98} syscall_req_header_t;
  99
 100typedef struct syscall_req {
 101        syscall_req_header_t header;
 102        uint32_t payload_len;
 103        void* payload;
 104} syscall_req_t;
 105
 106typedef struct syscall_rsp_header {
 107        int32_t return_val;
 108        uint32_t return_errno;
 109} syscall_rsp_header_t;
 110
 111typedef struct syscall_rsp {
 112        syscall_rsp_header_t header;
 113        uint32_t payload_len;
 114        void* payload;
 115} syscall_rsp_t;
 116
 117void run_server();
 118int init_syscall_server(int* fd_read, int* fd_write);
 119void translate_stat(struct stat* native, struct newlib_stat* newlib);
 120int translate_flags(int native_flags);
 121int translate_mode(int native_mode);
 122int translate_whence(int native_whence);
 123void translate_errno(int native, int newlib);
 124void set_syscall_req_payload_len(syscall_req_t* req);
 125void read_syscall_req(int fd, syscall_req_t* req);
 126void read_syscall_req_header(int fd, syscall_req_t* req);
 127void read_syscall_req_payload(int fd, syscall_req_t* req);
 128void write_syscall_rsp(int fd, syscall_rsp_t* rsp);
 129void write_syscall_rsp_header(int fd, syscall_rsp_t* rsp);
 130void write_syscall_rsp_payload(int fd, syscall_rsp_t* rsp);
 131int read_syscall_server(int fd, char* buf, int len);
 132int write_syscall_server(int fd, char* buf, int len, int bytes_to_follow); 
 133void error(int fd, const char* s);
 134char* sandbox_file_name(char* name, uint32_t len);
 135
 136void handle_syscall(syscall_req_t* req, syscall_rsp_t* rsp);
 137void handle_open(syscall_req_t* req, syscall_rsp_t* rsp);
 138void handle_close(syscall_req_t* req, syscall_rsp_t* rsp);
 139void handle_read(syscall_req_t* req, syscall_rsp_t* rsp);
 140void handle_write(syscall_req_t* req, syscall_rsp_t* rsp);
 141void handle_link(syscall_req_t* req, syscall_rsp_t* rsp);
 142void handle_unlink(syscall_req_t* req, syscall_rsp_t* rsp);
 143void handle_lseek(syscall_req_t* req, syscall_rsp_t* rsp);
 144void handle_fstat(syscall_req_t* req, syscall_rsp_t* rsp);
 145void handle_isatty(syscall_req_t* req, syscall_rsp_t* rsp);
 146void handle_stat(syscall_req_t* req, syscall_rsp_t* rsp);
 147
 148#endif //SERIAL_SERVER_H
 149