1 /* 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 3 * Use of this source code is governed by a BSD-style license that can be 4 * found in the LICENSE file. 5 */ 6 7 /* 8 * This file is based on the file "newlib/libc/include/sys/unistd.h" 9 * from newlib. 10 */ 11 12 #ifndef NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_INCLUDE_SYS_UNISTD_H_ 13 #define NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_INCLUDE_SYS_UNISTD_H_ 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 /* 20 * We need this file in the service_runtime only to agree on enum values, 21 * therefore most of it should be compiled only for NaCl applications 22 */ 23 #if defined(NACL_IN_TOOLCHAIN_HEADERS) 24 #include <_ansi.h> 25 #include <sys/types.h> 26 #include <sys/_types.h> 27 #define __need_size_t 28 #define __need_ptrdiff_t 29 #include <stddef.h> 30 #include <stdint.h> 31 32 extern char **environ; 33 34 void _EXFUN(_exit, (int __status ) _ATTRIBUTE ((noreturn))); 35 36 int _EXFUN(access,(const char *__path, int __amode )); 37 unsigned _EXFUN(alarm, (unsigned __secs )); 38 int _EXFUN(chdir, (const char *__path )); 39 int _EXFUN(chmod, (const char *__path, mode_t __mode )); 40 #if !defined(__INSIDE_CYGWIN__) 41 int _EXFUN(chown, (const char *__path, uid_t __owner, gid_t __group )); 42 #endif 43 #if defined(__CYGWIN__) || defined(__rtems__) 44 int _EXFUN(chroot, (const char *__path )); 45 #endif 46 int _EXFUN(close, (int __fildes )); 47 #if defined(__CYGWIN__) 48 size_t _EXFUN(confstr, (int __name, char *__buf, size_t __len)); 49 #endif 50 char _EXFUN(*ctermid, (char *__s )); 51 char _EXFUN(*cuserid, (char *__s )); 52 #if defined(__CYGWIN__) 53 int _EXFUN(daemon, (int nochdir, int noclose)); 54 #endif 55 int _EXFUN(dup, (int __fildes )); 56 int _EXFUN(dup2, (int __fildes, int __fildes2 )); 57 #if defined(__CYGWIN__) 58 void _EXFUN(endusershell, (void)); 59 #endif 60 int _EXFUN(execl, (const char *__path, const char *, ... )); 61 int _EXFUN(execle, (const char *__path, const char *, ... )); 62 int _EXFUN(execlp, (const char *__file, const char *, ... )); 63 int _EXFUN(execv, (const char *__path, char * const __argv[] )); 64 int _EXFUN(execve, (const char *__path, char * const __argv[], char * const __envp[] )); 65 int _EXFUN(execvp, (const char *__file, char * const __argv[] )); 66 int _EXFUN(fchdir, (int __fildes)); 67 int _EXFUN(fchmod, (int __fildes, mode_t __mode )); 68 #if !defined(__INSIDE_CYGWIN__) 69 int _EXFUN(fchown, (int __fildes, uid_t __owner, gid_t __group )); 70 #endif 71 pid_t _EXFUN(fork, (void )); 72 long _EXFUN(fpathconf, (int __fd, int __name )); 73 int _EXFUN(fsync, (int __fd)); 74 int _EXFUN(fdatasync, (int __fd)); 75 char _EXFUN(*getcwd, (char *__buf, size_t __size )); 76 #if defined(__CYGWIN__) 77 int _EXFUN(getdomainname ,(char *__name, size_t __len)); 78 #endif 79 #if !defined(__INSIDE_CYGWIN__) 80 gid_t _EXFUN(getegid, (void )); 81 uid_t _EXFUN(geteuid, (void )); 82 gid_t _EXFUN(getgid, (void )); 83 #endif 84 int _EXFUN(getgroups, (int __gidsetsize, gid_t __grouplist[] )); 85 #if defined(__CYGWIN__) 86 long _EXFUN(gethostid, (void)); 87 #endif 88 char _EXFUN(*getlogin, (void )); 89 #if defined(_POSIX_THREAD_SAFE_FUNCTIONS) 90 int _EXFUN(getlogin_r, (char *name, size_t namesize) ); 91 #endif 92 char _EXFUN(*getpass, (const char *__prompt)); 93 int _EXFUN(getpagesize, (void)); 94 #if defined(__CYGWIN__) 95 int _EXFUN(getpeereid, (int, uid_t *, gid_t *)); 96 #endif 97 pid_t _EXFUN(getpgid, (pid_t)); 98 pid_t _EXFUN(getpgrp, (void )); 99 pid_t _EXFUN(getpid, (void )); 100 pid_t _EXFUN(getppid, (void )); 101 #ifdef __CYGWIN__ 102 pid_t _EXFUN(getsid, (pid_t)); 103 #endif 104 #if !defined(__INSIDE_CYGWIN__) 105 uid_t _EXFUN(getuid, (void )); 106 #endif 107 #ifdef __CYGWIN__ 108 char *_EXFUN(getusershell, (void)); 109 char _EXFUN(*getwd, (char *__buf )); 110 int _EXFUN(iruserok, (unsigned long raddr, int superuser, const char *ruser, const char *luser)); 111 #endif 112 int _EXFUN(isatty, (int __fildes )); 113 #if !defined(__INSIDE_CYGWIN__) 114 int _EXFUN(lchown, (const char *__path, uid_t __owner, gid_t __group )); 115 #endif 116 int _EXFUN(link, (const char *__path1, const char *__path2 )); 117 int _EXFUN(nice, (int __nice_value )); 118 #if !defined(__INSIDE_CYGWIN__) 119 off_t _EXFUN(lseek, (int __fildes, off_t __offset, int __whence )); 120 #endif 121 #if defined(__SPU__) 122 #define F_ULOCK 0 123 #define F_LOCK 1 124 #define F_TLOCK 2 125 #define F_TEST 3 126 int _EXFUN(lockf, (int __fd, int __cmd, off_t __len)); 127 #endif 128 long _EXFUN(pathconf, (const char *__path, int __name )); 129 int _EXFUN(pause, (void )); 130 #ifdef __CYGWIN__ 131 int _EXFUN(pthread_atfork, (void (*)(void), void (*)(void), void (*)(void))); 132 #endif 133 int _EXFUN(pipe, (int __fildes[2])); 134 int _EXFUN(pipe2, (int __fildes[2], int __flags)); 135 ssize_t _EXFUN(pread, (int __fd, void *__buf, size_t __nbytes, off_t __offset)); 136 ssize_t _EXFUN(pwrite, (int __fd, const void *__buf, size_t __nbytes, off_t __offset)); 137 _READ_WRITE_RETURN_TYPE _EXFUN(read, (int __fd, void *__buf, size_t __nbyte )); 138 #if defined(__CYGWIN__) 139 int _EXFUN(rresvport, (int *__alport)); 140 int _EXFUN(revoke, (char *__path)); 141 #endif 142 int _EXFUN(rmdir, (const char *__path )); 143 #if defined(__CYGWIN__) 144 int _EXFUN(ruserok, (const char *rhost, int superuser, const char *ruser, const char *luser)); 145 #endif 146 void * _EXFUN(sbrk, (intptr_t __incr)); 147 #if !defined(__INSIDE_CYGWIN__) 148 #if defined(__CYGWIN__) 149 int _EXFUN(setegid, (gid_t __gid )); 150 int _EXFUN(seteuid, (uid_t __uid )); 151 #endif 152 int _EXFUN(setgid, (gid_t __gid )); 153 #endif 154 #if defined(__CYGWIN__) 155 int _EXFUN(setgroups, (int ngroups, const gid_t *grouplist )); 156 #endif 157 int _EXFUN(setpgid, (pid_t __pid, pid_t __pgid )); 158 int _EXFUN(setpgrp, (void )); 159 #if defined(__CYGWIN__) && !defined(__INSIDE_CYGWIN__) 160 int _EXFUN(setregid, (gid_t __rgid, gid_t __egid)); 161 int _EXFUN(setreuid, (uid_t __ruid, uid_t __euid)); 162 #endif 163 pid_t _EXFUN(setsid, (void )); 164 #if !defined(__INSIDE_CYGWIN__) 165 int _EXFUN(setuid, (uid_t __uid )); 166 #endif 167 #if defined(__CYGWIN__) 168 void _EXFUN(setusershell, (void)); 169 #endif 170 unsigned _EXFUN(sleep, (unsigned int __seconds )); 171 void _EXFUN(swab, (const void *, void *, ssize_t)); 172 long _EXFUN(sysconf, (int __name )); 173 pid_t _EXFUN(tcgetpgrp, (int __fildes )); 174 int _EXFUN(tcsetpgrp, (int __fildes, pid_t __pgrp_id )); 175 char _EXFUN(*ttyname, (int __fildes )); 176 #if defined(__CYGWIN__) 177 int _EXFUN(ttyname_r, (int, char *, size_t)); 178 #endif 179 int _EXFUN(unlink, (const char *__path )); 180 int _EXFUN(usleep, (useconds_t __useconds)); 181 int _EXFUN(vhangup, (void )); 182 _READ_WRITE_RETURN_TYPE _EXFUN(write, (int __fd, const void *__buf, size_t __nbyte )); 183 184 #ifdef __CYGWIN__ 185 # define __UNISTD_GETOPT__ 186 # include <getopt.h> 187 # undef __UNISTD_GETOPT__ 188 #else 189 extern char *optarg; /* getopt(3) external variables */ 190 extern int optind, opterr, optopt; 191 int getopt(int, char * const [], const char *); 192 extern int optreset; /* getopt(3) external variable */ 193 #endif 194 195 #ifndef _POSIX_SOURCE 196 pid_t _EXFUN(vfork, (void )); 197 198 extern char *suboptarg; /* getsubopt(3) external variable */ 199 int getsubopt(char **, char * const *, char **); 200 #endif /* _POSIX_SOURCE */ 201 202 #ifdef _COMPILING_NEWLIB 203 /* Provide prototypes for most of the _<systemcall> names that are 204 provided in newlib for some compilers. */ 205 int _EXFUN(_close, (int __fildes )); 206 pid_t _EXFUN(_fork, (void )); 207 pid_t _EXFUN(_getpid, (void )); 208 int _EXFUN(_link, (const char *__path1, const char *__path2 )); 209 _off_t _EXFUN(_lseek, (int __fildes, _off_t __offset, int __whence )); 210 #ifdef __LARGE64_FILES 211 _off64_t _EXFUN(_lseek64, (int __filedes, _off64_t __offset, int __whence )); 212 #endif 213 _READ_WRITE_RETURN_TYPE _EXFUN(_read, (int __fd, void *__buf, size_t __nbyte )); 214 void * _EXFUN(_sbrk, (ptrdiff_t __incr)); 215 int _EXFUN(_unlink, (const char *__path )); 216 _READ_WRITE_RETURN_TYPE _EXFUN(_write, (int __fd, const void *__buf, size_t __nbyte )); 217 int _EXFUN(_execve, (const char *__path, char * const __argv[], char * const __envp[] )); 218 #endif 219 220 #if defined(__CYGWIN__) || defined(__rtems__) || defined(__sh__) \ 221 || defined(__SPU__) || defined(NACL_IN_TOOLCHAIN_HEADERS) 222 #if !defined(__INSIDE_CYGWIN__) 223 int _EXFUN(ftruncate, (int __fd, off_t __length)); 224 int _EXFUN(truncate, (const char *, off_t __length)); 225 #endif 226 #endif 227 228 #if defined(__CYGWIN__) || defined(__rtems__) || \ 229 defined(NACL_IN_TOOLCHAIN_HEADERS) 230 int _EXFUN(getdtablesize, (void)); 231 int _EXFUN(setdtablesize, (int)); 232 useconds_t _EXFUN(ualarm, (useconds_t __useconds, useconds_t __interval)); 233 #if !(defined (_WINSOCK_H) || defined (__USE_W32_SOCKETS)) 234 /* winsock[2].h defines as __stdcall, and with int as 2nd arg */ 235 int _EXFUN(gethostname, (char *__name, size_t __len)); 236 #endif 237 char *_EXFUN(mktemp, (char *)); 238 #endif 239 240 #if defined(__CYGWIN__) || defined(__SPU__) 241 void _EXFUN(sync, (void)); 242 #elif defined(__rtems__) 243 int _EXFUN(sync, (void)); 244 #endif 245 246 int _EXFUN(readlink, (const char *__path, char *__buf, int __buflen)); 247 int _EXFUN(symlink, (const char *__name1, const char *__name2)); 248 249 # define SEEK_SET 0 250 # define SEEK_CUR 1 251 # define SEEK_END 2 252 253 #include <sys/features.h> 254 255 #define STDIN_FILENO 0 /* standard input file descriptor */ 256 #define STDOUT_FILENO 1 /* standard output file descriptor */ 257 #define STDERR_FILENO 2 /* standard error file descriptor */ 258 259 #endif /* defined(NACL_IN_TOOLCHAIN_HEADERS) */ 260 261 #define NACL_ABI_F_OK 0 262 #define NACL_ABI_R_OK 4 263 #define NACL_ABI_W_OK 2 264 #define NACL_ABI_X_OK 1 265 266 /* 267 * sysconf values as supported by NativeClient 268 * 269 * These configuration names are defined within an enum so that 270 * -Wswitch-enum etc can be useful to detect bugs. They are also an 271 * identity macro definition -- explicitly defined by Posix as allowed 272 * -- so that code can be written using #ifdef conditionals to do 273 * simple code configuration based on whether a confname is available 274 * (and typically presumed to be implemented). (This is in contrast 275 * to autoconf-style configurations, which may involve compiling a 276 * short program to exercise functionality to determine if a feature 277 * is implemented.) 278 */ 279 enum { 280 NACL_ABI__SC_NPROCESSORS_ONLN = 1, 281 #define NACL_ABI__SC_NPROCESSORS_ONLN NACL_ABI__SC_NPROCESSORS_ONLN 282 NACL_ABI__SC_PAGESIZE = 2, 283 #define NACL_ABI__SC_PAGESIZE NACL_ABI__SC_PAGESIZE 284 NACL_ABI__SC_NACL_CPU_FEATURE_X86 = 1 << 16, 285 #define NACL_ABI__SC_NACL_CPU_FEATURE_X86 \ 286 NACL_ABI__SC_NACL_CPU_FEATURE_X86 287 288 /* 289 * The sysconf values below are not part of the stable ABI. 290 */ 291 NACL_ABI__SC_NACL_FILE_ACCESS_ENABLED = 1 << 24, 292 #define NACL_ABI__SC_NACL_FILE_ACCESS_ENABLED \ 293 NACL_ABI__SC_NACL_FILE_ACCESS_ENABLED 294 NACL_ABI__SC_NACL_LIST_MAPPINGS_ENABLED, 295 #define NACL_ABI__SC_NACL_LIST_MAPPINGS_ENABLED \ 296 NACL_ABI__SC_NACL_LIST_MAPPINGS_ENABLED 297 NACL_ABI__SC_NACL_PNACL_MODE, 298 #define NACL_ABI__SC_NACL_PNACL_MODE \ 299 NACL_ABI__SC_NACL_PNACL_MODE 300 }; 301 302 #if defined(NACL_IN_TOOLCHAIN_HEADERS) 303 /* 304 * TODO(gregoryd) pathconf and confstr are not supported on NaCl, 305 * consider removing the definitions below. 306 */ 307 308 /* 309 * pathconf values per IEEE Std 1003.1, 2004 Edition 310 */ 311 312 #define _PC_LINK_MAX 0 313 #define _PC_MAX_CANON 1 314 #define _PC_MAX_INPUT 2 315 #define _PC_NAME_MAX 3 316 #define _PC_PATH_MAX 4 317 #define _PC_PIPE_BUF 5 318 #define _PC_CHOWN_RESTRICTED 6 319 #define _PC_NO_TRUNC 7 320 #define _PC_VDISABLE 8 321 #define _PC_ASYNC_IO 9 322 #define _PC_PRIO_IO 10 323 #define _PC_SYNC_IO 11 324 #define _PC_FILESIZEBITS 12 325 #define _PC_2_SYMLINKS 13 326 #define _PC_SYMLINK_MAX 14 327 #ifdef __CYGWIN__ 328 /* Ask for POSIX permission bits support. */ 329 #define _PC_POSIX_PERMISSIONS 90 330 /* Ask for full POSIX permission support including uid/gid settings. */ 331 #define _PC_POSIX_SECURITY 91 332 #endif 333 334 /* 335 * confstr values per IEEE Std 1003.1, 2004 Edition 336 */ 337 338 #ifdef __CYGWIN__ /* Only defined on Cygwin for now. */ 339 #define _CS_PATH 0 340 #define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 1 341 #define _CS_XBS5_ILP32_OFF32_CFLAGS _CS_POSIX_V6_ILP32_OFF32_CFLAGS 342 #define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 2 343 #define _CS_XBS5_ILP32_OFF32_LDFLAGS _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 344 #define _CS_POSIX_V6_ILP32_OFF32_LIBS 3 345 #define _CS_XBS5_ILP32_OFF32_LIBS _CS_POSIX_V6_ILP32_OFF32_LIBS 346 #define _CS_XBS5_ILP32_OFF32_LINTFLAGS 4 347 #define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 5 348 #define _CS_XBS5_ILP32_OFFBIG_CFLAGS _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 349 #define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 6 350 #define _CS_XBS5_ILP32_OFFBIG_LDFLAGS _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 351 #define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 7 352 #define _CS_XBS5_ILP32_OFFBIG_LIBS _CS_POSIX_V6_ILP32_OFFBIG_LIBS 353 #define _CS_XBS5_ILP32_OFFBIG_LINTFLAGS 8 354 #define _CS_POSIX_V6_LP64_OFF64_CFLAGS 9 355 #define _CS_XBS5_LP64_OFF64_CFLAGS _CS_POSIX_V6_LP64_OFF64_CFLAGS 356 #define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 10 357 #define _CS_XBS5_LP64_OFF64_LDFLAGS _CS_POSIX_V6_LP64_OFF64_LDFLAGS 358 #define _CS_POSIX_V6_LP64_OFF64_LIBS 11 359 #define _CS_XBS5_LP64_OFF64_LIBS _CS_POSIX_V6_LP64_OFF64_LIBS 360 #define _CS_XBS5_LP64_OFF64_LINTFLAGS 12 361 #define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 13 362 #define _CS_XBS5_LPBIG_OFFBIG_CFLAGS _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 363 #define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 14 364 #define _CS_XBS5_LPBIG_OFFBIG_LDFLAGS _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 365 #define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 15 366 #define _CS_XBS5_LPBIG_OFFBIG_LIBS _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 367 #define _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS 16 368 #define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 17 369 #endif 370 371 #endif /* defined(NACL_IN_TOOLCHAIN_HEADERS) */ 372 373 #ifndef __CYGWIN__ 374 # define MAXPATHLEN 1024 375 #endif 376 377 #ifdef __cplusplus 378 } 379 #endif 380 #endif /* NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_INCLUDE_SYS_UNISTD_H_ */ 381