1 /*
2  * Copyright (c) 2011 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  * NaCl Service Runtime API.
9  */
10 
11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_INCLUDE_SYS_FCNTL_H_
12 #define NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_INCLUDE_SYS_FCNTL_H_
13 
14 #if defined(NACL_IN_TOOLCHAIN_HEADERS)
15 #include <sys/types.h>
16 #endif
17 
18 /* from bits/fcntl.h */
19 #define NACL_ABI_O_ACCMODE       0003
20 #define NACL_ABI_O_RDONLY          00
21 #define NACL_ABI_O_WRONLY          01
22 #define NACL_ABI_O_RDWR            02
23 
24 #define NACL_ABI_O_CREAT         0100 /* not fcntl */
25 #define NACL_ABI_O_TRUNC        01000 /* not fcntl */
26 #define NACL_ABI_O_APPEND       02000
27 #define NACL_ABI_O_DIRECTORY  0200000 /* not fcntl */
28 
29 /*
30  * Features not implemented by NaCl, but required by the newlib build.
31  */
32 #define NACL_ABI_O_EXCL          0200
33 #define NACL_ABI_O_NONBLOCK     04000
34 #define NACL_ABI_O_NDELAY      NACL_ABI_O_NONBLOCK
35 #define NACL_ABI_O_SYNC        010000
36 #define NACL_ABI_O_FSYNC       NACL_ABI_O_SYNC
37 #define NACL_ABI_O_ASYNC       020000
38 
39 /*
40  * Features not implemented by NaCl, but required by nacl_helper_nonsfi.
41  */
42 #define NACL_ABI_O_CLOEXEC   02000000
43 
44 /* XXX close on exec request; must match UF_EXCLOSE in user.h */
45 #define FD_CLOEXEC  1 /* posix */
46 
47 /* fcntl(2) requests */
48 #define NACL_ABI_F_DUPFD   0 /* Duplicate fildes */
49 #define NACL_ABI_F_GETFD   1 /* Get fildes flags (close on exec) */
50 #define NACL_ABI_F_SETFD   2 /* Set fildes flags (close on exec) */
51 #define NACL_ABI_F_GETFL   3 /* Get file flags */
52 #define NACL_ABI_F_SETFL   4 /* Set file flags */
53 #ifndef _POSIX_SOURCE
54 #define NACL_ABI_F_GETOWN  5 /* Get owner - for ASYNC */
55 #define NACL_ABI_F_SETOWN  6 /* Set owner - for ASYNC */
56 #endif  /* !_POSIX_SOURCE */
57 #define NACL_ABI_F_GETLK   7 /* Get record-locking information */
58 #define NACL_ABI_F_SETLK   8 /* Set or Clear a record-lock (Non-Blocking) */
59 #define NACL_ABI_F_SETLKW  9 /* Set or Clear a record-lock (Blocking) */
60 #ifndef _POSIX_SOURCE
61 #define NACL_ABI_F_RGETLK  10  /* Test a remote lock to see if it is blocked */
62 #define NACL_ABI_F_RSETLK  11  /* Set or unlock a remote lock */
63 #define NACL_ABI_F_CNVT    12  /* Convert a fhandle to an open fd */
64 #define NACL_ABI_F_RSETLKW   13  /* Set or Clear remote record-lock(Blocking) */
65 #endif  /* !_POSIX_SOURCE */
66 
67 /* fcntl(2) flags (l_type field of flock structure) */
68 #define NACL_ABI_F_RDLCK   1 /* read lock */
69 #define NACL_ABI_F_WRLCK   2 /* write lock */
70 #define NACL_ABI_F_UNLCK   3 /* remove lock(s) */
71 #ifndef _POSIX_SOURCE
72 #define NACL_ABI_F_UNLKSYS 4 /* remove remote locks for a given system */
73 #endif  /* !_POSIX_SOURCE */
74 
75 /* For openat(2) used by nacl_helper_nonsfi. */
76 #define NACL_ABI_AT_FDCWD (-2)
77 
78 #if defined(NACL_IN_TOOLCHAIN_HEADERS)
79 /* file segment locking set data type - information passed to system by user */
80 struct flock {
81   short l_type;
82   short l_whence;
83   off_t l_start;
84   off_t l_len;
85   pid_t l_pid;
86 };
87 
88 #ifdef __cplusplus
89 extern "C" {
90 #endif  /* __cplusplus */
91 
92 extern int open(const char *file, int oflag, ...);
93 extern int creat(const char *file, mode_t mode);
94 extern int fcntl(int, int, ...);
95 extern int openat(int dirfd, const char *pathname, int oflag, ...);
96 
97 #ifdef __cplusplus
98 }  /* extern "C" */
99 #endif  /* __cplusplus */
100 #endif  /* defined(NACL_IN_TOOLCHAIN_HEADERS) */
101 
102 #endif
103