2 ** Copyright 2001-2004, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
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>
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
{
47 char name
[SYS_MAX_OS_NAME_LEN
];
50 typedef struct sem_info
{
53 char name
[SYS_MAX_OS_NAME_LEN
];
55 thread_id latest_holder
;
58 typedef struct port_info
{
61 char name
[SYS_MAX_OS_NAME_LEN
];
74 char name
[SYS_MAX_OS_NAME_LEN
];
79 proc_id owner_proc_id
;
81 char name
[SYS_MAX_OS_NAME_LEN
];
85 addr_t user_stack_base
;
88 bigtime_t kernel_time
;
91 // args to proc_create_proc()
93 PROC_FLAG_SUSPENDED
= 1,
94 PROC_FLAG_NEW_PGROUP
= 2,
95 PROC_FLAG_NEW_SESSION
= 4
98 // args for the create_area funcs
100 REGION_ADDR_ANY_ADDRESS
= 0,
101 REGION_ADDR_EXACT_ADDRESS
105 REGION_WIRING_LAZY
= 0,
107 REGION_WIRING_WIRED_ALREADY
,
108 REGION_WIRING_WIRED_CONTIG
112 REGION_NO_PRIVATE_MAP
= 0,
118 #define LOCK_KERNEL 0x2
119 #define LOCK_MASK 0x3
123 // info about the size of memory in the system
124 int physical_page_size
;
127 // amount of virtual memory left to commit
130 // info about the page queues
136 int modified_temporary_pages
;
141 // info about vm activity
146 TIMER_MODE_ONESHOT
= 0,
154 int _kern_null(void);
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
);
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
);
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
);