1 /* 2 * Copyright 2004-2005, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _KERNEL_SYSCALLS_H 6 #define _KERNEL_SYSCALLS_H 7 8 9 #include <OS.h> 10 #include <image.h> 11 //#include <disk_device_manager/ddm_userland_interface.h> 12 13 //#include <sys/select.h> 14 #include <sys/uio.h> 15 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 struct sigaction; 22 struct rlimit; 23 struct stat; 24 struct pollfd; 25 struct fs_info; 26 struct dirent; 27 28 // This marks the beginning of the syscalls prototypes for gensyscallinfos. 29 // NOTE: 30 // * Nothing but those prototypes may live here. 31 // * The arguments of the functions must be named to be processed properly. 32 33 #ifdef GEN_SYSCALL_INFOS_PROCESSING 34 #pragma syscalls begin 35 #endif 36 37 extern int _kern_null(); 38 extern status_t _kern_generic_syscall(const char *subsystem, uint32 function, 39 void *buffer, size_t bufferSize); 40 41 extern int _kern_getrlimit(int resource, struct rlimit * rlp); 42 extern int _kern_setrlimit(int resource, const struct rlimit * rlp); 43 44 extern status_t _kern_shutdown(bool reboot); 45 extern status_t _kern_get_safemode_option(const char *parameter, char *buffer, size_t *_bufferSize); 46 47 /* sem functions */ 48 extern sem_id _kern_create_sem(int count, const char *name); 49 extern status_t _kern_delete_sem(sem_id id); 50 extern status_t _kern_switch_sem(sem_id releaseSem, sem_id id); 51 extern status_t _kern_switch_sem_etc(sem_id releaseSem, sem_id id, uint32 count, 52 uint32 flags, bigtime_t timeout); 53 extern status_t _kern_acquire_sem(sem_id id); 54 extern status_t _kern_acquire_sem_etc(sem_id id, uint32 count, uint32 flags, bigtime_t timeout); 55 extern status_t _kern_release_sem(sem_id id); 56 extern status_t _kern_release_sem_etc(sem_id id, uint32 count, uint32 flags); 57 extern status_t _kern_get_sem_count(sem_id id, int32* thread_count); 58 extern status_t _kern_get_sem_info(sem_id semaphore, struct sem_info *info, size_t size); 59 extern status_t _kern_get_next_sem_info(team_id team, uint32 *cookie, 60 struct sem_info *info, size_t size); 61 extern status_t _kern_set_sem_owner(sem_id id, team_id proc); 62 63 /* team & thread syscalls */ 64 65 // extern thread_id _kern_load_image(int32 argCount, const char **args, 66 // int32 envCount, const char **envp, int32 priority, 67 // uint32 flags); 68 // extern void _kern_exit_team(status_t returnValue); 69 // extern status_t _kern_kill_team(team_id team); 70 // extern team_id _kern_get_current_team(); 71 // extern status_t _kern_wait_for_team(team_id team, status_t *_returnCode); 72 // extern thread_id _kern_wait_for_child(thread_id child, uint32 flags, 73 // int32 *_reason, status_t *_returnCode); 74 // extern status_t _kern_exec(const char *path, int32 argc, char * const *argv, int32 envCount, 75 // char * const *environment); 76 // extern thread_id _kern_fork(void); 77 // extern pid_t _kern_process_info(pid_t process, int32 which); 78 // extern pid_t _kern_setpgid(pid_t process, pid_t group); 79 // extern pid_t _kern_setsid(void); 80 81 // extern thread_id _kern_spawn_thread(int32 (*func)(thread_func, void *), 82 // const char *name, int32 priority, void *data1, void *data2); 83 // extern thread_id _kern_find_thread(const char *name); 84 // extern status_t _kern_suspend_thread(thread_id thread); 85 // extern status_t _kern_resume_thread(thread_id thread); 86 // extern status_t _kern_rename_thread(thread_id thread, const char *newName); 87 // extern status_t _kern_set_thread_priority(thread_id thread, int32 newPriority); 88 // extern status_t _kern_kill_thread(thread_id thread); 89 // extern void _kern_exit_thread(status_t returnValue); 90 // extern status_t _kern_wait_for_thread(thread_id thread, status_t *_returnCode); 91 // extern bool _kern_has_data(thread_id thread); 92 // extern status_t _kern_send_data(thread_id thread, int32 code, const void *buffer, size_t bufferSize); 93 // extern int32 _kern_receive_data(thread_id *_sender, void *buffer, size_t bufferSize); 94 // extern int64 _kern_restore_signal_frame(); 95 96 // extern status_t _kern_get_thread_info(thread_id id, thread_info *info); 97 // extern status_t _kern_get_next_thread_info(team_id team, int32 *cookie, thread_info *info); 98 // extern status_t _kern_get_team_info(team_id id, team_info *info); 99 // extern status_t _kern_get_next_team_info(int32 *cookie, team_info *info); 100 // extern status_t _kern_get_team_usage_info(team_id team, int32 who, team_usage_info *info, size_t size); 101 102 // signal functions 103 // extern int _kern_send_signal(pid_t tid, uint sig); 104 // extern int _kern_sigprocmask(int how, const sigset_t *set, sigset_t *oldSet); 105 // extern int _kern_sigaction(int sig, const struct sigaction *action, struct sigaction *oldAction); 106 // extern bigtime_t _kern_set_alarm(bigtime_t time, uint32 mode); 107 108 // image functions 109 // extern image_id _kern_register_image(image_info *info, size_t size); 110 // extern status_t _kern_unregister_image(image_id id); 111 // extern void _kern_image_relocated(image_id id); 112 // extern void _kern_loading_app_failed(status_t error); 113 // extern status_t _kern_get_image_info(image_id id, image_info *info, size_t size); 114 // extern status_t _kern_get_next_image_info(team_id team, int32 *cookie, image_info *info, size_t size); 115 116 // VFS functions 117 // extern status_t _kern_mount(const char *path, const char *device, 118 // const char *fs_name, uint32 flags, const char *args); 119 // extern status_t _kern_unmount(const char *path, uint32 flags); 120 // extern status_t _kern_read_fs_info(dev_t device, struct fs_info *info); 121 // extern status_t _kern_write_fs_info(dev_t device, const struct fs_info *info, int mask); 122 // extern dev_t _kern_next_device(int32 *_cookie); 123 // extern status_t _kern_sync(void); 124 extern status_t _kern_entry_ref_to_path(dev_t device, ino_t inode, 125 const char *leaf, char *userPath, size_t pathLength); 126 extern int _kern_open_entry_ref(dev_t device, ino_t inode, const char *name, int openMode, int perms); 127 extern int _kern_open(int fd, const char *path, int openMode, int perms); 128 extern int _kern_open_dir_entry_ref(dev_t device, ino_t inode, const char *name); 129 extern int _kern_open_dir(int fd, const char *path); 130 extern int _kern_open_parent_dir(int fd, char *name, 131 size_t nameLength); 132 // extern status_t _kern_fcntl(int fd, int op, uint32 argument); 133 extern status_t _kern_fsync(int fd); 134 extern off_t _kern_seek(int fd, off_t pos, int seekType); 135 extern status_t _kern_create_dir_entry_ref(dev_t device, ino_t inode, const char *name, int perms); 136 extern status_t _kern_create_dir(int fd, const char *path, int perms); 137 // extern status_t _kern_remove_dir(const char *path); 138 extern status_t _kern_read_link(int fd, const char *path, char *buffer, 139 size_t *_bufferSize); 140 // extern status_t _kern_write_link(const char *path, const char *toPath); 141 extern status_t _kern_create_symlink(int fd, const char *path, 142 const char *toPath, int mode); 143 // extern status_t _kern_create_link(const char *path, const char *toPath); 144 extern status_t _kern_unlink(int fd, const char *path); 145 extern status_t _kern_rename(int oldDir, const char *oldpath, int newDir, 146 const char *newpath); 147 // extern status_t _kern_access(const char *path, int mode); 148 // extern ssize_t _kern_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet, 149 // bigtime_t timeout, const sigset_t *sigMask); 150 // extern ssize_t _kern_poll(struct pollfd *fds, int numfds, bigtime_t timeout); 151 extern int _kern_open_attr_dir(int fd, const char *path); 152 // extern int _kern_create_attr(int fd, const char *name, uint32 type, int openMode); 153 // extern int _kern_open_attr(int fd, const char *name, int openMode); 154 extern status_t _kern_remove_attr(int fd, const char *name); 155 extern status_t _kern_rename_attr(int fromFile, const char *fromName, int toFile, const char *toName); 156 // extern int _kern_open_index_dir(dev_t device); 157 // extern status_t _kern_create_index(dev_t device, const char *name, uint32 type, uint32 flags); 158 // extern status_t _kern_read_index_stat(dev_t device, const char *name, struct stat *stat); 159 // extern status_t _kern_remove_index(dev_t device, const char *name); 160 // extern status_t _kern_getcwd(char *buffer, size_t size); 161 // extern status_t _kern_setcwd(int fd, const char *path); 162 // extern int _kern_open_query(dev_t device, const char *query, size_t queryLength, 163 // uint32 flags, port_id port, int32 token); 164 165 // file descriptor functions 166 extern ssize_t _kern_read(int fd, off_t pos, void *buffer, size_t bufferSize); 167 //extern ssize_t _kern_readv(int fd, off_t pos, const iovec *vecs, size_t count); 168 extern ssize_t _kern_write(int fd, off_t pos, const void *buffer, size_t bufferSize); 169 //extern ssize_t _kern_writev(int fd, off_t pos, const iovec *vecs, size_t count); 170 // extern status_t _kern_ioctl(int fd, ulong cmd, void *data, size_t length); 171 extern ssize_t _kern_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount); 172 extern status_t _kern_rewind_dir(int fd); 173 extern status_t _kern_read_stat(int fd, const char *path, bool traverseLink, 174 struct stat *stat, size_t statSize); 175 extern status_t _kern_write_stat(int fd, const char *path, 176 bool traverseLink, const struct stat *stat, 177 size_t statSize, int statMask); 178 extern status_t _kern_close(int fd); 179 extern int _kern_dup(int fd); 180 // extern int _kern_dup2(int ofd, int nfd); 181 extern status_t _kern_lock_node(int fd); 182 extern status_t _kern_unlock_node(int fd); 183 184 // node monitor functions 185 // extern status_t _kern_stop_notifying(port_id port, uint32 token); 186 // extern status_t _kern_start_watching(dev_t device, ino_t node, uint32 flags, 187 // port_id port, uint32 token); 188 // extern status_t _kern_stop_watching(dev_t device, ino_t node, uint32 flags, 189 // port_id port, uint32 token); 190 191 // time functions 192 // extern status_t _kern_set_real_time_clock(uint32 time); 193 // extern status_t _kern_set_timezone(int32 timezoneOffset, bool daylightSavingTime); 194 // extern status_t _kern_set_tzfilename(const char *filename, size_t length, bool isGMT); 195 // extern status_t _kern_get_tzfilename(char *filename, size_t length, bool *_isGMT); 196 // 197 // extern bigtime_t _kern_system_time(); 198 // extern status_t _kern_snooze_etc(bigtime_t time, int timebase, int32 flags); 199 200 // area functions 201 // extern area_id _kern_create_area(const char *name, void **address, uint32 addressSpec, 202 // size_t size, uint32 lock, uint32 protection); 203 // extern status_t _kern_delete_area(area_id area); 204 // extern area_id _kern_area_for(void *address); 205 // extern area_id _kern_find_area(const char *name); 206 // extern status_t _kern_get_area_info(area_id area, area_info *info); 207 // extern status_t _kern_get_next_area_info(team_id team, int32 *cookie, area_info *info); 208 // extern status_t _kern_resize_area(area_id area, size_t newSize); 209 // extern status_t _kern_transfer_area(area_id area, void **_address, uint32 addressSpec, 210 // team_id target); 211 // extern status_t _kern_set_area_protection(area_id area, uint32 newProtection); 212 // extern area_id _kern_clone_area(const char *name, void **_address, uint32 addressSpec, 213 // uint32 protection, area_id sourceArea); 214 // extern status_t _kern_init_heap_address_range(addr_t base, addr_t size); 215 // 216 // area_id sys_vm_map_file(const char *name, void **address, int addr_type, 217 // addr_t size, int lock, int mapping, const char *path, off_t offset); 218 219 /* kernel port functions */ 220 // extern port_id _kern_create_port(int32 queue_length, const char *name); 221 // extern status_t _kern_close_port(port_id id); 222 // extern status_t _kern_delete_port(port_id id); 223 // extern port_id _kern_find_port(const char *port_name); 224 // extern status_t _kern_get_port_info(port_id id, struct port_info *info); 225 // extern status_t _kern_get_next_port_info(team_id team, uint32 *cookie, struct port_info *info); 226 // extern ssize_t _kern_port_buffer_size_etc(port_id port, uint32 flags, bigtime_t timeout); 227 // extern int32 _kern_port_count(port_id port); 228 // extern ssize_t _kern_read_port_etc(port_id port, int32 *msgCode, void *msgBuffer, 229 // size_t bufferSize, uint32 flags, bigtime_t timeout); 230 // extern status_t _kern_set_port_owner(port_id port, team_id team); 231 // extern status_t _kern_write_port_etc(port_id port, int32 msgCode, const void *msgBuffer, 232 // size_t bufferSize, uint32 flags, bigtime_t timeout); 233 // extern status_t _kern_writev_port_etc(port_id id, int32 msgCode, const iovec *msgVecs, 234 // size_t vecCount, size_t bufferSize, uint32 flags, bigtime_t timeout); 235 236 // debug support functions 237 // extern void _kern_debugger(const char *message); 238 // extern int _kern_disable_debugger(int state); 239 // 240 // extern status_t _kern_install_default_debugger(port_id debuggerPort); 241 // extern port_id _kern_install_team_debugger(team_id team, 242 // port_id debuggerPort); 243 // extern status_t _kern_remove_team_debugger(team_id team); 244 // extern status_t _kern_debug_thread(thread_id thread); 245 // extern void _kern_wait_for_debugger(void); 246 247 248 /* atomic_* ops (needed for CPUs that don't support them directly) */ 249 // #ifdef ATOMIC_FUNCS_ARE_SYSCALLS 250 // extern int32 _kern_atomic_set(vint32 *value, int32 newValue); 251 // extern int32 _kern_atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst); 252 // extern int32 _kern_atomic_add(vint32 *value, int32 addValue); 253 // extern int32 _kern_atomic_and(vint32 *value, int32 andValue); 254 // extern int32 _kern_atomic_or(vint32 *value, int32 orValue); 255 // extern int32 _kern_atomic_get(vint32 *value); 256 // #endif // ATOMIC_FUNCS_ARE_SYSCALLS 257 258 // #ifdef ATOMIC64_FUNCS_ARE_SYSCALLS 259 // extern int64 _kern_atomic_set64(vint64 *value, int64 newValue); 260 // extern int64 _kern_atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst); 261 // extern int64 _kern_atomic_add64(vint64 *value, int64 addValue); 262 // extern int64 _kern_atomic_and64(vint64 *value, int64 andValue); 263 // extern int64 _kern_atomic_or64(vint64 *value, int64 orValue); 264 // extern int64 _kern_atomic_get64(vint64 *value); 265 // #endif // ATOMIC64_FUNCS_ARE_SYSCALLS 266 267 // int sys_sysctl(int *name, uint namlen, void *oldp, size_t *oldlen, 268 // void *newp, size_t newlen); 269 // int sys_socket(int family, int type, int proto); 270 271 /* System informations */ 272 // extern status_t _kern_get_system_info(system_info *info, size_t size); 273 274 /* Debug output */ 275 // extern void _kern_debug_output(const char *message); 276 // extern status_t _kern_frame_buffer_update(addr_t baseAddress, int32 width, 277 // int32 height, int32 depth, int32 bytesPerRow); 278 279 /* messaging service */ 280 // extern area_id _kern_register_messaging_service(sem_id lockingSem, 281 // sem_id counterSem); 282 // extern status_t _kern_unregister_messaging_service(); 283 // 284 // extern void _kern_clear_caches(void *address, size_t length, uint32 flags); 285 286 // #ifdef __INTEL__ 287 // // our only x86 only syscall 288 // extern status_t _kern_get_cpuid(cpuid_info *info, uint32 eax, uint32 cpu); 289 // #endif 290 291 292 /* Disk Device Manager syscalls */ 293 /* 294 // iterating, retrieving device/partition data 295 extern partition_id _kern_get_next_disk_device_id(int32 *cookie, size_t *neededSize); 296 extern partition_id _kern_find_disk_device(const char *filename, size_t *neededSize); 297 extern partition_id _kern_find_partition(const char *filename, size_t *neededSize); 298 extern status_t _kern_get_disk_device_data(partition_id deviceID, bool deviceOnly, 299 bool shadow, user_disk_device_data *buffer, 300 size_t bufferSize, size_t *neededSize); 301 extern partition_id _kern_register_file_device(const char *filename); 302 extern status_t _kern_unregister_file_device(partition_id deviceID, 303 const char *filename); 304 // Only a valid deviceID or filename need to be passed. The other one 305 // is -1/NULL. If both is given only filename is ignored. 306 307 // disk systems 308 extern status_t _kern_get_disk_system_info(disk_system_id id, 309 user_disk_system_info *info); 310 extern status_t _kern_get_next_disk_system_info(int32 *cookie, 311 user_disk_system_info *info); 312 extern status_t _kern_find_disk_system(const char *name, user_disk_system_info *info); 313 extern bool _kern_supports_defragmenting_partition(partition_id partitionID, 314 int32 changeCounter, bool *whileMounted); 315 extern bool _kern_supports_repairing_partition(partition_id partitionID, 316 int32 changeCounter, bool checkOnly, bool *whileMounted); 317 extern bool _kern_supports_resizing_partition(partition_id partitionID, 318 int32 changeCounter, bool *canResizeContents, bool *whileMounted); 319 extern bool _kern_supports_moving_partition(partition_id partitionID, 320 int32 changeCounter, partition_id *unmovable, 321 partition_id *needUnmounting, size_t bufferSize); 322 extern bool _kern_supports_setting_partition_name(partition_id partitionID, 323 int32 changeCounter); 324 extern bool _kern_supports_setting_partition_content_name(partition_id partitionID, 325 int32 changeCounter, bool *whileMounted); 326 extern bool _kern_supports_setting_partition_type(partition_id partitionID, 327 int32 changeCounter); 328 extern bool _kern_supports_setting_partition_parameters(partition_id partitionID, 329 int32 changeCounter); 330 extern bool _kern_supports_setting_partition_content_parameters( 331 partition_id partitionID, int32 changeCounter, bool *whileMounted); 332 extern bool _kern_supports_initializing_partition(partition_id partitionID, 333 int32 changeCounter, const char *diskSystemName); 334 extern bool _kern_supports_creating_child_partition(partition_id partitionID, 335 int32 changeCounter); 336 extern bool _kern_supports_deleting_child_partition(partition_id partitionID, 337 int32 changeCounter); 338 extern bool _kern_is_sub_disk_system_for(disk_system_id diskSystemID, 339 partition_id partitionID, int32 changeCounter); 340 341 extern status_t _kern_validate_resize_partition(partition_id partitionID, 342 int32 changeCounter, off_t *size); 343 extern status_t _kern_validate_move_partition(partition_id partitionID, 344 int32 changeCounter, off_t *newOffset); 345 extern status_t _kern_validate_set_partition_name(partition_id partitionID, 346 int32 changeCounter, char *name); 347 extern status_t _kern_validate_set_partition_content_name(partition_id partitionID, 348 int32 changeCounter, char *name); 349 extern status_t _kern_validate_set_partition_type(partition_id partitionID, 350 int32 changeCounter, const char *type); 351 extern status_t _kern_validate_initialize_partition(partition_id partitionID, 352 int32 changeCounter, const char *diskSystemName, 353 char *name, const char *parameters, size_t parametersSize); 354 extern status_t _kern_validate_create_child_partition(partition_id partitionID, 355 int32 changeCounter, off_t *offset, off_t *size, 356 const char *type, const char *parameters, 357 size_t parametersSize); 358 extern status_t _kern_get_partitionable_spaces(partition_id partitionID, 359 int32 changeCounter, partitionable_space_data *buffer, 360 int32 count, int32 *actualCount); 361 extern status_t _kern_get_next_supported_partition_type(partition_id partitionID, 362 int32 changeCounter, int32 *cookie, char *type); 363 extern status_t _kern_get_partition_type_for_content_type(disk_system_id diskSystemID, 364 const char *contentType, char *type); 365 366 // disk device modification 367 extern status_t _kern_prepare_disk_device_modifications(partition_id deviceID); 368 extern status_t _kern_commit_disk_device_modifications(partition_id deviceID, 369 port_id port, int32 token, bool completeProgress); 370 extern status_t _kern_cancel_disk_device_modifications(partition_id deviceID); 371 extern bool _kern_is_disk_device_modified(partition_id deviceID); 372 extern status_t _kern_defragment_partition(partition_id partitionID, 373 int32 changeCounter); 374 extern status_t _kern_repair_partition(partition_id partitionID, int32 changeCounter, 375 bool checkOnly); 376 extern status_t _kern_resize_partition(partition_id partitionID, int32 changeCounter, 377 off_t size); 378 extern status_t _kern_move_partition(partition_id partitionID, int32 changeCounter, 379 off_t newOffset); 380 extern status_t _kern_set_partition_name(partition_id partitionID, 381 int32 changeCounter, const char *name); 382 extern status_t _kern_set_partition_content_name(partition_id partitionID, 383 int32 changeCounter, const char *name); 384 extern status_t _kern_set_partition_type(partition_id partitionID, 385 int32 changeCounter, const char *type); 386 extern status_t _kern_set_partition_parameters(partition_id partitionID, 387 int32 changeCounter, const char *parameters, 388 size_t parametersSize); 389 extern status_t _kern_set_partition_content_parameters(partition_id partitionID, 390 int32 changeCounter, const char *parameters, 391 size_t parametersSize); 392 extern status_t _kern_initialize_partition(partition_id partitionID, 393 int32 changeCounter, const char *diskSystemName, 394 const char *name, const char *parameters, 395 size_t parametersSize); 396 extern status_t _kern_uninitialize_partition(partition_id partitionID, 397 int32 changeCounter); 398 extern status_t _kern_create_child_partition(partition_id partitionID, 399 int32 changeCounter, off_t offset, off_t size, const char *type, 400 const char *parameters, size_t parametersSize, 401 partition_id *childID); 402 extern status_t _kern_delete_partition(partition_id partitionID, int32 changeCounter); 403 404 // jobs 405 extern status_t _kern_get_next_disk_device_job_info(int32 *cookie, 406 user_disk_device_job_info *info); 407 extern status_t _kern_get_disk_device_job_info(disk_job_id id, 408 user_disk_device_job_info *info); 409 extern status_t _kern_get_disk_device_job_progress_info(disk_job_id id, 410 disk_device_job_progress_info *info); 411 extern status_t _kern_pause_disk_device_job(disk_job_id id); 412 extern status_t _kern_cancel_disk_device_job(disk_job_id id, bool reverse);*/ 413 414 #if 0 415 416 // watching 417 status_t start_disk_device_watching(port_id, int32 token, uint32 flags); 418 status_t start_disk_device_job_watching(disk_job_id job, port_id, int32 token, 419 uint32 flags); 420 status_t stop_disk_device_watching(port_id, int32 token); 421 422 #endif // 0 423 424 425 // The end mark for gensyscallinfos. 426 #ifdef GEN_SYSCALL_INFOS_PROCESSING 427 #pragma syscalls end 428 #endif 429 430 #ifdef __cplusplus 431 } 432 #endif 433 434 #endif /* _KERNEL_SYSCALLS_H */ 435