[449] | 1 | /* |
---|
| 2 | * unistd.c - User level <unistd> library implementation. |
---|
| 3 | * |
---|
[625] | 4 | * Author Alain Greiner (2016,2017,2018,2019) |
---|
[449] | 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> |
---|
[457] | 25 | #include <hal_shared_types.h> |
---|
[449] | 26 | #include <hal_user.h> |
---|
| 27 | #include <syscalls_numbers.h> |
---|
[589] | 28 | #include <shared_signal.h> |
---|
[449] | 29 | |
---|
[589] | 30 | ////////////////////////////////// |
---|
| 31 | unsigned alarm( unsigned seconds ) |
---|
| 32 | { |
---|
| 33 | return hal_user_syscall( SYS_ALARM, |
---|
| 34 | (reg_t)seconds, 0, 0, 0 ); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | ////////////////////////////////// |
---|
| 38 | int chdir( const char * pathname ) |
---|
| 39 | { |
---|
| 40 | return hal_user_syscall( SYS_CHDIR, |
---|
| 41 | (reg_t)pathname, 0, 0, 0 ); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | /////////////////// |
---|
| 45 | int close( int fd ) |
---|
| 46 | { |
---|
| 47 | return hal_user_syscall( SYS_CLOSE, |
---|
| 48 | (reg_t)fd, 0, 0, 0 ); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | /////////////////////////// |
---|
| 52 | int 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 | //////////////// |
---|
| 63 | int fork( void ) |
---|
| 64 | { |
---|
| 65 | return hal_user_syscall( SYS_FORK, 0, 0, 0, 0 ); |
---|
| 66 | } |
---|
| 67 | |
---|
[626] | 68 | ////////////////// |
---|
| 69 | int fsync( int fd ) |
---|
| 70 | { |
---|
| 71 | return hal_user_syscall( SYS_FSYNC, |
---|
| 72 | (reg_t)fd, 0, 0, 0 ); |
---|
| 73 | } |
---|
| 74 | |
---|
[449] | 75 | ///////////////////////////// |
---|
| 76 | int getcwd( char * buf, |
---|
| 77 | unsigned int bytes ) |
---|
| 78 | { |
---|
| 79 | return hal_user_syscall( SYS_GETCWD, |
---|
| 80 | (reg_t)buf, |
---|
| 81 | (reg_t)bytes, 0, 0 ); |
---|
| 82 | } |
---|
[589] | 83 | |
---|
[626] | 84 | ////////////////// |
---|
[589] | 85 | int getpid( void ) |
---|
[449] | 86 | { |
---|
[589] | 87 | return hal_user_syscall( SYS_GETPID, 0, 0, 0, 0 ); |
---|
[449] | 88 | } |
---|
| 89 | |
---|
[589] | 90 | /////////////////// |
---|
| 91 | int isatty(int fd ) |
---|
[449] | 92 | { |
---|
[589] | 93 | return hal_user_syscall( SYS_ISATTY, |
---|
| 94 | (reg_t)fd, 0, 0, 0 ); |
---|
[449] | 95 | } |
---|
| 96 | |
---|
| 97 | /////////////////////////// |
---|
| 98 | int lseek( int fd, |
---|
| 99 | unsigned int offset, |
---|
| 100 | int whence ) |
---|
| 101 | { |
---|
| 102 | return hal_user_syscall( SYS_LSEEK, |
---|
| 103 | (reg_t)fd, |
---|
| 104 | (reg_t)offset, |
---|
| 105 | (reg_t)whence, 0 ); |
---|
| 106 | } |
---|
| 107 | |
---|
[589] | 108 | ///////////////// |
---|
| 109 | int pause( void ) |
---|
[449] | 110 | { |
---|
[589] | 111 | return hal_user_syscall( SYS_KILL, |
---|
| 112 | getpid(), |
---|
| 113 | SIGSTOP, 0, 0 ); |
---|
[449] | 114 | } |
---|
| 115 | |
---|
| 116 | ///////////////////// |
---|
| 117 | int pipe( int fd[2] ) |
---|
| 118 | { |
---|
[473] | 119 | return hal_user_syscall( SYS_PIPE, |
---|
| 120 | (reg_t)fd, 0, 0, 0 ); |
---|
[449] | 121 | } |
---|
| 122 | |
---|
[589] | 123 | ////////////////////////// |
---|
| 124 | int read( int fd, |
---|
| 125 | void * buf, |
---|
| 126 | unsigned int count ) |
---|
[449] | 127 | { |
---|
[589] | 128 | return hal_user_syscall( SYS_READ, |
---|
| 129 | (reg_t)fd, |
---|
| 130 | (reg_t)buf, |
---|
| 131 | (reg_t)count, 0 ); |
---|
[449] | 132 | } |
---|
| 133 | |
---|
| 134 | //////////////////////////// |
---|
| 135 | int rmdir( char * pathname ) |
---|
| 136 | { |
---|
| 137 | return hal_user_syscall( SYS_RMDIR, |
---|
| 138 | (reg_t)pathname, 0, 0, 0 ); |
---|
| 139 | } |
---|
| 140 | |
---|
[626] | 141 | ///////////////// |
---|
| 142 | void sync( void ) |
---|
| 143 | { |
---|
| 144 | hal_user_syscall( SYS_SYNC, 0, 0, 0, 0 ); |
---|
| 145 | } |
---|
| 146 | |
---|
[449] | 147 | /////////////////////////////////// |
---|
| 148 | int unlink( const char * pathname ) |
---|
| 149 | { |
---|
| 150 | return hal_user_syscall( SYS_UNLINK, |
---|
| 151 | (reg_t)pathname, 0, 0, 0 ); |
---|
| 152 | } |
---|
| 153 | |
---|
[589] | 154 | /////////////////////////// |
---|
| 155 | int write( int fd, |
---|
| 156 | const void * buf, |
---|
| 157 | unsigned int count ) |
---|
[449] | 158 | { |
---|
[589] | 159 | return hal_user_syscall( SYS_WRITE, |
---|
| 160 | (reg_t)fd, |
---|
| 161 | (reg_t)buf, |
---|
| 162 | (reg_t)count, 0 ); |
---|
[449] | 163 | } |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | |
---|