summaryrefslogtreecommitdiff
path: root/userland/libc/include/syscall.h
blob: 3699854636225f1450fd24de73c4f39e0c17007c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#ifndef SYSCALL_H
#define SYSCALL_H
#include <stddef.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/types.h>

#define SYS_OPEN 0
#define SYS_READ 1
#define SYS_WRITE 2
#define SYS_PREAD 3
#define SYS_PWRITE 4
#define SYS_FORK 5
#define SYS_EXEC 6
#define SYS_GETPID 7
#define SYS_EXIT 8
#define SYS_WAIT 9
#define SYS_BRK 10
#define SYS_SBRK 11
#define SYS_PIPE 12
#define SYS_DUP2 13
#define SYS_CLOSE 14
#define SYS_OPENPTY 15
#define SYS_POLL 16
#define SYS_MMAP 17
#define SYS_ACCEPT 18
#define SYS_BIND 19
#define SYS_SOCKET 20
#define SYS_SHM_OPEN 21
#define SYS_FTRUNCATE 22
#define SYS_FSTAT 23
#define SYS_MSLEEP 24
#define SYS_UPTIME 25
#define SYS_MKDIR 26
#define SYS_RECVFROM 27
#define SYS_SENDTO 28
#define SYS_SIGACTION 29
#define SYS_CHDIR 30
#define SYS_GETCWD 31
#define SYS_ISATTY 32
#define SYS_RANDOMFILL 33
#define SYS_MUNMAP 34
#define SYS_LSEEK 35
#define SYS_CONNECT 36
#define SYS_SETSOCKOPT 37
#define SYS_GETPEERNAME 38
#define SYS_FCNTL 39
#define SYS_CLOCK_GETTIME 40
#define SYS_QUEUE_CREATE 41
#define SYS_QUEUE_MOD_ENTRIES 42
#define SYS_QUEUE_WAIT 43
#define SYS_SENDFILE 44
#define SYS_SHM_UNLINK 45
#define SYS_DUP 46

int syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx,
            uint32_t esi, uint32_t edi);
int s_syscall(int sys);

extern int errno;
#define RC_ERRNO(_rc)                                                          \
  {                                                                            \
    int c = _rc;                                                               \
    if (c < 0) {                                                               \
      errno = -(c);                                                            \
      return -1;                                                               \
    }                                                                          \
    return c;                                                                  \
  }

typedef struct SYS_OPEN_PARAMS {
  const char *file;
  int flags;
  int mode;
} __attribute__((packed)) SYS_OPEN_PARAMS;

typedef struct SYS_PREAD_PARAMS {
  int fd;
  void *buf;
  size_t count;
  size_t offset;
} __attribute__((packed)) SYS_PREAD_PARAMS;

typedef struct SYS_READ_PARAMS {
  int fd;
  void *buf;
  size_t count;
} __attribute__((packed)) SYS_READ_PARAMS;

typedef struct SYS_PWRITE_PARAMS {
  int fd;
  const void *buf;
  size_t count;
  size_t offset;
} __attribute__((packed)) SYS_PWRITE_PARAMS;

typedef struct SYS_WRITE_PARAMS {
  int fd;
  const void *buf;
  size_t count;
} __attribute__((packed)) SYS_WRITE_PARAMS;

typedef struct SYS_EXEC_PARAMS {
  const char *path;
  char **argv;
} __attribute__((packed)) SYS_EXEC_PARAMS;

typedef struct SYS_DUP2_PARAMS {
  int org_fd;
  int new_fd;
} __attribute__((packed)) SYS_DUP2_PARAMS;

typedef struct SYS_OPENPTY_PARAMS {
  int *amaster;
  int *aslave;
  char *name;
  /*const struct termios*/ void *termp;
  /*const struct winsize*/ void *winp;
} __attribute__((packed)) SYS_OPENPTY_PARAMS;

typedef struct SYS_POLL_PARAMS {
  struct pollfd *fds;
  size_t nfds;
  int timeout;
} __attribute__((packed)) SYS_POLL_PARAMS;

typedef struct SYS_MMAP_PARAMS {
  void *addr;
  size_t length;
  int prot;
  int flags;
  int fd;
  size_t offset;
} __attribute__((packed)) SYS_MMAP_PARAMS;

typedef struct SYS_SOCKET_PARAMS {
  int domain;
  int type;
  int protocol;
} __attribute__((packed)) SYS_SOCKET_PARAMS;

typedef struct SYS_BIND_PARAMS {
  int sockfd;
  const struct sockaddr *addr;
  socklen_t addrlen;
} __attribute__((packed)) SYS_BIND_PARAMS;

typedef struct SYS_ACCEPT_PARAMS {
  int socket;
  struct sockaddr *address;
  socklen_t *address_len;
} __attribute__((packed)) SYS_ACCEPT_PARAMS;

typedef struct SYS_SHM_OPEN_PARAMS {
  const char *name;
  int oflag;
  mode_t mode;
} __attribute__((packed)) SYS_SHM_OPEN_PARAMS;

typedef struct SYS_FTRUNCATE_PARAMS {
  int fildes;
  size_t length;
} __attribute__((packed)) SYS_FTRUNCATE_PARAMS;
#endif