[1] | 1 | /* |
---|
[407] | 2 | * syscalls.h - Kernel side services for syscall handling. |
---|
[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> |
---|
[407] | 28 | #include <shared_syscalls.h> |
---|
[23] | 29 | |
---|
[407] | 30 | /** Forward declarations *****/ |
---|
[23] | 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 | |
---|
[407] | 38 | /****************************************************************************************** |
---|
| 39 | * [0] This function terminates the execution of the calling user thread, |
---|
[23] | 40 | * and makes the exit_value pointer available to any successful pthread_join() with the |
---|
| 41 | * terminating thread. |
---|
[409] | 42 | * It actually set the THREAD_SIG_EXIT signal, set the THREAD_BLOCKED_GLOBAL bit in the |
---|
| 43 | * thread descriptor and deschedule. |
---|
| 44 | * The thread will be detached from its process, and the memory allocated to the thread |
---|
| 45 | * descriptor will be released later by the scheduler. |
---|
[407] | 46 | ****************************************************************************************** |
---|
[409] | 47 | * @ exit_vallue : pointer to be returned to joining thread if thread is attached. |
---|
| 48 | * @ return 0 if success / return -1 if all locks not released or illegal argument. |
---|
[407] | 49 | *****************************************************************************************/ |
---|
[23] | 50 | int sys_thread_exit( void * exit_value ); |
---|
[16] | 51 | |
---|
[407] | 52 | /****************************************************************************************** |
---|
| 53 | * [1] This function calls the scheduler for the core running the calling thread. |
---|
| 54 | ****************************************************************************************** |
---|
| 55 | * @ x_size : [out] number of clusters in a row. |
---|
| 56 | * @ y_size : [out] number of clusters in a column. |
---|
| 57 | * @ ncores : [out] number of cores per cluster. |
---|
| 58 | * @ return always 0. |
---|
| 59 | *****************************************************************************************/ |
---|
| 60 | int sys_thread_yield(); |
---|
[16] | 61 | |
---|
[407] | 62 | /****************************************************************************************** |
---|
[23] | 63 | * [2] This function creates a new user thread. The <user_attr> argument is a pointer |
---|
| 64 | * on astructure containing the thread attributes, defined in thread.h file. |
---|
[407] | 65 | ****************************************************************************************** |
---|
[23] | 66 | * @ new_thread : [out] local pointer on created thread descriptor. |
---|
| 67 | * @ user_attr : [in] pointer on thread attributes structure. |
---|
| 68 | * @ start_func : [in] pointer on start function. |
---|
| 69 | * @ start_args : [in] pointer on start function arguments. |
---|
| 70 | * @ return 0 if success / return -1 if failure. |
---|
[407] | 71 | *****************************************************************************************/ |
---|
[23] | 72 | int sys_thread_create( struct thread_s * new_thread, |
---|
| 73 | struct pthread_attr_s * user_attr, |
---|
| 74 | void * start_func, |
---|
| 75 | void * start_args ); |
---|
[16] | 76 | |
---|
[407] | 77 | /****************************************************************************************** |
---|
[23] | 78 | * [3] This blocking function suspend execution of the calling thread until completion |
---|
| 79 | * of another target thread identified by the <trdid> argument. |
---|
[421] | 80 | * The target thread must be joinable (running in ATTACHED mode), and must be different |
---|
| 81 | * from the calling thread. |
---|
[23] | 82 | * If the <exit_value> argument is not NULL, the value passed to pthread_exit() by the |
---|
| 83 | * target thread is stored in the location referenced by exit_value. |
---|
[407] | 84 | ****************************************************************************************** |
---|
[23] | 85 | * @ trdid : [in] target thread identifier. |
---|
| 86 | * @ thread : [out] buffer for exit_value returned by target thread. |
---|
| 87 | * @ return 0 if success / return -1 if failure. |
---|
[407] | 88 | *****************************************************************************************/ |
---|
[23] | 89 | int sys_thread_join( trdid_t trdid, |
---|
| 90 | void ** exit_value ); |
---|
[16] | 91 | |
---|
[407] | 92 | /****************************************************************************************** |
---|
[23] | 93 | * [4] This function detach a joinable thread. |
---|
[407] | 94 | ****************************************************************************************** |
---|
[409] | 95 | * @ trdid : thread identifier. |
---|
[23] | 96 | * @ return 0 if success / return -1 if failure. |
---|
[407] | 97 | *****************************************************************************************/ |
---|
[23] | 98 | int sys_thread_detach( trdid_t trdid ); |
---|
[16] | 99 | |
---|
[407] | 100 | /****************************************************************************************** |
---|
[409] | 101 | * [5] This function requests a target thread identified by its <trdid> argument |
---|
| 102 | * to be cancelled. Depending on killer thread and target thread location, it calls |
---|
| 103 | * the thread_kil() function or the rpc_thread_kill_client() function to do the work. |
---|
| 104 | * It actually set the THREAD_SIG_KILL signal, set the THREAD_BLOCKED_GLOBAL bit in the |
---|
| 105 | * target thread descriptor and return. |
---|
| 106 | * The thread will be detached from its process, and the memory allocated to the thread |
---|
| 107 | * descriptor will be released later by the scheduler. |
---|
| 108 | ****************************************************************************************** |
---|
| 109 | * @ trdid : thread identifier. |
---|
| 110 | * @ return 0 if success / return -1 if illegal argument. |
---|
[407] | 111 | *****************************************************************************************/ |
---|
[409] | 112 | int sys_thread_cancel( trdid_t trdid ); |
---|
[16] | 113 | |
---|
[407] | 114 | /****************************************************************************************** |
---|
[23] | 115 | * [6] This function implement all operations on a POSIX unnamed semaphore, |
---|
| 116 | * that can be shared by threads running in different clusters. |
---|
| 117 | * The kernel structure representing a remote semaphore is in the remote_sem.h file, |
---|
| 118 | * and the code implementing the operations is in the remore_sem.c file. |
---|
[407] | 119 | ****************************************************************************************** |
---|
[23] | 120 | * @ vaddr : semaphore virtual address in user space == identifier. |
---|
| 121 | * @ operation : SEM_INIT / SEM_DESTROY / SEM_GETVALUE / SEM_POST / SEM_WAIT. |
---|
| 122 | * @ value : pointer on in/out argument in user space. |
---|
| 123 | * @ return 0 if success / return -1 if failure. |
---|
[407] | 124 | *****************************************************************************************/ |
---|
[23] | 125 | int sys_sem( void * vaddr, |
---|
| 126 | uint32_t operation, |
---|
| 127 | uint32_t * value ); |
---|
[16] | 128 | |
---|
[407] | 129 | /****************************************************************************************** |
---|
[23] | 130 | * [7] This function implement all operations on a POSIX condition variable. |
---|
| 131 | * The kernel structure representing a cond_var is defined in the remote_cv.h file, |
---|
| 132 | * The code implementing the operations is defined in the remote_cv.c file. |
---|
[407] | 133 | ****************************************************************************************** |
---|
[23] | 134 | * @ vaddr : condvar virtual address in user space == identifier. |
---|
| 135 | * @ operation : operation type (see below). |
---|
| 136 | * @ attr : mutex virtual address in user space == identifier. |
---|
| 137 | * @ return 0 if success / return -1 if failure. |
---|
[407] | 138 | *****************************************************************************************/ |
---|
[23] | 139 | int sys_condvar( void * condvar, |
---|
| 140 | uint32_t operation, |
---|
| 141 | void * mutex ); |
---|
[16] | 142 | |
---|
[407] | 143 | /****************************************************************************************** |
---|
[23] | 144 | * [8] This function implement all operations on a POSIX barrier. |
---|
| 145 | * The kernel structure representing a barrier is defined in the remote_barrier.h file. |
---|
| 146 | * The code implementting the operations is defined in the remote_barrier.c file. |
---|
[407] | 147 | ****************************************************************************************** |
---|
[23] | 148 | * @ vaddr : barrier virtual address in user space == identifier. |
---|
| 149 | * @ operation : BARRIER_INIT / BARRIER_DESTROY / BARRIER_WAIT. |
---|
| 150 | * @ count : number of expected threads (only used by BARRIER_INIT operation). |
---|
| 151 | * @ return 0 if success / return -1 if failure. |
---|
[407] | 152 | *****************************************************************************************/ |
---|
[23] | 153 | int sys_barrier( void * vaddr, |
---|
| 154 | uint32_t operation, |
---|
| 155 | uint32_t count ); |
---|
[16] | 156 | |
---|
[407] | 157 | /****************************************************************************************** |
---|
[23] | 158 | * [9] This function implement all operations on a POSIX mutex. |
---|
| 159 | * The kernel structure representing a barrier is defined in the remote_barrier.h file. |
---|
| 160 | * The code implementting the operations is defined in the remote_barrier.c file. |
---|
[407] | 161 | ****************************************************************************************** |
---|
[23] | 162 | * @ vaddr : mutex virtual address in user space == identifier. |
---|
| 163 | * @ operation : MUTEX_INIT / MUTEX_DESTROY / MUTEX_LOCK / MUTEX_UNLOCK |
---|
| 164 | * @ attr : mutex attributes (non supported yet => must be 0). |
---|
| 165 | * @ return 0 if success / return -1 if failure. |
---|
[407] | 166 | *****************************************************************************************/ |
---|
[23] | 167 | int sys_mutex( void * vaddr, |
---|
| 168 | uint32_t operation, |
---|
| 169 | uint32_t count ); |
---|
[16] | 170 | |
---|
[407] | 171 | /****************************************************************************************** |
---|
[408] | 172 | * [10] This function implement the exit system call terminating a POSIX process. |
---|
[407] | 173 | ****************************************************************************************** |
---|
[408] | 174 | * @ status : terminaison status (not used in present implementation). |
---|
[407] | 175 | *****************************************************************************************/ |
---|
[409] | 176 | int sys_exit( uint32_t status ); |
---|
[16] | 177 | |
---|
[407] | 178 | /****************************************************************************************** |
---|
[408] | 179 | * [11] This function remove an existing mapping defined by the <addr> and <size> |
---|
[407] | 180 | * arguments in user space. |
---|
| 181 | ****************************************************************************************** |
---|
| 182 | * @ addr : base address in user space. |
---|
| 183 | * # size : number of bytes. |
---|
[23] | 184 | * @ return 0 if success / return -1 if failure. |
---|
[407] | 185 | *****************************************************************************************/ |
---|
| 186 | int sys_munmap( void * addr, |
---|
| 187 | uint32_t size ); |
---|
[16] | 188 | |
---|
[407] | 189 | /****************************************************************************************** |
---|
| 190 | * [12] This function open or create an open file descriptor. |
---|
| 191 | ****************************************************************************************** |
---|
[23] | 192 | * @ pathname : pathname (can be relative or absolute). |
---|
| 193 | * @ flags : bit vector attributes (see below). |
---|
| 194 | * @ mode : access rights. |
---|
| 195 | * @ return file descriptor index in fd_array if success / return -1 if failure. |
---|
[407] | 196 | *****************************************************************************************/ |
---|
[23] | 197 | int sys_open( char * pathname, |
---|
| 198 | uint32_t flags, |
---|
| 199 | uint32_t mode ); |
---|
[16] | 200 | |
---|
[407] | 201 | /****************************************************************************************** |
---|
| 202 | * [13] This function map physical memory (or a file) in the calling thread virtual space. |
---|
| 203 | * The <attr> argument is a pointer on a structure for arguments (see shared_syscalls.h). |
---|
| 204 | ****************************************************************************************** |
---|
| 205 | * @ attr : pointer on attributes structure. |
---|
| 206 | * @ return 0 if success / return -1 if failure. |
---|
| 207 | *****************************************************************************************/ |
---|
| 208 | int sys_mmap( mmap_attr_t * attr ); |
---|
[23] | 209 | |
---|
[407] | 210 | /****************************************************************************************** |
---|
[23] | 211 | * [14] This function read bytes from an open file identified by its file descriptor. |
---|
[407] | 212 | * The file can be a regular file or character oriented device. |
---|
[408] | 213 | * IRQs are enabled during this system call. |
---|
[407] | 214 | ****************************************************************************************** |
---|
[23] | 215 | * @ file_id : open file index in fd_array. |
---|
| 216 | * @ buf : buffer virtual address in user space. |
---|
| 217 | * @ count : number of bytes. |
---|
| 218 | * @ return number of bytes actually read if success / returns -1 if failure. |
---|
[407] | 219 | *****************************************************************************************/ |
---|
[23] | 220 | int sys_read( uint32_t file_id, |
---|
| 221 | void * buf, |
---|
| 222 | uint32_t count ); |
---|
[16] | 223 | |
---|
[407] | 224 | /****************************************************************************************** |
---|
[23] | 225 | * [15] This function writes bytes to an open file identified by its file descriptor. |
---|
[407] | 226 | * The file can be a regular file or character oriented device. |
---|
[408] | 227 | * IRQs are enabled during this system call. |
---|
[407] | 228 | ****************************************************************************************** |
---|
[23] | 229 | * @ file_id : open file index in fd_array. |
---|
| 230 | * @ buf : buffer virtual address in user space. |
---|
| 231 | * @ count : number of bytes. |
---|
| 232 | * @ return number of bytes actually written if success / returns -1 if failure. |
---|
[407] | 233 | *****************************************************************************************/ |
---|
[23] | 234 | int sys_write( uint32_t file_id, |
---|
| 235 | void * buf, |
---|
| 236 | uint32_t count ); |
---|
[16] | 237 | |
---|
[407] | 238 | /****************************************************************************************** |
---|
| 239 | * [16] This function repositions the offset of the file descriptor identified by <file_id>, |
---|
| 240 | * according to the operation type defined by the <whence> argument. |
---|
| 241 | ****************************************************************************************** |
---|
[23] | 242 | * @ file_id : open file index in fd_array. |
---|
[407] | 243 | * @ offset : used to compute new offset value. |
---|
[23] | 244 | * @ whence : operation type (see below). |
---|
| 245 | * @ return 0 if success / returns -1 if failure. |
---|
[407] | 246 | *****************************************************************************************/ |
---|
[23] | 247 | int sys_lseek( xptr_t file_id, |
---|
| 248 | uint32_t offset, |
---|
| 249 | uint32_t whence ); |
---|
[16] | 250 | |
---|
[407] | 251 | /****************************************************************************************** |
---|
[23] | 252 | * [17] This function release the memory allocated for the file descriptor identified by |
---|
| 253 | * the <file_id> argument, and remove the fd array_entry in all copies of the process |
---|
| 254 | * descriptor. |
---|
[407] | 255 | ****************************************************************************************** |
---|
[23] | 256 | file_id : file descriptor index in fd_array. |
---|
| 257 | * @ return 0 if success / returns -1 if failure. |
---|
[407] | 258 | *****************************************************************************************/ |
---|
[23] | 259 | int sys_close( uint32_t file_id ); |
---|
[16] | 260 | |
---|
[407] | 261 | /****************************************************************************************** |
---|
| 262 | * [18] This function removes a directory entry identified by the <pathname> from the |
---|
[23] | 263 | * directory, and decrement the link count of the file referenced by the link. |
---|
| 264 | * If the link count reduces to zero, and no process has the file open, then all resources |
---|
| 265 | * associated with the file are reclaimed. If one or more process have the file open when |
---|
| 266 | * the last link is removed, the link is removed, but the removal of the file is delayed |
---|
| 267 | * until all references to it have been closed. |
---|
[407] | 268 | ****************************************************************************************** |
---|
[23] | 269 | * @ pathname : pathname (can be relative or absolute). |
---|
| 270 | * @ return 0 if success / returns -1 if failure. |
---|
[407] | 271 | *****************************************************************************************/ |
---|
[23] | 272 | int sys_unlink( char * pathname ); |
---|
[16] | 273 | |
---|
[407] | 274 | /****************************************************************************************** |
---|
[23] | 275 | * [19] This function creates in the calling thread cluster an unnamed pipe, and two |
---|
| 276 | * (read and write) file descriptors. |
---|
[407] | 277 | * TODO not implemented yet... |
---|
| 278 | ****************************************************************************************** |
---|
[23] | 279 | * @ file_id[0] : [out] read only file descriptor index. |
---|
| 280 | * @ file_id[1] : [out] write only file descriptor index. |
---|
| 281 | * @ return 0 if success / return -1 if failure. |
---|
[407] | 282 | *****************************************************************************************/ |
---|
[23] | 283 | int sys_pipe( uint32_t file_id[2] ); |
---|
[16] | 284 | |
---|
[407] | 285 | /****************************************************************************************** |
---|
[23] | 286 | * [20] This function change the current working directory in reference process descriptor. |
---|
[407] | 287 | ****************************************************************************************** |
---|
[23] | 288 | * @ pathname : pathname (can be relative or absolute). |
---|
| 289 | * @ return 0 if success / returns -1 if failure. |
---|
[407] | 290 | *****************************************************************************************/ |
---|
[23] | 291 | int sys_chdir( char * pathname ); |
---|
[16] | 292 | |
---|
[407] | 293 | /****************************************************************************************** |
---|
[23] | 294 | * [21] This function creates a new directory in file system. |
---|
[407] | 295 | ****************************************************************************************** |
---|
[23] | 296 | * @ pathname : pathname (can be relative or absolute). |
---|
| 297 | * @ mode : access rights (as defined in chmod). |
---|
| 298 | * @ return 0 if success / returns -1 if failure. |
---|
[407] | 299 | *****************************************************************************************/ |
---|
[279] | 300 | int sys_mkdir( char * pathname, |
---|
[23] | 301 | uint32_t mode ); |
---|
[16] | 302 | |
---|
[407] | 303 | /****************************************************************************************** |
---|
[23] | 304 | * [22] This function creates a named FIFO file in the calling thread cluster. |
---|
| 305 | * The associated read and write file descriptors mut be be explicitely created |
---|
[407] | 306 | * using the sys_open() function. |
---|
| 307 | ****************************************************************************************** |
---|
[23] | 308 | * @ pathname : pathname (can be relative or absolute). |
---|
| 309 | * @ mode : access rights (as defined in chmod). |
---|
| 310 | * @ return 0 if success / returns -1 if failure. |
---|
[407] | 311 | *****************************************************************************************/ |
---|
[23] | 312 | int sys_mkfifo( char * pathname, |
---|
| 313 | uint32_t mode ); |
---|
[16] | 314 | |
---|
[407] | 315 | /****************************************************************************************** |
---|
| 316 | * [23] This function open a directory, that must exist in the file system, returning |
---|
| 317 | * a DIR pointer on the directory in user space. |
---|
| 318 | ****************************************************************************************** |
---|
[23] | 319 | * @ pathname : pathname (can be relative or absolute). |
---|
[407] | 320 | * @ dirp : [out] buffer for pointer on user directory (DIR). |
---|
[23] | 321 | * @ return 0 if success / returns -1 if failure. |
---|
[407] | 322 | *****************************************************************************************/ |
---|
| 323 | int sys_opendir( char * pathname, |
---|
| 324 | DIR ** dirp ); |
---|
[16] | 325 | |
---|
[407] | 326 | /****************************************************************************************** |
---|
| 327 | * [24] This function returns an user pointer on the dirent structure describing the |
---|
| 328 | * next directory entry in the directory identified by the <dirp> argument. |
---|
| 329 | ****************************************************************************************** |
---|
| 330 | * @ dirp : user pointer identifying the searched directory. |
---|
| 331 | * @ dentp : [out] buffer for pointer on user direntory entry (dirent). |
---|
| 332 | * @ return O if success / returns -1 if failure. |
---|
| 333 | *****************************************************************************************/ |
---|
| 334 | int sys_readdir( DIR * dirp, |
---|
| 335 | struct dirent ** dentp ); |
---|
| 336 | |
---|
| 337 | /****************************************************************************************** |
---|
| 338 | * [25] This function closes the directory identified by the <dirp> argument, and releases |
---|
| 339 | * all structures associated with the <dirp> pointer. |
---|
| 340 | ****************************************************************************************** |
---|
| 341 | * @ dirp : user pointer identifying the directory. |
---|
[23] | 342 | * @ return 0 if success / returns -1 if failure. |
---|
[407] | 343 | *****************************************************************************************/ |
---|
| 344 | int sys_closedir( DIR * dirp ); |
---|
[16] | 345 | |
---|
[407] | 346 | /****************************************************************************************** |
---|
[23] | 347 | * [26] This function returns the pathname of the current working directory. |
---|
[407] | 348 | ****************************************************************************************** |
---|
[23] | 349 | * buf : buffer addres in user space. |
---|
| 350 | * nbytes : user buffer size in bytes. |
---|
| 351 | * @ return 0 if success / returns -1 if failure. |
---|
[407] | 352 | *****************************************************************************************/ |
---|
[23] | 353 | int sys_getcwd( char * buf, |
---|
| 354 | uint32_t nbytes ); |
---|
[16] | 355 | |
---|
[407] | 356 | /****************************************************************************************** |
---|
| 357 | * [27] This slot is not used. |
---|
| 358 | *****************************************************************************************/ |
---|
[16] | 359 | |
---|
[407] | 360 | /****************************************************************************************** |
---|
[23] | 361 | * [28] This function forces the calling thread to sleep, for a fixed number of cycles. |
---|
[407] | 362 | ****************************************************************************************** |
---|
[23] | 363 | * cycles : number of cycles. |
---|
[407] | 364 | *****************************************************************************************/ |
---|
[23] | 365 | int sys_alarm( uint32_t cycles ); |
---|
[16] | 366 | |
---|
[407] | 367 | /****************************************************************************************** |
---|
| 368 | * [29] This function removes a directory file whose name is given by <pathname>. |
---|
| 369 | * The directory must not have any entries other than `.' and `..'. |
---|
| 370 | ****************************************************************************************** |
---|
[23] | 371 | * @ pathname : pathname (can be relative or absolute). |
---|
| 372 | * @ return 0 if success / returns -1 if failure. |
---|
[407] | 373 | *****************************************************************************************/ |
---|
[23] | 374 | int sys_rmdir( char * pathname ); |
---|
[16] | 375 | |
---|
[407] | 376 | /****************************************************************************************** |
---|
[23] | 377 | * [30] This function implement the operations related to User Thread Local Storage. |
---|
| 378 | * It is actually implemented as an uint32_t variable in the thread descriptor. |
---|
[407] | 379 | ****************************************************************************************** |
---|
[23] | 380 | * @ operation : UTLS operation type as defined below. |
---|
| 381 | * @ value : argument value for the UTLS_SET operation. |
---|
| 382 | * @ return value for the UTLS_GET and UTLS_GET_ERRNO / return -1 if failure. |
---|
[407] | 383 | *****************************************************************************************/ |
---|
[23] | 384 | int sys_utls( uint32_t operation, |
---|
| 385 | uint32_t value ); |
---|
[16] | 386 | |
---|
[407] | 387 | /****************************************************************************************** |
---|
[23] | 388 | * [31] This function change the acces rights for the file/dir identified by the |
---|
| 389 | * pathname argument. |
---|
[407] | 390 | ****************************************************************************************** |
---|
[23] | 391 | * @ pathname : pathname (can be relative or absolute). |
---|
| 392 | * @ rights : acces rights. |
---|
| 393 | * @ return 0 if success / returns -1 if failure. |
---|
[407] | 394 | *****************************************************************************************/ |
---|
[23] | 395 | int sys_chmod( char * pathname, |
---|
| 396 | uint32_t rights ); |
---|
[16] | 397 | |
---|
[407] | 398 | /****************************************************************************************** |
---|
[23] | 399 | * [32] This function associate a specific signal handler to a given signal type. |
---|
| 400 | * Tee handlers for the SIGKILL and SIGSTOP signals cannot be redefined. |
---|
[407] | 401 | ****************************************************************************************** |
---|
[23] | 402 | * @ sig_id : index defining signal type (from 1 to 31). |
---|
| 403 | * @ handler : pointer on fonction implementing the specific handler. |
---|
| 404 | * @ return 0 if success / returns -1 if failure. |
---|
[407] | 405 | *****************************************************************************************/ |
---|
[23] | 406 | int sys_signal( uint32_t sig_id, |
---|
| 407 | void * handler ); |
---|
[16] | 408 | |
---|
[407] | 409 | /****************************************************************************************** |
---|
[23] | 410 | * [33] This function returns in the structure <tv>, defined in the time.h file, |
---|
| 411 | * the current time (in seconds & micro-seconds). |
---|
| 412 | * It is computed from the calling core descriptor. |
---|
| 413 | * The timezone is not supported. |
---|
[407] | 414 | ****************************************************************************************** |
---|
[23] | 415 | * @ tv : pointer on the timeval structure. |
---|
| 416 | * @ tz : pointer on the timezone structure : must be NULL. |
---|
| 417 | * @ return 0 if success / returns -1 if failure. |
---|
[407] | 418 | *****************************************************************************************/ |
---|
[50] | 419 | int sys_timeofday( struct timeval * tv, |
---|
| 420 | struct timezone * tz ); |
---|
[16] | 421 | |
---|
[407] | 422 | /****************************************************************************************** |
---|
[16] | 423 | * [34] This function implements the "kill" system call. |
---|
[23] | 424 | * It register the signal defined by the <sig_id> argument in all thread descriptors |
---|
| 425 | * of a target process identified by the <pid> argument. This is done in all clusters |
---|
| 426 | * containing threads for the target process. |
---|
| 427 | * It can be executed by any thread running in any cluster, as this function uses |
---|
[407] | 428 | * remote access to traverse the list of process copies stored in the owner cluster, |
---|
[23] | 429 | * and the RPC_SIGNAL_RISE to signal the remote threads. |
---|
[421] | 430 | * This function does nothing for (sig_id == 0). This can be used to check process pid. |
---|
| 431 | * TODO : This first implementation supports only SIGKILL / SIGSTOP / SIGCONT values. |
---|
[407] | 432 | ****************************************************************************************** |
---|
[16] | 433 | * @ pid : target process identifier. |
---|
[23] | 434 | * @ sig_id : index defining the signal type (from 1 to 31). |
---|
| 435 | * @ return 0 if success / returns -1 if failure. |
---|
[407] | 436 | *****************************************************************************************/ |
---|
[16] | 437 | int sys_kill( pid_t pid, |
---|
[23] | 438 | uint32_t sig_id ); |
---|
[16] | 439 | |
---|
[407] | 440 | /****************************************************************************************** |
---|
[23] | 441 | * [35] This function implements the "getpid" system call. |
---|
[407] | 442 | ****************************************************************************************** |
---|
| 443 | * @ returns the process PID for the calling thread. |
---|
| 444 | *****************************************************************************************/ |
---|
[1] | 445 | int sys_getpid(); |
---|
| 446 | |
---|
[407] | 447 | /****************************************************************************************** |
---|
[16] | 448 | * [36] This function implement the "fork" system call. |
---|
[1] | 449 | * The calling process descriptor (parent process), and the associated thread descriptor are |
---|
| 450 | * replicated in the same cluster as the calling thread, but the new process (child process) |
---|
[23] | 451 | * is registered in another target cluster, that is the new process owner. |
---|
[1] | 452 | * The child process and the associated main thread will be migrated to the target cluster |
---|
[407] | 453 | * later, when the child process makes an "exec" or any other system call... TODO [AG] |
---|
[1] | 454 | * The target cluster depends on the "fork_user" flag and "fork_cxy" variable that can be |
---|
| 455 | * stored in the calling thread descriptor by the specific fork_place() system call. |
---|
| 456 | * If not, the sys_fork() function makes a query to the DQDT to select the target cluster. |
---|
[407] | 457 | ****************************************************************************************** |
---|
| 458 | * @ if success, returns child process PID to parent, and return O to child. |
---|
| 459 | * @ if failure, returns -1 to parent / no child process is created. |
---|
| 460 | *****************************************************************************************/ |
---|
[1] | 461 | int sys_fork(); |
---|
| 462 | |
---|
[407] | 463 | /****************************************************************************************** |
---|
| 464 | * [37] This function implement the "exec" system call, that creates a new process |
---|
| 465 | * descriptor. |
---|
| 466 | * It is executed in the client cluster, but the new process descriptor and the main |
---|
| 467 | * thread are created in a server cluster, that is generally another cluster. |
---|
| 468 | * - if the server_cluster is the client cluster, it calls directly the process_make_exec() |
---|
[23] | 469 | * function to create a new process, and launch a new thread in local cluster. |
---|
[407] | 470 | * - if the target_cluster is remote, it calls the rpc_process_exec_client() to execute |
---|
| 471 | * process_signedmake_exec() on the remote cluster. |
---|
[1] | 472 | * In both case this function build an exec_info_t structure containing all informations |
---|
[23] | 473 | * required to build the new process descriptor and the associated thread. |
---|
| 474 | * Finally, the calling process and thread are deleted. |
---|
[407] | 475 | ****************************************************************************************** |
---|
| 476 | * @ filename : string pointer on .elf filename (pointer in user space) |
---|
| 477 | * @ argv : array of strings on process arguments (pointers in user space) |
---|
| 478 | * @ envp : array of strings on environment variables (pointers in user space) |
---|
[23] | 479 | * @ returns O if success / returns -1 if failure. |
---|
[407] | 480 | *****************************************************************************************/ |
---|
[1] | 481 | int sys_exec( char * filename, |
---|
| 482 | char ** argv, |
---|
| 483 | char ** envp ); |
---|
| 484 | |
---|
[407] | 485 | /****************************************************************************************** |
---|
| 486 | * [38] This function returns in the <stat> structure, defined in the "shared_syscalls.h" |
---|
| 487 | * file, various informations on the file/directory identified by the <pathname> argument. |
---|
| 488 | ****************************************************************************************** |
---|
| 489 | * @ pathname : user pointer on file pathname. |
---|
| 490 | * @ stat : user pointer on the stat structure. |
---|
[23] | 491 | * @ returns O if success / returns -1 if failure. |
---|
[407] | 492 | *****************************************************************************************/ |
---|
| 493 | int sys_stat( const char * pathname, |
---|
| 494 | struct stat * stat ); |
---|
[1] | 495 | |
---|
[407] | 496 | /****************************************************************************************** |
---|
[421] | 497 | * [39] This blocking function wait a change of a child process state. A change can be: |
---|
| 498 | * - a termination of child following a child exit. |
---|
| 499 | * - a termination of child following a SIGKILL signal. |
---|
| 500 | * - a blocking of child following a SIGSTOP signal. |
---|
| 501 | * It returns the PID of the involved child process, after storing in the memory slot |
---|
| 502 | * pointed by the <status> argument relevant information on the child state change. |
---|
| 503 | * The following macros can be used to extract information from status: |
---|
| 504 | * - WIFEXITED(status) : is true if the child process terminated with an exit(). |
---|
| 505 | * - WIFSIGNALED(status) : is true if the child process terminated by a signal. |
---|
| 506 | * - WIFSTOPPED(status) : is true if the child process is stopped by a signal. |
---|
| 507 | * - WEXITSTATUS(status) : returns the low-order 8 bits of the exit() argument. |
---|
| 508 | * A status of 0 indicates a normal termination. |
---|
| 509 | * If a parent process terminates without waiting for all child processes to terminate, |
---|
| 510 | * the remaining child processes are attached to the init process. |
---|
| 511 | ****************************************************************************************** |
---|
| 512 | * @ status : pointer on the child PID status. |
---|
| 513 | * @ return child PID if success / return -1 if failure. |
---|
[407] | 514 | *****************************************************************************************/ |
---|
[421] | 515 | int sys_wait( uint32_t * status ); |
---|
[1] | 516 | |
---|
[407] | 517 | /****************************************************************************************** |
---|
| 518 | * [40] This function returns the hardware platform parameters. |
---|
| 519 | ****************************************************************************************** |
---|
| 520 | * @ x_size : [out] number of clusters in a row. |
---|
| 521 | * @ y_size : [out] number of clusters in a column. |
---|
[421] | 522 | * @ y_width : [out] number of bits in Y field for CXY. |
---|
[407] | 523 | * @ ncores : [out] number of cores per cluster. |
---|
| 524 | * @ return 0 if success / return -1 if illegal arguments |
---|
| 525 | *****************************************************************************************/ |
---|
| 526 | int sys_get_config( uint32_t * x_size, |
---|
| 527 | uint32_t * y_size, |
---|
[421] | 528 | uint32_t * y_width, |
---|
[407] | 529 | uint32_t * ncores ); |
---|
[1] | 530 | |
---|
[407] | 531 | /****************************************************************************************** |
---|
| 532 | * [41] This function returns the calling core cluster and local index. |
---|
| 533 | ****************************************************************************************** |
---|
| 534 | * @ cxy : [out] cluster identifier (fixed format) |
---|
| 535 | * @ lid : [out] core local index in cluster. |
---|
| 536 | * @ return 0 if success / return -1 if illegal arguments |
---|
| 537 | *****************************************************************************************/ |
---|
| 538 | int sys_get_core( uint32_t * cxy, |
---|
| 539 | uint32_t * lid ); |
---|
[1] | 540 | |
---|
[407] | 541 | /****************************************************************************************** |
---|
| 542 | * [42] This function returns in a 64 bits user buffer the calling core cycles count. |
---|
| 543 | * It uses both the hardware register and the core descriptor cycles count to take |
---|
| 544 | * into account a possible harware register overflow in 32 bits architectures. |
---|
| 545 | ****************************************************************************************** |
---|
| 546 | * cycle : [out] address of buffer in user space. |
---|
| 547 | * @ return 0 if success / return -1 if illegal arguments |
---|
| 548 | *****************************************************************************************/ |
---|
| 549 | int sys_get_cycle( uint64_t * cycle ); |
---|
| 550 | |
---|
| 551 | /****************************************************************************************** |
---|
[421] | 552 | * [43] This debug function displays on the kernel terminal TXT0 an user defined string, |
---|
| 553 | * or the current state of a kernel structure, identified by the <type> argument. |
---|
| 554 | * The <arg0> and <arg1> arguments depends on the structure type. It can be: |
---|
| 555 | * - VMM : VSL and GPT for a process identified by <pid>. |
---|
| 556 | * - SCHED : all threads allocated to a scheduler identified by <cxy> & <lid>. |
---|
| 557 | * - PROCESS : all processes registered in a cluster identified by <cxy>. |
---|
| 558 | * - VFS : all files registered in the VFS cache. |
---|
| 559 | * - CHDEV : all registered channel devices. |
---|
[407] | 560 | ****************************************************************************************** |
---|
[421] | 561 | * type : [in] STRING / VMM / SCHED / PROCESS / VSEG / VFS |
---|
| 562 | * arg0 : [in] type dependant argument. |
---|
| 563 | * arg1 : [in] type dependant argument. |
---|
[407] | 564 | * @ return 0 if success / return -1 if illegal arguments |
---|
| 565 | *****************************************************************************************/ |
---|
[421] | 566 | int sys_display( reg_t type, |
---|
| 567 | reg_t arg0, |
---|
| 568 | reg_t arg1 ); |
---|
[407] | 569 | |
---|
| 570 | /****************************************************************************************** |
---|
| 571 | * [45] This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition, |
---|
| 572 | * and deschedule. |
---|
| 573 | ****************************************************************************************** |
---|
| 574 | * @ return 0 if success / returns -1 if failure. |
---|
| 575 | *****************************************************************************************/ |
---|
| 576 | int sys_thread_sleep(); |
---|
| 577 | |
---|
| 578 | /****************************************************************************************** |
---|
| 579 | * [46] This function unblock the thread identified by its <trdid> from the |
---|
| 580 | * THREAD_BLOCKED_GLOBAL condition. |
---|
| 581 | ****************************************************************************************** |
---|
| 582 | * @ trdid : target thread identifier. |
---|
| 583 | * @ return 0 if success / return -1 if failure. |
---|
| 584 | *****************************************************************************************/ |
---|
| 585 | int sys_thread_wakeup(); |
---|
| 586 | |
---|
[421] | 587 | /****************************************************************************************** |
---|
| 588 | * [47] This non-standard function is used to activate / desactivate the trace for a thread |
---|
| 589 | * identified by the <trdid> and <pid> arguments. |
---|
| 590 | * It can be called by any other thread in the same process. |
---|
| 591 | ****************************************************************************************** |
---|
| 592 | * @ operation : operation type as defined below. |
---|
| 593 | * @ pid : process identifier. |
---|
| 594 | * @ trdid : thread identifier. |
---|
| 595 | * @ returns O if success / returns -1 if failure. |
---|
| 596 | *****************************************************************************************/ |
---|
| 597 | int sys_trace( uint32_t operation, |
---|
| 598 | pid_t pid, |
---|
| 599 | uint32_t trdid ); |
---|
[407] | 600 | |
---|
[421] | 601 | /****************************************************************************************** |
---|
| 602 | * [48] This function gives the process identified by the <pid> argument |
---|
| 603 | * the exclusive ownership of its TXT_TX terminal (put it in foreground). |
---|
| 604 | ****************************************************************************************** |
---|
| 605 | * @ pid : process identifier. |
---|
| 606 | * @ return 0 if success / return -1 if failure. |
---|
| 607 | *****************************************************************************************/ |
---|
| 608 | int sys_fg( pid_t pid ); |
---|
| 609 | |
---|
| 610 | |
---|
[16] | 611 | #endif // _SYSCALLS_H_ |
---|