[1] | 1 | /* |
---|
[16] | 2 | * syscalls.h - kernel services definition |
---|
[1] | 3 | * |
---|
[23] | 4 | * Author Alain Greiner (2016,2017) |
---|
[1] | 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
[16] | 24 | #ifndef _SYSCALLS_H_ |
---|
| 25 | #define _SYSCALLS_H_ |
---|
[1] | 26 | |
---|
[23] | 27 | #include <hal_types.h> |
---|
| 28 | #include <time.h> |
---|
| 29 | |
---|
| 30 | /***** Forward declarations *****/ |
---|
| 31 | |
---|
| 32 | struct thread_s; // defined in thread.h |
---|
| 33 | struct pthread_attr_s; // defined in thread.h |
---|
| 34 | struct vfs_stat_s; // defined in vfs.h |
---|
| 35 | struct vfs_dirent_s; // defined in vfs.h |
---|
| 36 | struct mmap_attr_s; // defined in vmm.h |
---|
| 37 | |
---|
[1] | 38 | /****************************************************************************************** |
---|
[16] | 39 | * This enum defines the mnemonics for the syscall indexes. |
---|
| 40 | * It must be kept consistent with the array defined in do_syscalls.c |
---|
[1] | 41 | *****************************************************************************************/ |
---|
| 42 | enum |
---|
| 43 | { |
---|
[23] | 44 | SYS_THREAD_EXIT = 0, |
---|
| 45 | SYS_MMAP = 1, |
---|
| 46 | SYS_THREAD_CREATE = 2, |
---|
| 47 | SYS_THREAD_JOIN = 3, |
---|
| 48 | SYS_THREAD_DETACH = 4, |
---|
| 49 | SYS_THREAD_YIELD = 5, |
---|
| 50 | SYS_SEM = 6, |
---|
| 51 | SYS_CONDVAR = 7, |
---|
| 52 | SYS_BARRIER = 8, |
---|
| 53 | SYS_MUTEX = 9, |
---|
| 54 | |
---|
| 55 | SYS_SLEEP = 10, |
---|
| 56 | SYS_WAKEUP = 11, |
---|
| 57 | SYS_OPEN = 12, |
---|
| 58 | SYS_CREAT = 13, |
---|
| 59 | SYS_READ = 14, |
---|
| 60 | SYS_WRITE = 15, |
---|
| 61 | SYS_LSEEK = 16, |
---|
| 62 | SYS_CLOSE = 17, |
---|
| 63 | SYS_UNLINK = 18, |
---|
| 64 | SYS_PIPE = 19, |
---|
| 65 | |
---|
| 66 | SYS_CHDIR = 20, |
---|
| 67 | SYS_MKDIR = 21, |
---|
| 68 | SYS_MKFIFO = 22, |
---|
| 69 | SYS_OPENDIR = 23, |
---|
| 70 | SYS_READDIR = 24, |
---|
| 71 | SYS_CLOSEDIR = 25, |
---|
| 72 | SYS_GETCWD = 26, |
---|
| 73 | SYS_CLOCK = 27, |
---|
| 74 | SYS_ALARM = 28, |
---|
| 75 | SYS_RMDIR = 29, |
---|
| 76 | |
---|
| 77 | SYS_UTLS = 30, |
---|
| 78 | SYS_CHMOD = 31, |
---|
| 79 | SYS_SIGNAL = 32, |
---|
| 80 | SYS_TIMEOFDAY = 33, |
---|
| 81 | SYS_KILL = 34, |
---|
| 82 | SYS_GETPID = 35, |
---|
| 83 | SYS_FORK = 36, |
---|
| 84 | SYS_EXEC = 37, |
---|
| 85 | SYS_STAT = 38, |
---|
| 86 | SYS_TRACE = 39, |
---|
| 87 | |
---|
| 88 | SYSCALLS_NR = 40, |
---|
[1] | 89 | }; |
---|
| 90 | |
---|
[23] | 91 | |
---|
[1] | 92 | /********************************************************************************************/ |
---|
[23] | 93 | /******************** system calls ****************************************************/ |
---|
[1] | 94 | /********************************************************************************************/ |
---|
| 95 | |
---|
| 96 | /********************************************************************************************* |
---|
[23] | 97 | * [0] This function terminates the execution of the calling user thread value, |
---|
| 98 | * and makes the exit_value pointer available to any successful pthread_join() with the |
---|
| 99 | * terminating thread. |
---|
| 100 | ********************************************************************************************* |
---|
| 101 | * @ exit_vallue : [out] pointer to to the parrent thread if attached. |
---|
| 102 | * @ return 0 if success / return -1 if failure. |
---|
[1] | 103 | ********************************************************************************************/ |
---|
[23] | 104 | int sys_thread_exit( void * exit_value ); |
---|
[16] | 105 | |
---|
| 106 | /********************************************************************************************* |
---|
[23] | 107 | * [1] This function map physical memory (or a file) in the calling thread virtual space. |
---|
| 108 | * The <attr> argument is a pointer on a structure containing arguments, defined in vmm.h. |
---|
| 109 | * TODO not implemented yet... |
---|
| 110 | ********************************************************************************************* |
---|
| 111 | * @ attr : pointer on attributes structure. |
---|
| 112 | * @ return 0 if success / return -1 if failure. |
---|
[16] | 113 | ********************************************************************************************/ |
---|
[23] | 114 | int sys_mmap( struct mmap_attr_s * attr ); |
---|
[16] | 115 | |
---|
| 116 | /********************************************************************************************* |
---|
[23] | 117 | * [2] This function creates a new user thread. The <user_attr> argument is a pointer |
---|
| 118 | * on astructure containing the thread attributes, defined in thread.h file. |
---|
| 119 | ********************************************************************************************* |
---|
| 120 | * @ new_thread : [out] local pointer on created thread descriptor. |
---|
| 121 | * @ user_attr : [in] pointer on thread attributes structure. |
---|
| 122 | * @ start_func : [in] pointer on start function. |
---|
| 123 | * @ start_args : [in] pointer on start function arguments. |
---|
| 124 | * @ return 0 if success / return -1 if failure. |
---|
[16] | 125 | ********************************************************************************************/ |
---|
[23] | 126 | int sys_thread_create( struct thread_s * new_thread, |
---|
| 127 | struct pthread_attr_s * user_attr, |
---|
| 128 | void * start_func, |
---|
| 129 | void * start_args ); |
---|
[16] | 130 | |
---|
| 131 | /********************************************************************************************* |
---|
[23] | 132 | * [3] This blocking function suspend execution of the calling thread until completion |
---|
| 133 | * of another target thread identified by the <trdid> argument. |
---|
| 134 | * If the <exit_value> argument is not NULL, the value passed to pthread_exit() by the |
---|
| 135 | * target thread is stored in the location referenced by exit_value. |
---|
| 136 | ********************************************************************************************* |
---|
| 137 | * @ trdid : [in] target thread identifier. |
---|
| 138 | * @ thread : [out] buffer for exit_value returned by target thread. |
---|
| 139 | * @ return 0 if success / return -1 if failure. |
---|
[16] | 140 | ********************************************************************************************/ |
---|
[23] | 141 | int sys_thread_join( trdid_t trdid, |
---|
| 142 | void ** exit_value ); |
---|
[16] | 143 | |
---|
| 144 | /********************************************************************************************* |
---|
[23] | 145 | * [4] This function detach a joinable thread. |
---|
| 146 | ********************************************************************************************* |
---|
| 147 | * @ trdid : thread identifier. |
---|
| 148 | * @ return 0 if success / return -1 if failure. |
---|
[16] | 149 | ********************************************************************************************/ |
---|
[23] | 150 | int sys_thread_detach( trdid_t trdid ); |
---|
[16] | 151 | |
---|
| 152 | /********************************************************************************************* |
---|
[23] | 153 | * [5] This function calls the scheduler for the core running the calling thread. |
---|
| 154 | ********************************************************************************************* |
---|
| 155 | * @ return always 0. |
---|
[16] | 156 | ********************************************************************************************/ |
---|
| 157 | int sys_thread_yield(); |
---|
| 158 | |
---|
| 159 | /********************************************************************************************* |
---|
[23] | 160 | * [6] This function implement all operations on a POSIX unnamed semaphore, |
---|
| 161 | * that can be shared by threads running in different clusters. |
---|
| 162 | * The kernel structure representing a remote semaphore is in the remote_sem.h file, |
---|
| 163 | * and the code implementing the operations is in the remore_sem.c file. |
---|
| 164 | ********************************************************************************************* |
---|
| 165 | * @ vaddr : semaphore virtual address in user space == identifier. |
---|
| 166 | * @ operation : SEM_INIT / SEM_DESTROY / SEM_GETVALUE / SEM_POST / SEM_WAIT. |
---|
| 167 | * @ value : pointer on in/out argument in user space. |
---|
| 168 | * @ return 0 if success / return -1 if failure. |
---|
[16] | 169 | ********************************************************************************************/ |
---|
[23] | 170 | int sys_sem( void * vaddr, |
---|
| 171 | uint32_t operation, |
---|
| 172 | uint32_t * value ); |
---|
[16] | 173 | |
---|
[23] | 174 | typedef enum |
---|
| 175 | { |
---|
| 176 | SEM_INIT, |
---|
| 177 | SEM_DESTROY, |
---|
| 178 | SEM_GETVALUE, |
---|
| 179 | SEM_WAIT, |
---|
| 180 | SEM_POST, |
---|
| 181 | } |
---|
| 182 | sem_operation_t; |
---|
| 183 | |
---|
[16] | 184 | /********************************************************************************************* |
---|
[23] | 185 | * [7] This function implement all operations on a POSIX condition variable. |
---|
| 186 | * The kernel structure representing a cond_var is defined in the remote_cv.h file, |
---|
| 187 | * The code implementing the operations is defined in the remote_cv.c file. |
---|
| 188 | ********************************************************************************************* |
---|
| 189 | * @ vaddr : condvar virtual address in user space == identifier. |
---|
| 190 | * @ operation : operation type (see below). |
---|
| 191 | * @ attr : mutex virtual address in user space == identifier. |
---|
| 192 | * @ return 0 if success / return -1 if failure. |
---|
[16] | 193 | ********************************************************************************************/ |
---|
[23] | 194 | int sys_condvar( void * condvar, |
---|
| 195 | uint32_t operation, |
---|
| 196 | void * mutex ); |
---|
[16] | 197 | |
---|
[23] | 198 | typedef enum |
---|
| 199 | { |
---|
| 200 | CONDVAR_INIT, |
---|
| 201 | CONDVAR_DESTROY, |
---|
| 202 | CONDVAR_WAIT, |
---|
| 203 | CONDVAR_SIGNAL, |
---|
| 204 | CONDVAR_BROADCAST, |
---|
| 205 | } |
---|
| 206 | condvar_operation_t; |
---|
| 207 | |
---|
[16] | 208 | /********************************************************************************************* |
---|
[23] | 209 | * [8] This function implement all operations on a POSIX barrier. |
---|
| 210 | * The kernel structure representing a barrier is defined in the remote_barrier.h file. |
---|
| 211 | * The code implementting the operations is defined in the remote_barrier.c file. |
---|
| 212 | ********************************************************************************************* |
---|
| 213 | * @ vaddr : barrier virtual address in user space == identifier. |
---|
| 214 | * @ operation : BARRIER_INIT / BARRIER_DESTROY / BARRIER_WAIT. |
---|
| 215 | * @ count : number of expected threads (only used by BARRIER_INIT operation). |
---|
| 216 | * @ return 0 if success / return -1 if failure. |
---|
[16] | 217 | ********************************************************************************************/ |
---|
[23] | 218 | int sys_barrier( void * vaddr, |
---|
| 219 | uint32_t operation, |
---|
| 220 | uint32_t count ); |
---|
[16] | 221 | |
---|
[23] | 222 | typedef enum |
---|
| 223 | { |
---|
| 224 | BARRIER_INIT, |
---|
| 225 | BARRIER_DESTROY, |
---|
| 226 | BARRIER_WAIT, |
---|
| 227 | } |
---|
| 228 | barrier_operation_t; |
---|
| 229 | |
---|
[16] | 230 | /********************************************************************************************* |
---|
[23] | 231 | * [9] This function implement all operations on a POSIX mutex. |
---|
| 232 | * The kernel structure representing a barrier is defined in the remote_barrier.h file. |
---|
| 233 | * The code implementting the operations is defined in the remote_barrier.c file. |
---|
| 234 | ********************************************************************************************* |
---|
| 235 | * @ vaddr : mutex virtual address in user space == identifier. |
---|
| 236 | * @ operation : MUTEX_INIT / MUTEX_DESTROY / MUTEX_LOCK / MUTEX_UNLOCK |
---|
| 237 | * @ attr : mutex attributes (non supported yet => must be 0). |
---|
| 238 | * @ return 0 if success / return -1 if failure. |
---|
[16] | 239 | ********************************************************************************************/ |
---|
[23] | 240 | int sys_mutex( void * vaddr, |
---|
| 241 | uint32_t operation, |
---|
| 242 | uint32_t count ); |
---|
[16] | 243 | |
---|
[23] | 244 | typedef enum |
---|
| 245 | { |
---|
| 246 | MUTEX_INIT, |
---|
| 247 | MUTEX_DESTROY, |
---|
| 248 | MUTEX_LOCK, |
---|
| 249 | MUTEX_UNLOCK, |
---|
| 250 | } |
---|
| 251 | mutex_operation_t; |
---|
| 252 | |
---|
[16] | 253 | /********************************************************************************************* |
---|
[23] | 254 | * [10] This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition, |
---|
| 255 | * and deschedule. |
---|
| 256 | ********************************************************************************************* |
---|
| 257 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 258 | ********************************************************************************************/ |
---|
| 259 | int sys_thread_sleep(); |
---|
| 260 | |
---|
| 261 | /********************************************************************************************* |
---|
[23] | 262 | * [11] This function unblock the thread identified by its <trdid> from the |
---|
| 263 | * THREAD_BLOCKED_GLOBAL condition. |
---|
| 264 | ********************************************************************************************* |
---|
| 265 | * @ trdid : target thread identifier. |
---|
| 266 | * @ return 0 if success / return -1 if failure. |
---|
[16] | 267 | ********************************************************************************************/ |
---|
| 268 | int sys_thread_wakeup(); |
---|
| 269 | |
---|
| 270 | /********************************************************************************************* |
---|
[23] | 271 | * [12] This function open or create a file. |
---|
| 272 | ********************************************************************************************* |
---|
| 273 | * @ pathname : pathname (can be relative or absolute). |
---|
| 274 | * @ flags : bit vector attributes (see below). |
---|
| 275 | * @ mode : access rights. |
---|
| 276 | * @ return file descriptor index in fd_array if success / return -1 if failure. |
---|
[16] | 277 | ********************************************************************************************/ |
---|
[23] | 278 | int sys_open( char * pathname, |
---|
| 279 | uint32_t flags, |
---|
| 280 | uint32_t mode ); |
---|
[16] | 281 | |
---|
[23] | 282 | typedef enum |
---|
| 283 | { |
---|
| 284 | O_RDONLY = 0x0010000, /*! open file in read-only mode */ |
---|
| 285 | O_WRONLY = 0x0020000, /*! open file in write-only mode */ |
---|
| 286 | O_RDWR = 0x0030000, /*! open file in read/write mode */ |
---|
| 287 | O_NONBLOCK = 0x0040000, /*! do not block if data non available */ |
---|
| 288 | O_APPEND = 0x0080000, /*! append on each write */ |
---|
| 289 | O_CREAT = 0x0100000, /*! create file if it does not exist */ |
---|
| 290 | O_TRUNC = 0x0200000, /*! file length is forced to 0 */ |
---|
| 291 | O_EXCL = 0x0400000, /*! error if VFS_O_CREAT and file exist */ |
---|
| 292 | O_SYNC = 0x0800000, /*! synchronize File System on each write */ |
---|
| 293 | O_CLOEXEC = 0x1000000, /*! set the close-on-exec flag in file descriptor */ |
---|
| 294 | O_DIR = 0x2000000, /*! new file descriptor is for a directory */ |
---|
| 295 | } |
---|
| 296 | open_attributes_t; |
---|
| 297 | |
---|
[16] | 298 | /********************************************************************************************* |
---|
[23] | 299 | * [13] This function creates a new file as specified by the arguments. |
---|
| 300 | * This function is obsolete, you should use open() with 0_CREATE. |
---|
| 301 | ********************************************************************************************* |
---|
| 302 | * @ pathname : pathname (can be relative or absolute). |
---|
| 303 | * @ mode : access rights. |
---|
[16] | 304 | ********************************************************************************************/ |
---|
[23] | 305 | int sys_creat( char * pathname, |
---|
| 306 | uint32_t mode ); |
---|
[16] | 307 | |
---|
| 308 | /********************************************************************************************* |
---|
[23] | 309 | * [14] This function read bytes from an open file identified by its file descriptor. |
---|
| 310 | * This file can be a regular file or character oriented device. |
---|
| 311 | ********************************************************************************************* |
---|
| 312 | * @ file_id : open file index in fd_array. |
---|
| 313 | * @ buf : buffer virtual address in user space. |
---|
| 314 | * @ count : number of bytes. |
---|
| 315 | * @ return number of bytes actually read if success / returns -1 if failure. |
---|
[16] | 316 | ********************************************************************************************/ |
---|
[23] | 317 | int sys_read( uint32_t file_id, |
---|
| 318 | void * buf, |
---|
| 319 | uint32_t count ); |
---|
[16] | 320 | |
---|
| 321 | /********************************************************************************************* |
---|
[23] | 322 | * [15] This function writes bytes to an open file identified by its file descriptor. |
---|
| 323 | * This file can be a regular file or character oriented device. |
---|
| 324 | ********************************************************************************************* |
---|
| 325 | * @ file_id : open file index in fd_array. |
---|
| 326 | * @ buf : buffer virtual address in user space. |
---|
| 327 | * @ count : number of bytes. |
---|
| 328 | * @ return number of bytes actually written if success / returns -1 if failure. |
---|
[16] | 329 | ********************************************************************************************/ |
---|
[23] | 330 | int sys_write( uint32_t file_id, |
---|
| 331 | void * buf, |
---|
| 332 | uint32_t count ); |
---|
[16] | 333 | |
---|
| 334 | /********************************************************************************************* |
---|
[23] | 335 | * [16] This function epositions the offset of the file descriptor identified by <file_id>, |
---|
| 336 | * according to the operation type defined by the <whence> and <offset> arguments. |
---|
| 337 | ********************************************************************************************* |
---|
| 338 | * @ file_id : open file index in fd_array. |
---|
| 339 | * @ offset : buffer virtual address in user space. |
---|
| 340 | * @ whence : operation type (see below). |
---|
| 341 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 342 | ********************************************************************************************/ |
---|
[23] | 343 | int sys_lseek( xptr_t file_id, |
---|
| 344 | uint32_t offset, |
---|
| 345 | uint32_t whence ); |
---|
[16] | 346 | |
---|
[23] | 347 | typedef enum |
---|
| 348 | { |
---|
| 349 | SEEK_SET = 0, /*! new_offset <= offset */ |
---|
| 350 | SEEK_CUR = 1, /*! new_offset <= current_offset + offset */ |
---|
| 351 | SEEK_END = 2, /*! new_iffset <= current_size + offset */ |
---|
| 352 | } |
---|
| 353 | lseek_operation_t; |
---|
| 354 | |
---|
[16] | 355 | /********************************************************************************************* |
---|
[23] | 356 | * [17] This function release the memory allocated for the file descriptor identified by |
---|
| 357 | * the <file_id> argument, and remove the fd array_entry in all copies of the process |
---|
| 358 | * descriptor. |
---|
| 359 | ********************************************************************************************* |
---|
| 360 | file_id : file descriptor index in fd_array. |
---|
| 361 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 362 | ********************************************************************************************/ |
---|
[23] | 363 | int sys_close( uint32_t file_id ); |
---|
[16] | 364 | |
---|
| 365 | /********************************************************************************************* |
---|
[23] | 366 | * [18] This function removes a directory entry identified by the <pathname> from its |
---|
| 367 | * directory, and decrement the link count of the file referenced by the link. |
---|
| 368 | * If the link count reduces to zero, and no process has the file open, then all resources |
---|
| 369 | * associated with the file are reclaimed. If one or more process have the file open when |
---|
| 370 | * the last link is removed, the link is removed, but the removal of the file is delayed |
---|
| 371 | * until all references to it have been closed. |
---|
| 372 | ********************************************************************************************* |
---|
| 373 | * @ pathname : pathname (can be relative or absolute). |
---|
| 374 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 375 | ********************************************************************************************/ |
---|
[23] | 376 | int sys_unlink( char * pathname ); |
---|
[16] | 377 | |
---|
| 378 | /********************************************************************************************* |
---|
[23] | 379 | * [19] This function creates in the calling thread cluster an unnamed pipe, and two |
---|
| 380 | * (read and write) file descriptors. |
---|
| 381 | ********************************************************************************************* |
---|
| 382 | * @ file_id[0] : [out] read only file descriptor index. |
---|
| 383 | * @ file_id[1] : [out] write only file descriptor index. |
---|
| 384 | * @ return 0 if success / return -1 if failure. |
---|
[16] | 385 | ********************************************************************************************/ |
---|
[23] | 386 | int sys_pipe( uint32_t file_id[2] ); |
---|
[16] | 387 | |
---|
| 388 | /********************************************************************************************* |
---|
[23] | 389 | * [20] This function change the current working directory in reference process descriptor. |
---|
| 390 | ********************************************************************************************* |
---|
| 391 | * @ pathname : pathname (can be relative or absolute). |
---|
| 392 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 393 | ********************************************************************************************/ |
---|
[23] | 394 | int sys_chdir( char * pathname ); |
---|
[16] | 395 | |
---|
| 396 | /********************************************************************************************* |
---|
[23] | 397 | * [21] This function creates a new directory in file system. |
---|
| 398 | ********************************************************************************************* |
---|
| 399 | * @ pathname : pathname (can be relative or absolute). |
---|
| 400 | * @ mode : access rights (as defined in chmod). |
---|
| 401 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 402 | ********************************************************************************************/ |
---|
[23] | 403 | int sys_mkdir( char pathname, |
---|
| 404 | uint32_t mode ); |
---|
[16] | 405 | |
---|
| 406 | /********************************************************************************************* |
---|
[23] | 407 | * [22] This function creates a named FIFO file in the calling thread cluster. |
---|
| 408 | * The associated read and write file descriptors mut be be explicitely created |
---|
| 409 | * using the sy_open() function. |
---|
| 410 | ********************************************************************************************* |
---|
| 411 | * @ pathname : pathname (can be relative or absolute). |
---|
| 412 | * @ mode : access rights (as defined in chmod). |
---|
| 413 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 414 | ********************************************************************************************/ |
---|
[23] | 415 | int sys_mkfifo( char * pathname, |
---|
| 416 | uint32_t mode ); |
---|
[16] | 417 | |
---|
| 418 | /********************************************************************************************* |
---|
[23] | 419 | * [23] This function open a directory, that must exist in the file system. |
---|
| 420 | ********************************************************************************************* |
---|
| 421 | * @ pathname : pathname (can be relative or absolute). |
---|
| 422 | * @ return file descriptor index in fd_array if success / return -1 if failure. |
---|
[16] | 423 | ********************************************************************************************/ |
---|
[23] | 424 | int sys_opendir( char * pathname ); |
---|
[16] | 425 | |
---|
| 426 | /********************************************************************************************* |
---|
[23] | 427 | * [24] This function returns in the structure pointed by the <dirent> argument various |
---|
| 428 | * information about an entry of the directory identified by the <file_id> argument. |
---|
| 429 | ********************************************************************************************* |
---|
| 430 | * @ file_id : file descriptor index of the searched directory. |
---|
| 431 | * @ dirent : pointer on a dirent structure in user space. |
---|
| 432 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 433 | ********************************************************************************************/ |
---|
[23] | 434 | int sys_readdir( uint32_t file_id, |
---|
| 435 | struct vfs_dirent_s * dirent ); |
---|
[16] | 436 | |
---|
| 437 | /********************************************************************************************* |
---|
[23] | 438 | * [25] This function close the file descriptor previouly open by the opendir() function. |
---|
| 439 | ********************************************************************************************* |
---|
| 440 | * @ file_id : file descriptor index of the searched directory. |
---|
| 441 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 442 | ********************************************************************************************/ |
---|
[23] | 443 | int sys_closedir( uint32_t file_id ); |
---|
[16] | 444 | |
---|
| 445 | /********************************************************************************************* |
---|
[23] | 446 | * [26] This function returns the pathname of the current working directory. |
---|
| 447 | ********************************************************************************************* |
---|
| 448 | * buf : buffer addres in user space. |
---|
| 449 | * nbytes : user buffer size in bytes. |
---|
| 450 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 451 | ********************************************************************************************/ |
---|
[23] | 452 | int sys_getcwd( char * buf, |
---|
| 453 | uint32_t nbytes ); |
---|
[16] | 454 | |
---|
| 455 | /********************************************************************************************* |
---|
[23] | 456 | * [27] This function returns in a 64 bits user buffer the calling core cycles count. |
---|
| 457 | * It uses both the hardware register and the core descriptor cycles count tos take |
---|
| 458 | * into account a possible harware register overflow in 32 bits architectures. |
---|
| 459 | ********************************************************************************************* |
---|
| 460 | * cyles : [out] address of buffer in user space. |
---|
[16] | 461 | ********************************************************************************************/ |
---|
[23] | 462 | int sys_clock( uint64_t * cycles ); |
---|
[16] | 463 | |
---|
| 464 | /********************************************************************************************* |
---|
[23] | 465 | * [28] This function forces the calling thread to sleep, for a fixed number of cycles. |
---|
| 466 | ********************************************************************************************* |
---|
| 467 | * cycles : number of cycles. |
---|
[16] | 468 | ********************************************************************************************/ |
---|
[23] | 469 | int sys_alarm( uint32_t cycles ); |
---|
[16] | 470 | |
---|
| 471 | /********************************************************************************************* |
---|
[23] | 472 | * [29] This undefined function does nothing. |
---|
| 473 | ********************************************************************************************* |
---|
| 474 | * @ pathname : pathname (can be relative or absolute). |
---|
| 475 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 476 | ********************************************************************************************/ |
---|
[23] | 477 | int sys_rmdir( char * pathname ); |
---|
[16] | 478 | |
---|
| 479 | /********************************************************************************************* |
---|
[23] | 480 | * [30] This function implement the operations related to User Thread Local Storage. |
---|
| 481 | * It is actually implemented as an uint32_t variable in the thread descriptor. |
---|
| 482 | ********************************************************************************************* |
---|
| 483 | * @ operation : UTLS operation type as defined below. |
---|
| 484 | * @ value : argument value for the UTLS_SET operation. |
---|
| 485 | * @ return value for the UTLS_GET and UTLS_GET_ERRNO / return -1 if failure. |
---|
[16] | 486 | ********************************************************************************************/ |
---|
[23] | 487 | int sys_utls( uint32_t operation, |
---|
| 488 | uint32_t value ); |
---|
[16] | 489 | |
---|
[23] | 490 | typedef enum |
---|
| 491 | { |
---|
| 492 | UTLS_SET = 1, |
---|
| 493 | UTLS_GET = 2, |
---|
| 494 | UTLS_GET_ERRNO = 3, |
---|
| 495 | } |
---|
| 496 | utls_operation_t; |
---|
| 497 | |
---|
[16] | 498 | /********************************************************************************************* |
---|
[23] | 499 | * [31] This function change the acces rights for the file/dir identified by the |
---|
| 500 | * pathname argument. |
---|
| 501 | ********************************************************************************************* |
---|
| 502 | * @ pathname : pathname (can be relative or absolute). |
---|
| 503 | * @ rights : acces rights. |
---|
| 504 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 505 | ********************************************************************************************/ |
---|
[23] | 506 | int sys_chmod( char * pathname, |
---|
| 507 | uint32_t rights ); |
---|
[16] | 508 | |
---|
| 509 | /********************************************************************************************* |
---|
[23] | 510 | * [32] This function associate a specific signal handler to a given signal type. |
---|
| 511 | * Tee handlers for the SIGKILL and SIGSTOP signals cannot be redefined. |
---|
| 512 | ********************************************************************************************* |
---|
| 513 | * @ sig_id : index defining signal type (from 1 to 31). |
---|
| 514 | * @ handler : pointer on fonction implementing the specific handler. |
---|
| 515 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 516 | ********************************************************************************************/ |
---|
[23] | 517 | int sys_signal( uint32_t sig_id, |
---|
| 518 | void * handler ); |
---|
[16] | 519 | |
---|
| 520 | /********************************************************************************************* |
---|
[23] | 521 | * [33] This function returns in the structure <tv>, defined in the time.h file, |
---|
| 522 | * the current time (in seconds & micro-seconds). |
---|
| 523 | * It is computed from the calling core descriptor. |
---|
| 524 | * The timezone is not supported. |
---|
| 525 | ********************************************************************************************* |
---|
| 526 | * @ tv : pointer on the timeval structure. |
---|
| 527 | * @ tz : pointer on the timezone structure : must be NULL. |
---|
| 528 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 529 | ********************************************************************************************/ |
---|
[50] | 530 | int sys_timeofday( struct timeval * tv, |
---|
| 531 | struct timezone * tz ); |
---|
[16] | 532 | |
---|
| 533 | /********************************************************************************************* |
---|
| 534 | * [34] This function implements the "kill" system call. |
---|
[23] | 535 | * It register the signal defined by the <sig_id> argument in all thread descriptors |
---|
| 536 | * of a target process identified by the <pid> argument. This is done in all clusters |
---|
| 537 | * containing threads for the target process. |
---|
| 538 | * It can be executed by any thread running in any cluster, as this function uses |
---|
| 539 | * remote access to traverse the list of process copies in the owner cluster, |
---|
| 540 | * and the RPC_SIGNAL_RISE to signal the remote threads. |
---|
[16] | 541 | ********************************************************************************************* |
---|
| 542 | * @ pid : target process identifier. |
---|
[23] | 543 | * @ sig_id : index defining the signal type (from 1 to 31). |
---|
| 544 | * @ return 0 if success / returns -1 if failure. |
---|
[16] | 545 | ********************************************************************************************/ |
---|
| 546 | int sys_kill( pid_t pid, |
---|
[23] | 547 | uint32_t sig_id ); |
---|
[16] | 548 | |
---|
| 549 | /********************************************************************************************* |
---|
[23] | 550 | * [35] This function implements the "getpid" system call. |
---|
| 551 | ********************************************************************************************* |
---|
| 552 | * @ returns the PID for the calling thread. |
---|
[16] | 553 | ********************************************************************************************/ |
---|
[1] | 554 | int sys_getpid(); |
---|
| 555 | |
---|
| 556 | /********************************************************************************************* |
---|
[16] | 557 | * [36] This function implement the "fork" system call. |
---|
[1] | 558 | * The calling process descriptor (parent process), and the associated thread descriptor are |
---|
| 559 | * replicated in the same cluster as the calling thread, but the new process (child process) |
---|
[23] | 560 | * is registered in another target cluster, that is the new process owner. |
---|
[1] | 561 | * The child process and the associated main thread will be migrated to the target cluster |
---|
| 562 | * later, when the child process makes an "exec" or any other system call. |
---|
| 563 | * The target cluster depends on the "fork_user" flag and "fork_cxy" variable that can be |
---|
| 564 | * stored in the calling thread descriptor by the specific fork_place() system call. |
---|
| 565 | * If not, the sys_fork() function makes a query to the DQDT to select the target cluster. |
---|
| 566 | ********************************************************************************************* |
---|
| 567 | * @ returns child process PID if success / returns -1 if failure |
---|
| 568 | ********************************************************************************************/ |
---|
| 569 | int sys_fork(); |
---|
| 570 | |
---|
| 571 | /********************************************************************************************* |
---|
[16] | 572 | * [37] This function implement the "exec" system call. |
---|
[1] | 573 | * It is executed in the client cluster, but the new process descriptor and main thread |
---|
[23] | 574 | * must be created in a server cluster, that is generally another cluster. |
---|
| 575 | * - if the server_cluster is the client cluster, call directly the process_make_exec() |
---|
| 576 | * function to create a new process, and launch a new thread in local cluster. |
---|
| 577 | * - if the target_cluster is remote, call rpc_process_exec_client() to execute the |
---|
| 578 | * process_make_exec() on the remote cluster. |
---|
[1] | 579 | * In both case this function build an exec_info_t structure containing all informations |
---|
[23] | 580 | * required to build the new process descriptor and the associated thread. |
---|
| 581 | * Finally, the calling process and thread are deleted. |
---|
[16] | 582 | ********************************************************************************************* |
---|
[1] | 583 | * @ filename : string pointer on .elf filename (virtual pointer in user space) |
---|
| 584 | * @ argv : array of strings on process arguments (virtual pointers in user space) |
---|
| 585 | * @ envp : array of strings on Renvironment variables (virtual pointers in user space) |
---|
[23] | 586 | * @ returns O if success / returns -1 if failure. |
---|
[1] | 587 | ********************************************************************************************/ |
---|
| 588 | int sys_exec( char * filename, |
---|
| 589 | char ** argv, |
---|
| 590 | char ** envp ); |
---|
| 591 | |
---|
[16] | 592 | /********************************************************************************************* |
---|
[23] | 593 | * [38] This function returns in the <stat> structure, defined in the vfs.h file, |
---|
| 594 | * various informations on the file/directory identified by the <file_id> argument. |
---|
| 595 | ********************************************************************************************* |
---|
| 596 | * @ file_id : file descriptor index in fd_array. |
---|
| 597 | * @ stat : pointer on the stat structure. |
---|
| 598 | * @ returns O if success / returns -1 if failure. |
---|
[16] | 599 | ********************************************************************************************/ |
---|
[23] | 600 | int sys_stat( uint32_t file_id, |
---|
| 601 | struct vfs_stat_s * stat ); |
---|
[1] | 602 | |
---|
| 603 | /********************************************************************************************* |
---|
[23] | 604 | * [39] This function is used to activate / desactivate Rthe trace for a thread |
---|
| 605 | * identified by the <trdid> and <pid> arguments. |
---|
| 606 | * It can be called by any other thread. |
---|
| 607 | ********************************************************************************************* |
---|
| 608 | * @ operation : operation type as defined below. |
---|
| 609 | * @ pid : process identifier. |
---|
| 610 | * @ trdid : thread identifier. |
---|
| 611 | * @ returns O if success / returns -1 if failure. |
---|
[1] | 612 | ********************************************************************************************/ |
---|
[23] | 613 | int sys_trace( uint32_t operation, |
---|
| 614 | pid_t pid, |
---|
| 615 | uint32_t trdid ); |
---|
[1] | 616 | |
---|
[23] | 617 | typedef enum |
---|
| 618 | { |
---|
| 619 | TRACE_ON = 0, |
---|
| 620 | TRACE_OFF = 1, |
---|
| 621 | } |
---|
| 622 | trace_operation_t; |
---|
[1] | 623 | |
---|
| 624 | |
---|
[16] | 625 | #endif // _SYSCALLS_H_ |
---|