Use process struct flag to indicate tracing instead of scanning an array.
[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_SYSTRACES                           1024
15
16 #define SYSCALL_STRLEN                          128
17
18 #define MAX_ASRC_BATCH                          10
19
20 #define SYSTR_RECORD_SZ                         256
21 #define SYSTR_BUF_SZ                            PGSIZE
22 #define SYSTR_PRETTY_BUF_SZ                     (SYSTR_BUF_SZ -                            \
23                                      sizeof(struct systrace_record))
24 struct systrace_record {
25         struct systrace_record_anon {
26                 uint64_t                start_timestamp, end_timestamp;
27                 uintreg_t               syscallno;
28                 uintreg_t               arg0;
29                 uintreg_t               arg1;
30                 uintreg_t               arg2;
31                 uintreg_t               arg3;
32                 uintreg_t               arg4;
33                 uintreg_t               arg5;
34                 uintreg_t               retval;
35                 int                             pid;
36                 uint32_t                coreid;
37                 uint32_t                vcoreid;
38                 char                    *pretty_buf;
39                 uint8_t                 datalen;
40         };
41         uint8_t                 data[SYSTR_RECORD_SZ - sizeof(struct systrace_record_anon)];
42 };
43
44 /* Syscall table */
45 typedef intreg_t (*syscall_t)(struct proc *, uintreg_t, uintreg_t, uintreg_t,
46                               uintreg_t, uintreg_t, uintreg_t);
47 struct sys_table_entry {
48         syscall_t call;
49         char *name;
50 };
51 extern const struct sys_table_entry syscall_table[];
52 extern const int max_syscall;
53 /* Syscall invocation */
54 void prep_syscalls(struct proc *p, struct syscall *sysc, unsigned int nr_calls);
55 void run_local_syscall(struct syscall *sysc);
56 intreg_t syscall(struct proc *p, uintreg_t sc_num, uintreg_t a0, uintreg_t a1,
57                  uintreg_t a2, uintreg_t a3, uintreg_t a4, uintreg_t a5);
58 void set_errno(int errno);
59 int get_errno(void);
60 void unset_errno(void);
61 void set_errstr(const char *errstr, ...);
62 char *current_errstr(void);
63 struct errbuf *get_cur_errbuf(void);
64 void set_cur_errbuf(struct errbuf *ebuf);
65 char *get_cur_genbuf(void);
66 void __signal_syscall(struct syscall *sysc, struct proc *p);
67
68 /* Tracing functions */
69 void systrace_start(bool silent);
70 int systrace_trace_pid(struct proc *p);
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 */