Move all of the files in include/libc/... down to the top level include path.
[newos.git] / include / sys / syscalls.h
blobd2160416e277dd713327c5031e965e87a0d8319a
1 /*
2 ** Copyright 2001-2004, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
5 #ifndef _LIBSYS_SYSCALLS_H
6 #define _LIBSYS_SYSCALLS_H
8 #include <kernel/ktypes.h>
9 #include <newos/types.h>
10 #include <newos/defines.h>
11 #include <sys/resource.h>
12 #include <signal.h>
14 typedef enum {
15 STREAM_TYPE_ANY = 0,
16 STREAM_TYPE_FILE,
17 STREAM_TYPE_DIR,
18 STREAM_TYPE_DEVICE,
19 STREAM_TYPE_PIPE
20 } stream_type;
22 typedef enum {
23 _SEEK_SET = 0,
24 _SEEK_CUR,
25 _SEEK_END
26 } seek_type;
28 struct file_stat {
29 vnode_id vnid;
30 stream_type type;
31 off_t size;
34 #define SEM_FLAG_NO_RESCHED 1
35 #define SEM_FLAG_TIMEOUT 2
36 #define SEM_FLAG_INTERRUPTABLE 4
38 #define PORT_FLAG_TIMEOUT 2
40 // info about a region that external entities may want to know
41 typedef struct vm_region_info {
42 region_id id;
43 addr_t base;
44 addr_t size;
45 int lock;
46 int wiring;
47 char name[SYS_MAX_OS_NAME_LEN];
48 } vm_region_info;
50 typedef struct sem_info {
51 sem_id sem;
52 proc_id proc;
53 char name[SYS_MAX_OS_NAME_LEN];
54 int32 count;
55 thread_id latest_holder;
56 } sem_info;
58 typedef struct port_info {
59 port_id id;
60 proc_id owner;
61 char name[SYS_MAX_OS_NAME_LEN];
62 int32 capacity;
63 int32 queue_count;
64 int32 total_count;
65 } port_info;
67 struct proc_info {
68 proc_id pid;
69 proc_id ppid;
70 pgrp_id pgid;
71 sess_id sid;
72 int state;
73 int num_threads;
74 char name[SYS_MAX_OS_NAME_LEN];
77 struct thread_info {
78 thread_id id;
79 proc_id owner_proc_id;
81 char name[SYS_MAX_OS_NAME_LEN];
82 int state;
83 int priority;
85 addr_t user_stack_base;
87 bigtime_t user_time;
88 bigtime_t kernel_time;
91 // args to proc_create_proc()
92 enum {
93 PROC_FLAG_SUSPENDED = 1,
94 PROC_FLAG_NEW_PGROUP = 2,
95 PROC_FLAG_NEW_SESSION = 4
98 // args for the create_area funcs
99 enum {
100 REGION_ADDR_ANY_ADDRESS = 0,
101 REGION_ADDR_EXACT_ADDRESS
104 enum {
105 REGION_WIRING_LAZY = 0,
106 REGION_WIRING_WIRED,
107 REGION_WIRING_WIRED_ALREADY,
108 REGION_WIRING_WIRED_CONTIG
111 enum {
112 REGION_NO_PRIVATE_MAP = 0,
113 REGION_PRIVATE_MAP
116 #define LOCK_RO 0x0
117 #define LOCK_RW 0x1
118 #define LOCK_KERNEL 0x2
119 #define LOCK_MASK 0x3
121 // state of the vm
122 typedef struct {
123 // info about the size of memory in the system
124 int physical_page_size;
125 int physical_pages;
127 // amount of virtual memory left to commit
128 int max_commit;
130 // info about the page queues
131 int active_pages;
132 int inactive_pages;
133 int busy_pages;
134 int unused_pages;
135 int modified_pages;
136 int modified_temporary_pages;
137 int free_pages;
138 int clear_pages;
139 int wired_pages;
141 // info about vm activity
142 int page_faults;
143 } vm_info_t;
145 typedef enum {
146 TIMER_MODE_ONESHOT = 0,
147 TIMER_MODE_PERIODIC
148 } timer_mode;
150 #ifdef __cplusplus
151 extern "C" {
152 #endif
154 int _kern_null(void);
156 /* fs api */
157 int _kern_mount(const char *path, const char *device, const char *fs_name, void *args);
158 int _kern_unmount(const char *path);
159 int _kern_sync(void);
160 int _kern_opendir(const char *path);
161 int _kern_closedir(int fd);
162 int _kern_rewinddir(int fd);
163 int _kern_readdir(int fd, void *buf, size_t len);
164 int _kern_open(const char *path, int omode);
165 int _kern_close(int fd);
166 int _kern_fsync(int fd);
167 ssize_t _kern_read(int fd, void *buf, off_t pos, ssize_t len);
168 ssize_t _kern_write(int fd, const void *buf, off_t pos, ssize_t len);
169 int _kern_seek(int fd, off_t pos, seek_type seek_type);
170 int _kern_ioctl(int fd, int op, void *buf, size_t len);
171 int _kern_create(const char *path);
172 int _kern_unlink(const char *path);
173 int _kern_rename(const char *oldpath, const char *newpath);
174 int _kern_mkdir(const char *path);
175 int _kern_rmdir(const char *path);
176 int _kern_rstat(const char *path, struct file_stat *stat);
177 int _kern_wstat(const char *path, struct file_stat *stat, int stat_mask);
178 int _kern_getcwd(char* buf, size_t size);
179 int _kern_setcwd(const char* path);
180 int _kern_dup(int fd);
181 int _kern_dup2(int ofd, int nfd);
183 bigtime_t _kern_system_time(void);
184 int _kern_snooze(bigtime_t time);
185 int _kern_getrlimit(int resource, struct rlimit * rlp);
186 int _kern_setrlimit(int resource, const struct rlimit * rlp);
188 /* sem functions */
189 sem_id _kern_sem_create(int count, const char *name);
190 int _kern_sem_delete(sem_id id);
191 int _kern_sem_acquire(sem_id id, int count);
192 int _kern_sem_acquire_etc(sem_id id, int count, int flags, bigtime_t timeout);
193 int _kern_sem_release(sem_id id, int count);
194 int _kern_sem_release_etc(sem_id id, int count, int flags);
195 int _kern_sem_get_count(sem_id id, int32* thread_count);
196 int _kern_sem_get_sem_info(sem_id id, struct sem_info *info);
197 int _kern_sem_get_next_sem_info(proc_id proc, uint32 *cookie, struct sem_info *info);
198 int _kern_set_sem_owner(sem_id id, proc_id proc);
200 thread_id _kern_get_current_thread_id(void);
201 void _kern_exit(int retcode);
202 proc_id _kern_proc_create_proc(const char *path, const char *name, char **args, int argc, int priority, int flags);
203 thread_id _kern_thread_create_thread(const char *name, int (*func)(void *args), void *args);
204 int _kern_thread_set_priority(thread_id tid, int priority);
205 int _kern_thread_wait_on_thread(thread_id tid, int *retcode);
206 int _kern_thread_suspend_thread(thread_id tid);
207 int _kern_thread_resume_thread(thread_id tid);
208 int _kern_thread_kill_thread(thread_id tid);
209 int _kern_thread_get_thread_info(thread_id id, struct thread_info *info);
210 int _kern_thread_get_next_thread_info(uint32 *cookie, proc_id pid, struct thread_info *info);
211 int _kern_proc_kill_proc(proc_id pid);
212 proc_id _kern_get_current_proc_id(void);
213 int _kern_proc_wait_on_proc(proc_id pid, int *retcode);
214 int _kern_proc_get_proc_info(proc_id id, struct proc_info *info);
215 int _kern_proc_get_next_proc_info(uint32 *cookie, struct proc_info *info);
216 region_id _kern_vm_create_anonymous_region(const char *name, void **address, int addr_type,
217 addr_t size, int wiring, int lock);
218 region_id _kern_vm_clone_region(const char *name, void **address, int addr_type,
219 region_id source_region, int mapping, int lock);
220 region_id _kern_vm_map_file(const char *name, void **address, int addr_type,
221 addr_t size, int lock, int mapping, const char *path, off_t offset);
222 int _kern_vm_delete_region(region_id id);
223 int _kern_vm_get_region_info(region_id id, vm_region_info *info);
224 int _kern_vm_get_vm_info(vm_info_t *uinfo);
226 /* process group/session group functions */
227 int _kern_setpgid(proc_id, pgrp_id);
228 pgrp_id _kern_getpgid(proc_id);
229 sess_id _kern_setsid(void);
231 /* kernel port functions */
232 port_id _kern_port_create(int32 queue_length, const char *name);
233 int _kern_port_close(port_id id);
234 int _kern_port_delete(port_id id);
235 port_id _kern_port_find(const char *port_name);
236 int _kern_port_get_info(port_id id, struct port_info *info);
237 int _kern_port_get_next_port_info(proc_id proc, uint32 *cookie, struct port_info *info);
238 ssize_t _kern_port_buffer_size(port_id port);
239 ssize_t _kern_port_buffer_size_etc(port_id port, uint32 flags, bigtime_t timeout);
240 int32 _kern_port_count(port_id port);
241 ssize_t _kern_port_read(port_id port, int32 *msg_code, void *msg_buffer, size_t buffer_size);
242 ssize_t _kern_port_read_etc(port_id port, int32 *msg_code, void *msg_buffer, size_t buffer_size, uint32 flags, bigtime_t timeout);
243 int _kern_port_set_owner(port_id port, proc_id proc);
244 int _kern_port_write(port_id port, int32 msg_code, void *msg_buffer, size_t buffer_size);
245 int _kern_port_write_etc(port_id port, int32 msg_code, void *msg_buffer, size_t buffer_size, uint32 flags, bigtime_t timeout);
247 /* atomic_* ops (needed for cpus that dont support them directly) */
248 int _kern_atomic_add(int *val, int incr);
249 int _kern_atomic_and(int *val, int incr);
250 int _kern_atomic_or(int *val, int incr);
251 int _kern_atomic_set(int *val, int set_to);
252 int _kern_test_and_set(int *val, int set_to, int test_val);
254 /* signals */
255 int _kern_sigaction(int sig, const struct sigaction *action, struct sigaction *old_action);
256 int _kern_send_signal(thread_id tid, uint signal);
257 int _kern_send_proc_signal(proc_id pid, uint signal);
258 bigtime_t _kern_set_alarm(bigtime_t time, timer_mode mode);
260 #ifdef __cplusplus
262 #endif
264 #endif