source: trunk/libs/mini-libc/unistd.c @ 625

Last change on this file since 625 was 625, checked in by alain, 2 years ago

Fix a bug in the vmm_remove_vseg() function: the physical pages
associated to an user DATA vseg were released to the kernel when
the target process descriptor was in the reference cluster.
This physical pages release should be done only when the page
forks counter value is zero.
All other modifications are cosmetic.

File size: 3.7 KB
Line 
1/*
2 * unistd.c - User level <unistd> library implementation.
3 *
4 * Author     Alain Greiner (2016,2017,2018,2019)
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#include <unistd.h>
25#include <hal_shared_types.h>
26#include <hal_user.h>
27#include <syscalls_numbers.h>
28#include <shared_signal.h>
29
30//////////////////////////////////
31unsigned alarm( unsigned seconds )
32{
33    return hal_user_syscall( SYS_ALARM,
34                             (reg_t)seconds, 0, 0, 0 );
35}
36
37//////////////////////////////////
38int chdir( const char * pathname )
39{
40    return hal_user_syscall( SYS_CHDIR,
41                             (reg_t)pathname, 0, 0, 0 );
42}
43
44///////////////////
45int close( int fd )
46{
47    return hal_user_syscall( SYS_CLOSE,
48                             (reg_t)fd, 0, 0, 0 );
49}
50
51///////////////////////////
52int execve( char  * pathname,
53            char ** argv,
54            char ** envp )
55{
56    return hal_user_syscall( SYS_EXEC,
57                             (reg_t)pathname,
58                             (reg_t)argv,
59                             (reg_t)envp, 0 );
60}
61
62////////////////
63int fork( void )
64{
65    return hal_user_syscall( SYS_FORK, 0, 0, 0, 0 );
66}
67
68/////////////////////////////
69int getcwd( char       * buf,
70            unsigned int bytes )
71{
72    return hal_user_syscall( SYS_GETCWD,
73                             (reg_t)buf,
74                             (reg_t)bytes, 0, 0 );
75}
76
77////////////
78int getpid( void )
79{
80    return hal_user_syscall( SYS_GETPID, 0, 0, 0, 0 );
81}
82
83///////////////////
84int isatty(int fd )
85{
86    return hal_user_syscall( SYS_ISATTY,
87                             (reg_t)fd, 0, 0, 0 );
88}
89
90///////////////////////////
91int lseek( int          fd,
92           unsigned int offset,
93           int          whence )
94{
95    return hal_user_syscall( SYS_LSEEK,
96                             (reg_t)fd,
97                             (reg_t)offset,
98                             (reg_t)whence, 0 );
99}
100
101/////////////////
102int pause( void )
103{
104    return hal_user_syscall( SYS_KILL, 
105                             getpid(),
106                             SIGSTOP, 0, 0 );
107}
108
109/////////////////////
110int pipe( int fd[2] )
111{
112    return hal_user_syscall( SYS_PIPE, 
113                             (reg_t)fd, 0, 0, 0 );
114}
115
116//////////////////////////
117int read( int          fd,
118          void       * buf,
119          unsigned int count )
120{
121    return hal_user_syscall( SYS_READ,
122                             (reg_t)fd,
123                             (reg_t)buf,
124                             (reg_t)count, 0 );
125}
126
127////////////////////////////
128int rmdir( char * pathname )
129{
130    return hal_user_syscall( SYS_RMDIR,
131                             (reg_t)pathname, 0, 0, 0 );
132} 
133
134///////////////////////////////////
135int unlink( const char * pathname )
136{
137    return hal_user_syscall( SYS_UNLINK,
138                             (reg_t)pathname, 0, 0, 0 );
139}
140
141///////////////////////////
142int write( int          fd,
143           const void * buf,
144           unsigned int count )
145{
146    return hal_user_syscall( SYS_WRITE,
147                             (reg_t)fd,
148                             (reg_t)buf,
149                             (reg_t)count, 0 );
150}
151
152
153
Note: See TracBrowser for help on using the repository browser.