source: trunk/kernel/syscalls/shared_syscalls.h @ 440

Last change on this file since 440 was 437, checked in by alain, 6 years ago

Fix various bugs

File size: 17.7 KB
Line 
1/*
2 * syscalls.h - Shared Kernel/User informations for syscalls.
3 *
4 * Author     Alain Greiner (2016,2017)
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 _SHARED_SYSCALLS_H_
25#define _SHARED_SYSCALLS_H_
26
27/******************************************************************************************
28 * This enum defines the mnemonics for the syscall indexes.
29 * It must be kept consistent with the array defined in do_syscalls.c
30 *****************************************************************************************/
31
32enum
33{
34        SYS_THREAD_EXIT    = 0,
35        SYS_THREAD_YIELD   = 1,
36        SYS_THREAD_CREATE  = 2,
37        SYS_THREAD_JOIN    = 3,
38        SYS_THREAD_DETACH  = 4,
39        SYS_THREAD_CANCEL  = 5,
40        SYS_SEM            = 6,
41        SYS_CONDVAR        = 7,
42        SYS_BARRIER        = 8,
43        SYS_MUTEX          = 9,
44
45    SYS_EXIT           = 10,
46    SYS_MUNMAP         = 11,
47        SYS_OPEN           = 12,
48        SYS_MMAP           = 13,
49        SYS_READ           = 14,
50        SYS_WRITE          = 15,
51        SYS_LSEEK          = 16,
52        SYS_CLOSE          = 17,
53        SYS_UNLINK         = 18,   
54        SYS_PIPE           = 19,
55
56        SYS_CHDIR          = 20,
57        SYS_MKDIR          = 21,
58        SYS_MKFIFO         = 22,   
59        SYS_OPENDIR        = 23,
60        SYS_READDIR        = 24,
61        SYS_CLOSEDIR       = 25,
62        SYS_GETCWD         = 26,
63        SYS_ISATTY         = 27, 
64        SYS_ALARM          = 28,   
65        SYS_RMDIR          = 29,
66
67        SYS_UTLS           = 30, 
68        SYS_CHMOD          = 31,
69        SYS_SIGNAL         = 32,
70        SYS_TIMEOFDAY      = 33,
71        SYS_KILL           = 34,
72        SYS_GETPID         = 35,
73        SYS_FORK           = 36,
74        SYS_EXEC           = 37,
75        SYS_STAT           = 38,     
76        SYS_WAIT           = 39,
77
78    SYS_GET_CONFIG     = 40,
79    SYS_GET_CORE       = 41,
80    SYS_GET_CYCLE      = 42,
81    SYS_DISPLAY        = 43,
82    SYS_UNDEFINED_44   = 44,   ///
83        SYS_THREAD_SLEEP   = 45,
84        SYS_THREAD_WAKEUP  = 46,
85    SYS_TRACE          = 47,
86    SYS_FG             = 48,
87    SYS_UNDEFINED_49   = 49,   ///
88
89        SYSCALLS_NR        = 50,
90};
91
92/*******************************************************************************************
93 * This defines the signal type mnemonics for the kill() syscall.
94 * WARNING : Only the three SIGKILL / SIGSTOP / SIGCONT are supported (december 2017)
95 ******************************************************************************************/
96
97#define SIGHUP     1       /*! hangup                                                     */
98#define SIGINT     2       /*! interrupt                                                  */
99#define SIGQUIT    3       /*! quit                                                       */
100#define SIGILL     4       /*! illegal instruction (not reset when caught)                */
101#define SIGTRAP    5       /*! trace trap (not reset when caught)                         */
102#define SIGABRT    6       /*! used by abort, replace SIGIOT in the future                */
103#define SIGEMT     7       /*! EMT instruction                                            */
104#define SIGFPE     8       /*! floating point exception                                   */
105#define SIGKILL    9       /*! kill (cannot be caught or ignored)                         */
106#define SIGBUS     10      /*! bus error                                                  */
107#define SIGSEGV    11      /*! segmentation violation                                     */
108#define SIGSYS     12      /*! bad argument to system call                                */
109#define SIGPIPE    13      /*! write on a pipe with no one to read it                     */
110#define SIGALRM    14      /*! alarm clock                                                */
111#define SIGTERM    15      /*! software termination signal from kill                      */
112#define SIGURG     16      /*! urgent condition on IO channel                             */
113#define SIGSTOP    17      /*! sendable stop signal not from tty                          */
114#define SIGTSTP    18      /*! stop signal from tty                                       */
115#define SIGCONT    19      /*! continue a stopped process                                 */
116#define SIGCHLD    20      /*! to parent on child stop or exit                            */
117#define SIGTTIN    21      /*! to readers pgrp upon background tty read                   */
118#define SIGTTOU    22      /*! like TTIN for output if (tp->t_local&LTOSTOP)              */
119#define SIGIO      23      /*! input/output possible signal                               */
120#define SIGXCPU    24      /*! exceeded CPU time limit                                    */
121#define SIGXFSZ    25      /*! exceeded file size limit                                   */
122#define SIGVTALRM  26      /*! virtual time alarm                                         */
123#define SIGPROF    27      /*! profiling time alarm                                       */
124#define SIGWINCH   28      /*! window changed                                             */
125#define SIGLOST    29      /*! resource lost (eg, record-lock lost)                       */
126#define SIGUSR1    30      /*! user defined signal 1                                      */
127#define SIGUSR2    31      /*! user defined signal 2                                      */
128
129/*******************************************************************************************
130 * This enum defines the supported terminaison status values for the exit() syscall.
131 ******************************************************************************************/
132
133typedef enum
134{
135        EXIT_SUCCESS,
136        EXIT_FAILURE,
137} 
138exit_statut_t;
139
140/*******************************************************************************************
141 * These typedef define the POSIX thread related types.
142 ******************************************************************************************/
143
144typedef unsigned int      sem_t;
145typedef unsigned int      pthread_cond_t;
146typedef unsigned int      pthread_condattr_t;
147typedef unsigned int      pthread_rwlock_t;
148typedef unsigned int      pthread_rwlockattr_t;
149typedef unsigned int      pthread_key_t;
150
151/*******************************************************************************************
152 * This structure and enum define the attributes for the "pthread_create" syscall.
153 ******************************************************************************************/
154
155typedef unsigned int  pthread_t;               
156
157typedef struct pthread_attr_s
158{
159        unsigned int      attributes;      /*! user defined attributes bit vector             */
160        unsigned int      cxy;             /*! target cluster identifier                      */
161        unsigned int      lid;             /*! target core local index                        */
162}
163pthread_attr_t;
164
165enum
166{
167    PT_ATTR_DETACH          = 0x0001,  /*! user defined not joinable                      */
168    PT_ATTR_CLUSTER_DEFINED = 0x0002,  /*! user defined target cluster                    */
169    PT_ATTR_CORE_DEFINED    = 0x0004,  /*! user defined core index in cluster             */
170};
171
172/*******************************************************************************************
173 * This enum defines the operation mnemonics for operations on POSIX unnamed semaphores.
174 ******************************************************************************************/
175
176typedef enum
177{
178        SEM_INIT,
179        SEM_DESTROY,
180        SEM_GETVALUE,
181        SEM_WAIT,
182        SEM_POST,
183} 
184sem_operation_t;
185
186/*******************************************************************************************
187 * This enum defines the operation mnemonics for operations on POSIX condition variables.
188 ******************************************************************************************/
189
190typedef enum
191{
192        CONDVAR_INIT,
193        CONDVAR_DESTROY,
194    CONDVAR_WAIT,
195    CONDVAR_SIGNAL,
196    CONDVAR_BROADCAST,
197} 
198condvar_operation_t;
199
200/*******************************************************************************************
201 * This enum defines the operation mnemonics for operations on POSIX barriers.
202 ******************************************************************************************/
203
204typedef enum
205{
206        BARRIER_INIT,
207        BARRIER_DESTROY,
208        BARRIER_WAIT,
209} 
210barrier_operation_t;
211
212/*******************************************************************************************
213 * This enum defines the operation mnemonics for operations on POSIX mutex.
214 ******************************************************************************************/
215
216typedef enum
217{
218        MUTEX_INIT,
219        MUTEX_DESTROY,
220        MUTEX_LOCK,
221        MUTEX_UNLOCK,
222} 
223mutex_operation_t;
224
225/*******************************************************************************************
226 * This enum defines the attributes bit-vector for an "open" syscall.
227 ******************************************************************************************/
228
229typedef enum
230{
231    O_RDONLY   = 0x0010000,    /*! open file in read-only mode                            */
232    O_WRONLY   = 0x0020000,    /*! open file in write-only mode                           */
233    O_RDWR     = 0x0030000,    /*! open file in read/write mode                           */
234    O_NONBLOCK = 0x0040000,    /*! do not block if data non available                     */
235    O_APPEND   = 0x0080000,    /*! append on each write                                   */
236    O_CREAT    = 0x0100000,    /*! create file if it does not exist                       */
237    O_TRUNC    = 0x0200000,    /*! file length is forced to 0                             */
238    O_EXCL     = 0x0400000,    /*! error if VFS_O_CREAT and file exist                    */
239    O_SYNC         = 0x0800000,    /*! synchronize File System on each write                  */
240    O_CLOEXEC  = 0x1000000,    /*! set the close-on-exec flag in file descriptor          */
241    O_DIR      = 0x2000000,    /*! new file descriptor is for a directory                 */
242}
243open_attr_t;
244
245/*******************************************************************************************
246 * This structure contains the arguments passed to the "mmap" syscall.
247 ******************************************************************************************/
248
249#define      MAP_FAILED  0
250
251typedef enum
252{
253    PROT_NONE   = 0x0,         /*! no access                                              */
254    PROT_EXEC   = 0x1,         /*! executable                                             */
255    PROT_WRITE  = 0x2,         /*! writable                                               */
256    PROT_READ   = 0x4,         /*! readable                                               */
257}
258mmap_prot_t;
259
260typedef enum
261{
262    MAP_FILE    = 0x00000000,  /*! map an open file defined by its fdid                   */ 
263    MAP_ANON    = 0x00000001,  /*! map an anonymous vseg in local cluster                 */
264    MAP_REMOTE  = 0x00000002,  /*! map an anonymous vseg in remote cluster (cxy == fdid)  */
265    MAP_PRIVATE = 0x00000010,  /*!                                                        */
266    MAP_SHARED  = 0x00000020,  /*!                                                        */
267    MAP_FIXED   = 0x00000100,  /*! non supported                                          */
268}
269mmap_flags_t;
270
271typedef struct mmap_attr_s
272{
273        void         * addr;       /*! requested virtual address (unused : should be NULL)    */
274        unsigned int   length;     /*! requested vseg size (bytes)                            */
275        unsigned int   prot;       /*! access modes                                           */
276        unsigned int   flags;      /*! MAP_FILE / MAP_ANON / MAP_PRIVATE / MAP_SHARED         */
277        unsigned int   fdid;       /*! file descriptor index (if MAP_FILE)                    */
278        unsigned int   offset;     /*! file offset (if MAP_FILE)                              */
279}
280mmap_attr_t;
281
282/*******************************************************************************************
283 * This enum defines the operation mnemonics for the "lseek" syscall.
284 ******************************************************************************************/
285
286typedef enum
287{
288    SEEK_SET  = 0,             /*! new_offset <= offset                                   */
289    SEEK_CUR  = 1,             /*! new_offset <= current_offset + offset                  */
290    SEEK_END  = 2,             /*! new_offset <= current_size + offset                    */
291}
292lseek_operation_t;
293
294/*******************************************************************************************
295 * This enum defines the operation mnemonics for the "utls" syscall (Thread Local Storage).
296 ******************************************************************************************/
297
298typedef enum
299{
300    UTLS_SET       = 1,
301    UTLS_GET       = 2,
302    UTLS_GET_ERRNO = 3,
303}
304utls_operation_t;
305
306/*******************************************************************************************
307 * This enum defines the operation mnemonics for the "trace" syscall.
308 ******************************************************************************************/
309
310typedef enum
311{
312    TRACE_ON       = 0,
313    TRACE_OFF      = 1,
314}
315trace_operation_t;
316
317/*******************************************************************************************
318 * This enum defines the type of structure for the "display" syscall.
319 ******************************************************************************************/
320
321typedef enum
322{
323    DISPLAY_STRING            = 0,
324    DISPLAY_VMM               = 1,
325    DISPLAY_SCHED             = 2,
326    DISPLAY_CLUSTER_PROCESSES = 3,
327    DISPLAY_VFS               = 4,
328    DISPLAY_CHDEV             = 5,
329    DISPLAY_TXT_PROCESSES     = 6,
330}
331display_type_t;
332
333/******************************************************************************************
334 * This structure define the informations associated to a file descriptor,
335 * returned to user space by the stat() system call.
336 *****************************************************************************************/
337
338typedef struct stat
339{
340        unsigned int    dev;        /*! ID of device containing file                             */
341        unsigned int    inum;       /*! inode number                                             */
342        unsigned int    mode;       /*! protection                                               */
343        unsigned int    nlink;      /*! number of hard links                                     */
344        unsigned int    uid;        /*! user ID of owner                                         */
345        unsigned int    gid;        /*! group ID of owner                                        */
346        unsigned int    rdev;       /*! device ID (if special file)                              */
347        unsigned int    size;       /*! total size, in bytes                                     */
348        unsigned int    blksize;    /*! blocksize for file system I/O                            */
349        unsigned int    blocks;     /*! number of 512B blocks allocated                          */
350}
351stat_t;
352
353/*******************************************************************************************
354 * These two structure defines the informations returned to user by the opendir()
355 * function, used by the readdir() function, and released by the closedir() function.
356 * - "DIR" describes the complete directory.
357 * - "dirent" describes one directory entry.
358 ******************************************************************************************/
359
360#define DIRENT_NAME_MAX_LENGTH  56
361#define DIRENT_MAX_NUMBER       63
362
363struct dirent
364{
365    unsigned int   inum;                                /*! inode identifier              */
366    unsigned int   type;                                /*! inode type                    */
367    char           name[DIRENT_NAME_MAX_LENGTH];        /*! directory entry name          */
368};
369
370typedef struct user_directory
371{
372    struct dirent   entry[DIRENT_MAX_NUMBER];
373    unsigned int    current;
374}
375DIR;
376
377/*******************************************************************************************
378 * These two structure are used by the gettimeofday() function.
379 ******************************************************************************************/
380
381struct timeval
382{
383    unsigned int tv_sec;                    /*! seconds since Jan. 1, 1970                */
384    unsigned int tv_usec;                   /*! and microseconds                          */
385};
386
387struct timezone
388{
389    int          tz_minuteswest;            /*! of Greenwich                              */
390    int          tz_dsttime;                /*! type of dst correction to apply           */
391};
392
393
394/*********************************************************************************************
395 * These macros can be used by the parent process to analyze a child process
396 * termination status, as returned by the wait() syscall.
397 * The termination state is a 32 bits word:
398 * - the 8 LSB bits contain the user defined exit status
399 * - the 24 other bits contain the flags defined below
400 ********************************************************************************************/
401
402#define PROCESS_TERM_STOP  0x100            /*! process received a SIGSTOP signal           */
403#define PROCESS_TERM_KILL  0x200            /*! process killed by a SIGKILL signal          */
404#define PROCESS_TERM_EXIT  0x400            /*! process terminated by a sys_exit()          */
405#define PROCESS_TERM_WAIT  0x800            /*! parent process executed a sys_wait()        */
406
407#define WIFEXITED( status )       (status & PROCESS_TERM_EXIT)
408#define WIFSIGNALED( status )     (status & PROCESS_TERM_KILL)
409#define WIFSTOPPED( status )      (status & PROCESS_TERM_STOP)
410#define WEXITSTATUS( status )     (status & 0xFF)
411
412
413#endif  // _SHARED_SYSCALLS_H_
Note: See TracBrowser for help on using the repository browser.