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