Fixes netlog
[akaros.git] / kern / include / syscall.h
1 #ifndef ROS_KERN_SYSCALL_H
2 #define ROS_KERN_SYSCALL_H
3 #ifndef ROS_KERNEL
4 # error "This is ROS kernel header; user programs should not #include it"
5 #endif
6
7 #include <ros/common.h>
8 #include <process.h>
9
10 #define SYSTRACE_ON                                     0x01
11 #define SYSTRACE_LOUD                           0x02
12 #define SYSTRACE_ALLPROC                        0x04
13
14 #define MAX_NUM_TRACED                          10
15 #define MAX_SYSTRACES                           1024
16
17 #define SYSCALL_STRLEN                          128
18
19 #define MAX_ASRC_BATCH                          10
20
21 #define SYSTR_RECORD_SZ                         256
22 #define SYSTR_BUF_SZ                            PGSIZE
23 #define SYSTR_PRETTY_BUF_SZ                     (SYSTR_BUF_SZ -                            \
24                                      sizeof(struct systrace_record))
25 struct systrace_record {
26         struct systrace_record_anon {
27                 uint64_t                start_timestamp, end_timestamp;
28                 uintreg_t               syscallno;
29                 uintreg_t               arg0;
30                 uintreg_t               arg1;
31                 uintreg_t               arg2;
32                 uintreg_t               arg3;
33                 uintreg_t               arg4;
34                 uintreg_t               arg5;
35                 uintreg_t               retval;
36                 int                             pid;
37                 uint32_t                coreid;
38                 uint32_t                vcoreid;
39                 char                    *pretty_buf;
40                 uint8_t                 datalen;
41         };
42         uint8_t                 data[SYSTR_RECORD_SZ - sizeof(struct systrace_record_anon)];
43 };
44
45 /* Syscall table */
46 typedef intreg_t (*syscall_t)(struct proc *, uintreg_t, uintreg_t, uintreg_t,
47                               uintreg_t, uintreg_t, uintreg_t);
48 struct sys_table_entry {
49         syscall_t call;
50         char *name;
51 };
52 extern const struct sys_table_entry syscall_table[];
53 extern const int max_syscall;
54 /* Syscall invocation */
55 void prep_syscalls(struct proc *p, struct syscall *sysc, unsigned int nr_calls);
56 void run_local_syscall(struct syscall *sysc);
57 intreg_t syscall(struct proc *p, uintreg_t sc_num, uintreg_t a0, uintreg_t a1,
58                  uintreg_t a2, uintreg_t a3, uintreg_t a4, uintreg_t a5);
59 void set_errno(int errno);
60 int get_errno(void);
61 void unset_errno(void);
62 void set_errstr(char *errstr, ...);
63 char *current_errstr(void);
64 struct errbuf *get_cur_errbuf(void);
65 void set_cur_errbuf(struct errbuf *ebuf);
66 char *get_cur_genbuf(void);
67 void __signal_syscall(struct syscall *sysc, struct proc *p);
68
69 /* Tracing functions */
70 void systrace_start(bool silent);
71 void systrace_stop(void);
72 int systrace_reg(bool all, struct proc *p);
73 int systrace_dereg(bool all, struct proc *p);
74 void systrace_print(bool all, struct proc *p);
75 void systrace_clear_buffer(void);
76
77 /* Utility */
78 bool syscall_uses_fd(struct syscall *sysc, int fd);
79 void print_sysc(struct proc *p, struct syscall *sysc);
80
81 #endif /* !ROS_KERN_SYSCALL_H */