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

Last change on this file since 638 was 626, checked in by alain, 6 years ago

This version has been tested on the sort multithreaded application
for TSAR_IOB architectures ranging from 1 to 8 clusters.
It fixes three bigs bugs:
1) the dev_ioc device API has been modified: the dev_ioc_sync_read()
and dev_ioc_sync_write() function use now extended pointers on the
kernel buffer to access a mapper stored in any cluster.
2) the hal_uspace API has been modified: the hal_copy_to_uspace()
and hal_copy_from_uspace() functions use now a (cxy,ptr) couple
to identify the target buffer (equivalent to an extended pointer.
3) an implementation bug has been fixed in the assembly code contained
in the hal_copy_to_uspace() and hal_copy_from_uspace() functions.

File size: 4.0 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 fsync( int fd )
70{
71    return hal_user_syscall( SYS_FSYNC,
72                             (reg_t)fd, 0, 0, 0 );
73}
74
75/////////////////////////////
76int 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}
83
84//////////////////
85int getpid( void )
86{
87    return hal_user_syscall( SYS_GETPID, 0, 0, 0, 0 );
88}
89
90///////////////////
91int isatty(int fd )
92{
93    return hal_user_syscall( SYS_ISATTY,
94                             (reg_t)fd, 0, 0, 0 );
95}
96
97///////////////////////////
98int 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
108/////////////////
109int pause( void )
110{
111    return hal_user_syscall( SYS_KILL, 
112                             getpid(),
113                             SIGSTOP, 0, 0 );
114}
115
116/////////////////////
117int pipe( int fd[2] )
118{
119    return hal_user_syscall( SYS_PIPE, 
120                             (reg_t)fd, 0, 0, 0 );
121}
122
123//////////////////////////
124int read( int          fd,
125          void       * buf,
126          unsigned int count )
127{
128    return hal_user_syscall( SYS_READ,
129                             (reg_t)fd,
130                             (reg_t)buf,
131                             (reg_t)count, 0 );
132}
133
134////////////////////////////
135int rmdir( char * pathname )
136{
137    return hal_user_syscall( SYS_RMDIR,
138                             (reg_t)pathname, 0, 0, 0 );
139} 
140
141/////////////////
142void sync( void )
143{
144    hal_user_syscall( SYS_SYNC, 0, 0, 0, 0 );
145}
146
147///////////////////////////////////
148int unlink( const char * pathname )
149{
150    return hal_user_syscall( SYS_UNLINK,
151                             (reg_t)pathname, 0, 0, 0 );
152}
153
154///////////////////////////
155int write( int          fd,
156           const void * buf,
157           unsigned int count )
158{
159    return hal_user_syscall( SYS_WRITE,
160                             (reg_t)fd,
161                             (reg_t)buf,
162                             (reg_t)count, 0 );
163}
164
165
166
Note: See TracBrowser for help on using the repository browser.