source: trunk/libs/mini-libc/unistd.h @ 522

Last change on this file since 522 was 476, checked in by viala@…, 6 years ago

[mini-libc] Add void type to function prototypes with no parameter

File size: 11.6 KB
Line 
1/*
2 * unistd.h - User level <unistd> library definition.
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 _UNISTD_H_
25#define _UNISTD_H_
26
27/*****************************************************************************************
28 * This file defines the user level, memory mapping related <mman> library.
29 * All these functions make a system call to access the kernel structures.
30 * The user/kernel shared structures and mnemonics are defined in
31 * the <syscalls/shared_include/shared_unistd.h> file.
32 ****************************************************************************************/
33
34#include <shared_unistd.h>
35
36/*****************************************************************************************
37 * This function returns the pathname of the current working directory.
38 *****************************************************************************************
39 * buf     : buffer addres in user space.
40 * nbytes  : user buffer size in bytes.
41 * @ return 0 if success / returns -1 if failure.
42 ****************************************************************************************/
43int getcwd( char       * buf,
44            unsigned int nbytes );
45
46/*****************************************************************************************
47 * This function read bytes from an open file identified by the <fd> file descriptor.
48 * This file can be a regular file or a character oriented device.
49 *****************************************************************************************
50 * @ fd       : open file index in fd_array.
51 * @ buf      : buffer virtual address in user space.
52 * @ count    : number of bytes.
53 * @ return number of bytes actually read if success / returns -1 if failure.
54 ****************************************************************************************/
55int read( int            fd,
56          void         * buf,
57          unsigned int   count );
58
59/*****************************************************************************************
60 * This function writes bytes to an open file identified by the <fd> file descriptor.
61 * This file can be a regular file or character oriented device.
62 *****************************************************************************************
63 * @ fd       : open file index in fd_array.
64 * @ buf      : buffer virtual address in user space.
65 * @ count    : number of bytes.
66 * @ return number of bytes actually written if success / returns -1 if failure.
67 ****************************************************************************************/
68int write( int            fd,
69           const void   * buf,
70           unsigned int   count );
71
72/*****************************************************************************************
73 * This function repositions the offset of the file descriptor identified by <file_id>,
74 * according to the operation type defined by the <whence> argument.
75 *****************************************************************************************
76 * @ fd       : open file index in fd_array.
77 * @ offset   : used to compute new offset value.
78 * @ whence   : operation type (SEEK_SET / SEEK_CUR / SEEK_END defined in syscalls.h)
79 * @ return 0 if success / returns -1 if failure.
80 ****************************************************************************************/
81int lseek( int           fd,
82           unsigned int  offset,
83           int           whence );
84
85/*****************************************************************************************
86 * This function release the memory allocated for the file descriptor identified by
87 * the <file_id> argument, and remove the fd array_entry in all copies of the process
88 * descriptor.
89 *****************************************************************************************
90 * @ fd   : file descriptor index in fd_array.
91 * @ return 0 if success / returns -1 if failure.
92 ****************************************************************************************/
93int close( int fd );
94
95/*****************************************************************************************
96 * This function removes a directory entry identified by the <pathname> from the
97 * directory, and decrement the link count of the file referenced by the link.
98 * If the link count reduces to zero, and no process has the file open, then all resources
99 * associated with the file are released.  If one or more process have the file open when
100 * the last link is removed, the link is removed, but the removal of the file is delayed
101 * until all references to it have been closed.
102 *****************************************************************************************
103 * @ pathname   : pathname (can be relative or absolute).
104 * @ return 0 if success / returns -1 if failure.
105 ****************************************************************************************/
106int unlink( const char * pathname );
107
108/*****************************************************************************************
109 * This function creates in the calling thread cluster an unnamed pipe, and two
110 * (read and write) file descriptors to access this pipe. The calling function must pass
111 * the pointer on the fd[] array.
112 * TODO not implemented yet...
113 *****************************************************************************************
114 * @ fd[0] : [out] read only file descriptor index.
115 * @ fd[1] : [out] write only file descriptor index.
116 * @ return 0 if success / return -1 if failure.
117 ****************************************************************************************/
118int pipe( int fd[2] );
119
120/*****************************************************************************************
121 * This function change the current working directory in reference process descriptor.
122 *****************************************************************************************
123 * @ pathname   : pathname (can be relative or absolute).
124 * @ return 0 if success / returns -1 if failure.
125 ****************************************************************************************/
126int chdir( const char * pathname );
127
128/*****************************************************************************************
129 * This function removes a directory file whose name is given by <pathname>.
130 * The directory must not have any entries other than `.' and `..'.
131 *****************************************************************************************
132 * @ pathname   : pathname (can be relative or absolute).
133 * @ return 0 if success / returns -1 if failure.
134 ****************************************************************************************/
135int rmdir( char * pathname ); 
136
137/*****************************************************************************************
138 * This function implement the "fork" system call on the user side.
139 * The calling process descriptor (parent process), and the associated thread descriptor
140 * are replicated in a - likely - remote cluster, that becomes the new process owner.
141 * The child process get a new PID is linked to the parent PID. The child process inherit
142 * from the parent process the memory image, and all open files (including the TXT).
143 * The child process becomes the TXT terminal owner.
144 * The target cluster depends on the "fork_user" flag and "fork_cxy" variable that can be
145 * stored in the calling thread descriptor by the specific fork_place() system call.
146 * If not, the kernel function makes a query to the DQDT to select the target cluster.
147 *****************************************************************************************
148 * @ if success, returns child process PID to parent, and return O to child.
149 * @ if failure, returns -1 to parent / no child process is created.
150 ****************************************************************************************/
151int fork( void );
152
153/*****************************************************************************************
154 * This function implement the "exec" system call on the user side.
155 * It creates, in the same cluster as the calling thread, a new process descriptor,
156 * and a new associated main thread descriptor, executing a new memory image defined
157 * by the <filename> argument. This new process inherit from the old process the PID
158 * and the PPID, as well as all open files (including the TXT).
159 * The old process descriptor, and all its threads are blocked, and marked for deletion.
160 * Therefore the exec syscall does not return to the calling thread in case of success.
161 * This function build an exec_info_t structure containing the new process arguments,
162 * as defined by the <arv> argument, and the new process environment variables,
163 * as defined by the <envp>  argument.
164 * TODO : the <argv> and <envp> arguments are not supported yet (both must be NULL).
165 *****************************************************************************************
166 * @ filename : string pointer on .elf filename (virtual pointer in user space)
167 * @ argv     : array of strings on process arguments (virtual pointers in user space)
168 * @ envp     : array of strings on environment variables (virtual pointers in user space)
169 * @ does not return if success / returns -1 if failure.
170 ****************************************************************************************/
171int execve( char  * filename,
172            char ** argv,
173            char ** envp );
174
175/*****************************************************************************************
176 * This function implements the "getpid" system call on the user side.
177 *****************************************************************************************
178 * @ returns the process PID for the calling thread process.
179 ****************************************************************************************/
180int getpid( void );
181
182/*****************************************************************************************
183 * This function test whether a file descriptor refers to a terminal.
184 *****************************************************************************************
185 * @ fd   : file descriptor index in fd_array.
186 * @ returns 1 if fd is an open file descriptor referring to a terminal / 0 otherwise.
187 ****************************************************************************************/
188int isatty( int fd );
189
190/*****************************************************************************************
191 * This function sets a timer to deliver the signal SIGALRM to the calling process,
192 * after the specified number of seconds.
193 * If an alarm has already been set with alarm() but has not been delivered,
194 * another call to alarm() will supersede the prior call.
195 * The request alarm(0) cancels the current alarm and the signal will not be delivered.
196 *****************************************************************************************
197 * @ seconds   : number of seconds.
198 * @ returns the amount of time left on the timer from a previous call to alarm().
199 *   If no alarm is currently set, the return value is 0.
200 ****************************************************************************************/
201unsigned alarm( unsigned seconds );
202
203#endif
Note: See TracBrowser for help on using the repository browser.