1 | /* |
---|
2 | * syscalls.h - Kernel side services for syscall handling. |
---|
3 | * |
---|
4 | * Author Alain Greiner (2016,2017,2018) |
---|
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 | |
---|
24 | #ifndef _SYSCALLS_H_ |
---|
25 | #define _SYSCALLS_H_ |
---|
26 | |
---|
27 | #include <hal_kernel_types.h> |
---|
28 | #include <shared_syscalls.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 | |
---|
38 | /****************************************************************************************** |
---|
39 | * [0] This function terminates the execution of the calling user thread, |
---|
40 | * and makes the exit_value pointer available to any successful pthread_join() with the |
---|
41 | * terminating thread. |
---|
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. |
---|
46 | ****************************************************************************************** |
---|
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. |
---|
49 | *****************************************************************************************/ |
---|
50 | int sys_thread_exit( void * exit_value ); |
---|
51 | |
---|
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( void ); |
---|
61 | |
---|
62 | /****************************************************************************************** |
---|
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. |
---|
65 | ****************************************************************************************** |
---|
66 | * @ trdid_ptr : [out] pointer on buffer for created thread trdid. |
---|
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. |
---|
71 | *****************************************************************************************/ |
---|
72 | int sys_thread_create( trdid_t * trdid_ptr, |
---|
73 | struct pthread_attr_s * user_attr, |
---|
74 | void * start_func, |
---|
75 | void * start_args ); |
---|
76 | |
---|
77 | /****************************************************************************************** |
---|
78 | * [3] This blocking function suspend execution of the calling thread until completion |
---|
79 | * of another target thread identified by the <trdid> argument. |
---|
80 | * The target thread must be joinable (running in ATTACHED mode), and must be different |
---|
81 | * from the calling thread. |
---|
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. |
---|
84 | ****************************************************************************************** |
---|
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. |
---|
88 | *****************************************************************************************/ |
---|
89 | int sys_thread_join( trdid_t trdid, |
---|
90 | void ** exit_value ); |
---|
91 | |
---|
92 | /****************************************************************************************** |
---|
93 | * [4] This function detach a joinable thread. |
---|
94 | ****************************************************************************************** |
---|
95 | * @ trdid : thread identifier. |
---|
96 | * @ return 0 if success / return -1 if failure. |
---|
97 | *****************************************************************************************/ |
---|
98 | int sys_thread_detach( trdid_t trdid ); |
---|
99 | |
---|
100 | /****************************************************************************************** |
---|
101 | * [5] This function requests a target thread identified by its <trdid> argument |
---|
102 | * to be cancelled. It calls the thread_kill() function to block the target thread |
---|
103 | * on the THREAD_BLOCKED_GLOBAL condition, and to set the THREAD_FLAG_REQ_DELETE. |
---|
104 | * The thread will be detached from its process, and the memory allocated to the thread |
---|
105 | * descriptor will be released by the scheduler at the next scheduling point. |
---|
106 | ****************************************************************************************** |
---|
107 | * @ trdid : thread identifier. |
---|
108 | * @ return 0 if success / return -1 if illegal argument. |
---|
109 | *****************************************************************************************/ |
---|
110 | int sys_thread_cancel( trdid_t trdid ); |
---|
111 | |
---|
112 | /****************************************************************************************** |
---|
113 | * [6] This function implement all operations on a POSIX unnamed semaphore, |
---|
114 | * that can be shared by threads running in different clusters. |
---|
115 | * The kernel structure representing a remote semaphore is in the remote_sem.h file, |
---|
116 | * and the code implementing the operations is in the remore_sem.c file. |
---|
117 | ****************************************************************************************** |
---|
118 | * @ vaddr : semaphore virtual address in user space == identifier. |
---|
119 | * @ operation : SEM_INIT / SEM_DESTROY / SEM_GETVALUE / SEM_POST / SEM_WAIT. |
---|
120 | * @ init_value : initial semaphore value. |
---|
121 | * @ current_value : pointer on buffer for current semaphore value. |
---|
122 | * @ return 0 if success / return -1 if failure. |
---|
123 | *****************************************************************************************/ |
---|
124 | int sys_sem( void * vaddr, |
---|
125 | uint32_t operation, |
---|
126 | uint32_t init_value, |
---|
127 | uint32_t * current_value ); |
---|
128 | |
---|
129 | /****************************************************************************************** |
---|
130 | * [7] This function implement all operations on a POSIX condition variable. |
---|
131 | * The kernel structure representing a condvar is defined in the remote_condvar.h file, |
---|
132 | * The code implementing the operations is defined in the remote_condvar.c file. |
---|
133 | ****************************************************************************************** |
---|
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. |
---|
138 | *****************************************************************************************/ |
---|
139 | int sys_condvar( void * condvar, |
---|
140 | uint32_t operation, |
---|
141 | void * mutex ); |
---|
142 | |
---|
143 | /****************************************************************************************** |
---|
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. |
---|
147 | ****************************************************************************************** |
---|
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. |
---|
152 | *****************************************************************************************/ |
---|
153 | int sys_barrier( void * vaddr, |
---|
154 | uint32_t operation, |
---|
155 | uint32_t count ); |
---|
156 | |
---|
157 | /****************************************************************************************** |
---|
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. |
---|
161 | ****************************************************************************************** |
---|
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. |
---|
166 | *****************************************************************************************/ |
---|
167 | int sys_mutex( void * vaddr, |
---|
168 | uint32_t operation, |
---|
169 | uint32_t count ); |
---|
170 | |
---|
171 | /****************************************************************************************** |
---|
172 | * [10] This function causes the file named <old> to be renamed as <new>. |
---|
173 | * If new exists, it is first removed. Both old and new must be of the same type (both |
---|
174 | * must be either directories or non-directories) and must reside on the same file system. |
---|
175 | * It guarantees that an instance of <new> will always exist, even if the system should |
---|
176 | * crash in the middle of the operation. |
---|
177 | ****************************************************************************************** |
---|
178 | * @ old : old file name. |
---|
179 | * @ new : new file name. |
---|
180 | * @ return 0 if success / return -1 if failure. |
---|
181 | *****************************************************************************************/ |
---|
182 | int sys_rename( char *old, |
---|
183 | char *new ); |
---|
184 | |
---|
185 | /****************************************************************************************** |
---|
186 | * [11] This function remove an existing mapping defined by the <addr> and <size> |
---|
187 | * arguments in user space. |
---|
188 | ****************************************************************************************** |
---|
189 | * @ addr : base address in user space. |
---|
190 | * # size : number of bytes. |
---|
191 | * @ return 0 if success / return -1 if failure. |
---|
192 | *****************************************************************************************/ |
---|
193 | int sys_munmap( void * addr, |
---|
194 | uint32_t size ); |
---|
195 | |
---|
196 | /****************************************************************************************** |
---|
197 | * [12] This function open or create an open file descriptor. |
---|
198 | ****************************************************************************************** |
---|
199 | * @ pathname : pathname (can be relative or absolute). |
---|
200 | * @ flags : bit vector attributes (see in shared_fcntl.h file) |
---|
201 | * @ mode : access rights. |
---|
202 | * @ return file descriptor index in fd_array if success / return -1 if failure. |
---|
203 | *****************************************************************************************/ |
---|
204 | int sys_open( char * pathname, |
---|
205 | uint32_t flags, |
---|
206 | uint32_t mode ); |
---|
207 | |
---|
208 | /****************************************************************************************** |
---|
209 | * [13] This function map physical memory (or a file) in the calling thread virtual space. |
---|
210 | * The <attr> argument is a pointer on a structure for arguments (see shared_syscalls.h). |
---|
211 | * The user defined virtual address (MAP_FIXED flag) is not supported. |
---|
212 | * TODO : the access rights checking is not implemented yet [AG] |
---|
213 | * TODO : the Copy on Write for MAP_PRIVATE is not implemented yet [AG] |
---|
214 | ****************************************************************************************** |
---|
215 | * @ attr : pointer on attributes structure. |
---|
216 | * @ return 0 if success / return -1 if failure. |
---|
217 | *****************************************************************************************/ |
---|
218 | int sys_mmap( mmap_attr_t * attr ); |
---|
219 | |
---|
220 | /****************************************************************************************** |
---|
221 | * [14] This function read bytes from an open file identified by its file descriptor. |
---|
222 | * The file can be a regular file or character oriented device. |
---|
223 | * IRQs are enabled during this system call. |
---|
224 | ****************************************************************************************** |
---|
225 | * @ file_id : open file index in fd_array. |
---|
226 | * @ buf : buffer virtual address in user space. |
---|
227 | * @ count : number of bytes. |
---|
228 | * @ return number of bytes actually read if success / returns -1 if failure. |
---|
229 | *****************************************************************************************/ |
---|
230 | int sys_read( uint32_t file_id, |
---|
231 | void * buf, |
---|
232 | uint32_t count ); |
---|
233 | |
---|
234 | /****************************************************************************************** |
---|
235 | * [15] This function writes bytes to an open file identified by its file descriptor. |
---|
236 | * The file can be a regular file or character oriented device. |
---|
237 | * IRQs are enabled during this system call. |
---|
238 | ****************************************************************************************** |
---|
239 | * @ file_id : open file index in fd_array. |
---|
240 | * @ buf : buffer virtual address in user space. |
---|
241 | * @ count : number of bytes. |
---|
242 | * @ return number of bytes actually written if success / returns -1 if failure. |
---|
243 | *****************************************************************************************/ |
---|
244 | int sys_write( uint32_t file_id, |
---|
245 | void * buf, |
---|
246 | uint32_t count ); |
---|
247 | |
---|
248 | /****************************************************************************************** |
---|
249 | * [16] This function repositions the offset of the file descriptor identified by <file_id>, |
---|
250 | * according to the operation type defined by the <whence> argument. |
---|
251 | ****************************************************************************************** |
---|
252 | * @ file_id : open file index in fd_array. |
---|
253 | * @ offset : used to compute new offset value. |
---|
254 | * @ whence : operation type (see below). |
---|
255 | * @ return 0 if success / returns -1 if failure. |
---|
256 | *****************************************************************************************/ |
---|
257 | int sys_lseek( xptr_t file_id, |
---|
258 | uint32_t offset, |
---|
259 | uint32_t whence ); |
---|
260 | |
---|
261 | /****************************************************************************************** |
---|
262 | * [17] This function release the memory allocated for the file descriptor identified by |
---|
263 | * the <file_id> argument, and remove the fd array_entry in all copies of the process |
---|
264 | * descriptor. |
---|
265 | ****************************************************************************************** |
---|
266 | file_id : file descriptor index in fd_array. |
---|
267 | * @ return 0 if success / returns -1 if failure. |
---|
268 | *****************************************************************************************/ |
---|
269 | int sys_close( uint32_t file_id ); |
---|
270 | |
---|
271 | /****************************************************************************************** |
---|
272 | * [18] This function removes a directory entry identified by the <pathname> from the |
---|
273 | * directory, and decrement the link count of the file referenced by the link. |
---|
274 | * If the link count reduces to zero, and no process has the file open, then all resources |
---|
275 | * associated with the file are reclaimed. If one or more process have the file open when |
---|
276 | * the last link is removed, the link is removed, but the removal of the file is delayed |
---|
277 | * until all references to it have been closed. |
---|
278 | ****************************************************************************************** |
---|
279 | * @ pathname : pathname (can be relative or absolute). |
---|
280 | * @ return 0 if success / returns -1 if failure. |
---|
281 | *****************************************************************************************/ |
---|
282 | int sys_unlink( char * pathname ); |
---|
283 | |
---|
284 | /****************************************************************************************** |
---|
285 | * [19] This function creates in the calling thread cluster an unnamed pipe, and two |
---|
286 | * (read and write) file descriptors. |
---|
287 | * TODO not implemented yet [AG] |
---|
288 | ****************************************************************************************** |
---|
289 | * @ file_id[0] : [out] read only file descriptor index. |
---|
290 | * @ file_id[1] : [out] write only file descriptor index. |
---|
291 | * @ return 0 if success / return -1 if failure. |
---|
292 | *****************************************************************************************/ |
---|
293 | int sys_pipe( uint32_t file_id[2] ); |
---|
294 | |
---|
295 | /****************************************************************************************** |
---|
296 | * [20] This function change the current working directory in reference process descriptor. |
---|
297 | ****************************************************************************************** |
---|
298 | * @ pathname : pathname (can be relative or absolute). |
---|
299 | * @ return 0 if success / returns -1 if failure. |
---|
300 | *****************************************************************************************/ |
---|
301 | int sys_chdir( char * pathname ); |
---|
302 | |
---|
303 | /****************************************************************************************** |
---|
304 | * [21] This function implements the "mkdir" system call, creating a new directory in |
---|
305 | * the file system, as defined by the <pathname> argument, with the access permission |
---|
306 | * defined by the <rights> argument. All nodes but the last in the pathname must exist. |
---|
307 | * It can be called by any thread running in any cluster. |
---|
308 | ****************************************************************************************** |
---|
309 | * @ pathname : pathname defining the new directory location in file system. |
---|
310 | * @ rights : access rights (non used yet). |
---|
311 | * @ return 0 if success / return -1 if failure. |
---|
312 | *****************************************************************************************/ |
---|
313 | int sys_mkdir( char * pathname, |
---|
314 | uint32_t rights ); |
---|
315 | |
---|
316 | /****************************************************************************************** |
---|
317 | * [22] This function creates a named FIFO file in the calling thread cluster. |
---|
318 | * The associated read and write file descriptors mut be be explicitely created |
---|
319 | * using the sys_open() function. |
---|
320 | ****************************************************************************************** |
---|
321 | * @ pathname : pathname (can be relative or absolute). |
---|
322 | * @ mode : access rights (as defined in chmod). |
---|
323 | * @ return 0 if success / returns -1 if failure. |
---|
324 | *****************************************************************************************/ |
---|
325 | int sys_mkfifo( char * pathname, |
---|
326 | uint32_t mode ); |
---|
327 | |
---|
328 | /****************************************************************************************** |
---|
329 | * [23] This function open a directory, that must exist in the file system, returning |
---|
330 | * a DIR pointer on the dirent array in user space. |
---|
331 | ****************************************************************************************** |
---|
332 | * @ pathname : [in] pathname (can be relative or absolute). |
---|
333 | * @ dirp : [out] buffer for pointer on user directory (DIR). |
---|
334 | * @ return 0 if success / returns -1 if failure. |
---|
335 | *****************************************************************************************/ |
---|
336 | int sys_opendir( char * pathname, |
---|
337 | DIR ** dirp ); |
---|
338 | |
---|
339 | /****************************************************************************************** |
---|
340 | * [24] This function returns an user pointer on the dirent structure describing the |
---|
341 | * next directory entry in the directory identified by the <dirp> argument. |
---|
342 | ****************************************************************************************** |
---|
343 | * @ dirp : [in] user pointer on dirent array identifying the open directory. |
---|
344 | * @ buffer : [out] pointer on user buffer for a pointer on dirent in user space. |
---|
345 | * @ return O if success / returns -1 if failure. |
---|
346 | *****************************************************************************************/ |
---|
347 | int sys_readdir( DIR * dirp, |
---|
348 | struct dirent ** buffer ); |
---|
349 | |
---|
350 | /****************************************************************************************** |
---|
351 | * [25] This function closes the directory identified by the <dirp> argument, and releases |
---|
352 | * all structures associated with the <dirp> pointer. |
---|
353 | ****************************************************************************************** |
---|
354 | * @ dirp : [in] user pointer on dirent array identifying the open directory. |
---|
355 | * @ return 0 if success / returns -1 if failure. |
---|
356 | *****************************************************************************************/ |
---|
357 | int sys_closedir( DIR * dirp ); |
---|
358 | |
---|
359 | /****************************************************************************************** |
---|
360 | * [26] This function returns the pathname of the current working directory. |
---|
361 | ****************************************************************************************** |
---|
362 | * buf : buffer addres in user space. |
---|
363 | * nbytes : user buffer size in bytes. |
---|
364 | * @ return 0 if success / returns -1 if failure. |
---|
365 | *****************************************************************************************/ |
---|
366 | int sys_getcwd( char * buf, |
---|
367 | uint32_t nbytes ); |
---|
368 | |
---|
369 | /****************************************************************************************** |
---|
370 | * [27] This function tests whether a given file descriptor dentified by the <file_id> |
---|
371 | * argument is an open file descriptor referring to a terminal. |
---|
372 | ****************************************************************************************** |
---|
373 | * @ file_id : file descriptor index |
---|
374 | * @ return 1 if it is a TXT device / return 0 if it is not a TXT device. |
---|
375 | *****************************************************************************************/ |
---|
376 | int sys_isatty( uint32_t file_id ); |
---|
377 | |
---|
378 | /****************************************************************************************** |
---|
379 | * [28] This function forces the calling thread to sleep, for a fixed number of cycles. |
---|
380 | ****************************************************************************************** |
---|
381 | * cycles : number of cycles. |
---|
382 | *****************************************************************************************/ |
---|
383 | int sys_alarm( uint32_t cycles ); |
---|
384 | |
---|
385 | /****************************************************************************************** |
---|
386 | * [29] This function removes a directory file whose name is given by <pathname>. |
---|
387 | * The directory must not have any entries other than `.' and `..'. |
---|
388 | ****************************************************************************************** |
---|
389 | * @ pathname : pathname (can be relative or absolute). |
---|
390 | * @ return 0 if success / returns -1 if failure. |
---|
391 | *****************************************************************************************/ |
---|
392 | int sys_rmdir( char * pathname ); |
---|
393 | |
---|
394 | /****************************************************************************************** |
---|
395 | * [30] This function implement the operations related to User Thread Local Storage. |
---|
396 | * It is actually implemented as an uint32_t variable in the thread descriptor. |
---|
397 | ****************************************************************************************** |
---|
398 | * @ operation : UTLS operation type as defined below. |
---|
399 | * @ value : argument value for the UTLS_SET operation. |
---|
400 | * @ return value for the UTLS_GET and UTLS_GET_ERRNO / return -1 if failure. |
---|
401 | *****************************************************************************************/ |
---|
402 | int sys_utls( uint32_t operation, |
---|
403 | uint32_t value ); |
---|
404 | |
---|
405 | /****************************************************************************************** |
---|
406 | * [31] This function change the acces rights for the file/dir identified by the |
---|
407 | * pathname argument. |
---|
408 | ****************************************************************************************** |
---|
409 | * @ pathname : pathname (can be relative or absolute). |
---|
410 | * @ rights : acces rights. |
---|
411 | * @ return 0 if success / returns -1 if failure. |
---|
412 | *****************************************************************************************/ |
---|
413 | int sys_chmod( char * pathname, |
---|
414 | uint32_t rights ); |
---|
415 | |
---|
416 | /****************************************************************************************** |
---|
417 | * [32] This function associate a specific signal handler to a given signal type. |
---|
418 | * The handlers for the SIGKILL and SIGSTOP signals cannot be redefined. |
---|
419 | ****************************************************************************************** |
---|
420 | * @ sig_id : index defining signal type (from 1 to 31). |
---|
421 | * @ handler : pointer on fonction implementing the specific handler. |
---|
422 | * @ return 0 if success / returns -1 if failure. |
---|
423 | *****************************************************************************************/ |
---|
424 | int sys_signal( uint32_t sig_id, |
---|
425 | void * handler ); |
---|
426 | |
---|
427 | /****************************************************************************************** |
---|
428 | * [33] This function returns in the structure <tv>, defined in the time.h file, |
---|
429 | * the current time (in seconds & micro-seconds). |
---|
430 | * It is computed from the calling core descriptor. |
---|
431 | * The timezone is not supported. |
---|
432 | ****************************************************************************************** |
---|
433 | * @ tv : pointer on the timeval structure. |
---|
434 | * @ tz : pointer on the timezone structure : must be NULL. |
---|
435 | * @ return 0 if success / returns -1 if failure. |
---|
436 | *****************************************************************************************/ |
---|
437 | int sys_timeofday( struct timeval * tv, |
---|
438 | struct timezone * tz ); |
---|
439 | |
---|
440 | /****************************************************************************************** |
---|
441 | * [34] This function implements the "kill" system call on the kernel side. |
---|
442 | * It register the signal defined by the <sig_id> argument in all thread descriptors |
---|
443 | * of a target process identified by the <pid> argument. This is done in all clusters |
---|
444 | * containing threads for the target process. |
---|
445 | * It can be executed by any thread running in any cluster, as this function uses |
---|
446 | * remote access to traverse the list of process copies stored in the owner cluster, |
---|
447 | * and the RPC_SIGNAL_RISE to signal the remote threads. |
---|
448 | * This function does nothing for (sig_id == 0). This can be used to check process pid. |
---|
449 | * TODO : This first implementation supports only SIGKILL / SIGSTOP / SIGCONT values. |
---|
450 | ****************************************************************************************** |
---|
451 | * @ pid : target process identifier. |
---|
452 | * @ sig_id : index defining the signal type. |
---|
453 | * @ return 0 if success / returns -1 if failure. |
---|
454 | *****************************************************************************************/ |
---|
455 | int sys_kill( pid_t pid, |
---|
456 | uint32_t sig_id ); |
---|
457 | |
---|
458 | /****************************************************************************************** |
---|
459 | * [35] This function implements the "getpid" system call on the kernel side. |
---|
460 | ****************************************************************************************** |
---|
461 | * @ returns the process PID for the calling thread. |
---|
462 | *****************************************************************************************/ |
---|
463 | int sys_getpid( void ); |
---|
464 | |
---|
465 | /****************************************************************************************** |
---|
466 | * [36] This function implement the "fork" system call on the kernel side. |
---|
467 | * The calling process descriptor (parent process), and the associated thread descriptor |
---|
468 | * are replicated in a - likely - remote cluster, that becomes the child process owner. |
---|
469 | * The child process get a new PID, and is linked to the parent PID. The child process |
---|
470 | * inherit from its parent the memory image, and all open files (including the TXT). |
---|
471 | * The child process becomes the TXT terminal owner. |
---|
472 | * The target cluster depends on the "fork_user" flag and "fork_cxy" variable that can be |
---|
473 | * stored in the calling thread descriptor by the specific fork_place() system call. |
---|
474 | * If not, the kernel function makes a query to the DQDT to select the target cluster. |
---|
475 | ****************************************************************************************** |
---|
476 | * @ if success, returns child process PID to parent, and return O to child. |
---|
477 | * @ if failure, returns -1 to parent / no child process is created. |
---|
478 | *****************************************************************************************/ |
---|
479 | int sys_fork( void ); |
---|
480 | |
---|
481 | /****************************************************************************************** |
---|
482 | * [37] This function implement the "exec" system call on the kernel side. |
---|
483 | * It creates, in the same cluster as the calling thread, a new process descriptor, |
---|
484 | * and a new associated main thread descriptor, executing a new memory image defined |
---|
485 | * by the <filename> argument. This new process inherit from the old process the PID |
---|
486 | * and the PPID, as well as all open files (including the TXT). |
---|
487 | * The old process descriptor, and all its threads are blocked, and marked for deletion. |
---|
488 | * Therefore the exec syscall does not return to the calling thread in case of success. |
---|
489 | * This function build an exec_info_t structure containing the new process arguments, |
---|
490 | * as defined by the <arv> argument, and the new process environment variables, |
---|
491 | * as defined by the <envp> argument. |
---|
492 | * TODO : the <argv> and <envp> arguments are not supported yet (both must be NULL). |
---|
493 | ****************************************************************************************** |
---|
494 | * @ filename : string pointer on .elf filename (pointer in user space) |
---|
495 | * @ argv : array of strings on process arguments (pointers in user space) |
---|
496 | * @ envp : array of strings on environment variables (pointers in user space) |
---|
497 | * @ does not return if success / returns -1 if failure. |
---|
498 | *****************************************************************************************/ |
---|
499 | int sys_exec( char * filename, |
---|
500 | char ** argv, |
---|
501 | char ** envp ); |
---|
502 | |
---|
503 | /****************************************************************************************** |
---|
504 | * [38] This function returns in the <stat> structure, defined in the "shared_syscalls.h" |
---|
505 | * file, various informations on the file/directory identified by the <pathname> argument. |
---|
506 | * TODO only the <st_ino>, <st_mode>,<st_uid>,<st_gid>,<st_size> are set. |
---|
507 | ****************************************************************************************** |
---|
508 | * @ pathname : user pointer on file pathname. |
---|
509 | * @ stat : user pointer on the stat structure. |
---|
510 | * @ returns O if success / returns -1 if failure. |
---|
511 | *****************************************************************************************/ |
---|
512 | int sys_stat( char * pathname, |
---|
513 | struct stat * stat ); |
---|
514 | |
---|
515 | /****************************************************************************************** |
---|
516 | * [39] This blocking function waits a change of a child process state, that can be: |
---|
517 | * - a termination of child following a process_make_exit(). |
---|
518 | * - a termination of child following a process_make_kill(). |
---|
519 | * - a blocking of child following a SIGSTOP signal. |
---|
520 | * In case of a multi-thread process, this function must be called by the main thread |
---|
521 | * runningin the reference cluster. |
---|
522 | * When a change has been observed, it returns the PID of the child process, and stores |
---|
523 | * in the <status> argument relevant information on the child state change. |
---|
524 | * The following macros can be used to extract information from status: |
---|
525 | * - WIFEXITED(status) : is true if the child process terminated with an exit(). |
---|
526 | * - WIFSIGNALED(status) : is true if the child process killed by a signal. |
---|
527 | * - WIFSTOPPED(status) : is true if the child process is stopped by a signal. |
---|
528 | * - WEXITSTATUS(status) : returns the low-order 8 bits of the exit() argument. |
---|
529 | * If a parent process terminates without waiting for all child processes to terminate, |
---|
530 | * the remaining child processes are attached to the init process. |
---|
531 | * WARNING: negative values for the <pid> argument are not supported. |
---|
532 | ****************************************************************************************** |
---|
533 | * @ searched_pid : searched child process identifier. |
---|
534 | * @ status : [out] child termination status. |
---|
535 | * @ return child PID if success / return -1 if searched PID not found. |
---|
536 | *****************************************************************************************/ |
---|
537 | int sys_wait( uint32_t * status ); |
---|
538 | |
---|
539 | /****************************************************************************************** |
---|
540 | * [40] This function implement the non-standard get_config() syscall. |
---|
541 | * It returns in <x_size>, <y_size>, <ncores> the hardware platform parameters. |
---|
542 | ****************************************************************************************** |
---|
543 | * @ x_size : [out] number of clusters in a row. |
---|
544 | * @ y_size : [out] number of clusters in a column. |
---|
545 | * @ ncores : [out] number of cores per cluster. |
---|
546 | * @ return 0 if success / return -1 if illegal arguments |
---|
547 | *****************************************************************************************/ |
---|
548 | int sys_get_config( uint32_t * x_size, |
---|
549 | uint32_t * y_size, |
---|
550 | uint32_t * ncores ); |
---|
551 | |
---|
552 | /****************************************************************************************** |
---|
553 | * [41] This function implements the non-standard get_core() syscall. |
---|
554 | * It returns in <cxy> and <lid> the calling core cluster and local index. |
---|
555 | ****************************************************************************************** |
---|
556 | * @ cxy : [out] cluster identifier (fixed format) |
---|
557 | * @ lid : [out] core local index in cluster. |
---|
558 | * @ return 0 if success / return -1 if illegal arguments |
---|
559 | *****************************************************************************************/ |
---|
560 | int sys_get_core( uint32_t * cxy, |
---|
561 | uint32_t * lid ); |
---|
562 | |
---|
563 | /****************************************************************************************** |
---|
564 | * [42] This function implements the non-standard get_cycle() syscall. |
---|
565 | * It returns in a 64 bits user buffer the calling core cycles count. |
---|
566 | * It uses both the hardware register and the core descriptor cycles count to take |
---|
567 | * into account a possible harware register overflow in 32 bits architectures. |
---|
568 | ****************************************************************************************** |
---|
569 | * cycle : [out] address of buffer in user space. |
---|
570 | * @ return 0 if success / return -1 if illegal arguments |
---|
571 | *****************************************************************************************/ |
---|
572 | int sys_get_cycle( uint64_t * cycle ); |
---|
573 | |
---|
574 | /****************************************************************************************** |
---|
575 | * [43] This debug function displays on the kernel terminal TXT0 an user defined string, |
---|
576 | * or the current state of a kernel structure, identified by the <type> argument. |
---|
577 | * The <arg0>, <arg1>, and <arg2> arguments depends on the structure type: |
---|
578 | * - DISPLAY_STRING : an user defined string |
---|
579 | * - DISPLAY_VMM : VSL and GPT for a process identified by <pid>. |
---|
580 | * - DISPLAY_SCHED : all threads allocated to a scheduler <cxy> & <lid>. |
---|
581 | * - DISPLAY_CLUSTER_PROCESS : all processes registered in a cluster identified by <cxy>. |
---|
582 | * - DISPLAY_TXT_PROCESS : all processes registered in a cluster identified by <cxy>. |
---|
583 | * - DISPLAY_VFS : all files registered in the VFS cache. |
---|
584 | * - DISPLAY_CHDEV : all registered channel devices. |
---|
585 | * - DISPLAY_DQDT : all DQDT nodes curren values. |
---|
586 | * - DISPLAY_BUSYLOCKS : all busylocks taken by one thread. |
---|
587 | * - DISPLAY_MAPPER : one page of a given mapper. |
---|
588 | ****************************************************************************************** |
---|
589 | * type : [in] type of display |
---|
590 | * arg0 : [in] type dependant argument. |
---|
591 | * arg1 : [in] type dependant argument. |
---|
592 | * arg2 : [in] type dependant argument. |
---|
593 | * @ return 0 if success / return -1 if illegal arguments |
---|
594 | *****************************************************************************************/ |
---|
595 | int sys_display( reg_t type, |
---|
596 | reg_t arg0, |
---|
597 | reg_t arg1, |
---|
598 | reg_t arg2 ); |
---|
599 | |
---|
600 | /****************************************************************************************** |
---|
601 | * [44] This function implements the non-standard place_fork() syscall. |
---|
602 | * It can be used to specify the target cluster <cxy> for a new process created |
---|
603 | * by a subsequent fork() syscall. |
---|
604 | * WARNING: it must be called before each fork() syscall, as the placement specification |
---|
605 | * is reset by the fork syscall. |
---|
606 | ****************************************************************************************** |
---|
607 | * @ cxy : cluster identifier. |
---|
608 | * @ return 0 if success / return -1 if failure. |
---|
609 | *****************************************************************************************/ |
---|
610 | int sys_place_fork( uint32_t cxy ); |
---|
611 | |
---|
612 | /****************************************************************************************** |
---|
613 | * [45] This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition, |
---|
614 | * and deschedule. |
---|
615 | ****************************************************************************************** |
---|
616 | * @ return 0 if success / returns -1 if failure. |
---|
617 | *****************************************************************************************/ |
---|
618 | int sys_thread_sleep( void ); |
---|
619 | |
---|
620 | /****************************************************************************************** |
---|
621 | * [46] This function unblock the thread identified by its <trdid> from the |
---|
622 | * THREAD_BLOCKED_GLOBAL condition. |
---|
623 | ****************************************************************************************** |
---|
624 | * @ trdid : target thread identifier. |
---|
625 | * @ return 0 if success / return -1 if failure. |
---|
626 | *****************************************************************************************/ |
---|
627 | int sys_thread_wakeup( trdid_t trdid ); |
---|
628 | |
---|
629 | /****************************************************************************************** |
---|
630 | * [47] This debug function is used to activate / desactivate the context switches trace |
---|
631 | * for a core identified by the <cxy> and <lid> arguments. |
---|
632 | * It can be called by any other thread in the same process. |
---|
633 | ****************************************************************************************** |
---|
634 | * @ active : activate trace if true / desactivate trace if false. |
---|
635 | * @ cxy : cluster identifier. |
---|
636 | * @ lid : core local index. |
---|
637 | * @ returns O if success / returns -1 if failure. |
---|
638 | *****************************************************************************************/ |
---|
639 | int sys_trace( bool_t active, |
---|
640 | cxy_t cxy, |
---|
641 | lid_t lid ); |
---|
642 | |
---|
643 | /****************************************************************************************** |
---|
644 | * [48] This function gives the process identified by the <pid> argument |
---|
645 | * the exclusive ownership of its TXT_TX terminal (put it in foreground). |
---|
646 | ****************************************************************************************** |
---|
647 | * @ pid : process identifier. |
---|
648 | * @ return 0 if success / return -1 if failure. |
---|
649 | *****************************************************************************************/ |
---|
650 | int sys_fg( pid_t pid ); |
---|
651 | |
---|
652 | /****************************************************************************************** |
---|
653 | * [49] This function returns a non-zero value in the <is_fg> buffer when the process |
---|
654 | * identified by the <pid> argument is the current TXT owner. |
---|
655 | ****************************************************************************************** |
---|
656 | * @ pid : process identifier. |
---|
657 | * @ is_fg : pointer on buffer. |
---|
658 | * @ return 0 if success / return -1 if failure. |
---|
659 | *****************************************************************************************/ |
---|
660 | int sys_is_fg( pid_t pid, |
---|
661 | uint32_t * is_fg ); |
---|
662 | |
---|
663 | /****************************************************************************************** |
---|
664 | * [50] This function implements the exit system call terminating a POSIX process. |
---|
665 | * It can be called by any thread running in any cluster. |
---|
666 | * It uses both remote accesses to access the owner process descriptor, and the |
---|
667 | * RPC_PROCESS_SIGACTION to delete remote process and thread descriptors. |
---|
668 | * In the present implementation, this function implements actually the _exit(): |
---|
669 | * - it does not flush open output streams. |
---|
670 | * - it does not close open streams. |
---|
671 | ****************************************************************************************** |
---|
672 | * @ status : terminaison status. |
---|
673 | *****************************************************************************************/ |
---|
674 | int sys_exit( uint32_t status ); |
---|
675 | |
---|
676 | #endif // _SYSCALLS_H_ |
---|