OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 The Native Client Authors. All rights reserved. | 2 * Copyright 2014 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #ifndef NATIVE_CLIENT_SRC_NONSFI_LINUX_ABI_CONVERSION_H_ | 7 #ifndef NATIVE_CLIENT_SRC_NONSFI_LINUX_ABI_CONVERSION_H_ |
8 #define NATIVE_CLIENT_SRC_NONSFI_LINUX_ABI_CONVERSION_H_ 1 | 8 #define NATIVE_CLIENT_SRC_NONSFI_LINUX_ABI_CONVERSION_H_ 1 |
9 | 9 |
10 #include <fcntl.h> | |
10 #include <stdint.h> | 11 #include <stdint.h> |
11 #include <string.h> | 12 #include <string.h> |
12 #include <sys/stat.h> | 13 #include <sys/stat.h> |
13 #include <sys/time.h> | 14 #include <sys/time.h> |
14 #include <time.h> | 15 #include <time.h> |
15 | 16 |
16 #include "native_client/src/nonsfi/linux/linux_syscall_defines.h" | 17 #include "native_client/src/nonsfi/linux/linux_syscall_defines.h" |
17 #include "native_client/src/trusted/service_runtime/nacl_config.h" | 18 #include "native_client/src/trusted/service_runtime/nacl_config.h" |
18 | 19 |
19 #if defined(__i386__) || defined(__arm__) | 20 #if defined(__i386__) || defined(__arm__) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 * We control the layout of this struct explicitly because PNaCl | 64 * We control the layout of this struct explicitly because PNaCl |
64 * clang inserts extra paddings even for the i386 target without | 65 * clang inserts extra paddings even for the i386 target without |
65 * this. | 66 * this. |
66 */ | 67 */ |
67 } __attribute__((packed)); | 68 } __attribute__((packed)); |
68 | 69 |
69 #else | 70 #else |
70 # error Unsupported architecture | 71 # error Unsupported architecture |
71 #endif | 72 #endif |
72 | 73 |
74 /* We do not use O_RDONLY for abi conversion because it is 0. */ | |
75 #define LINUX_O_WRONLY 01 | |
76 #define LINUX_O_RDWR 02 | |
77 #define LINUX_O_CREAT 0100 | |
78 #define LINUX_O_TRUNC 01000 | |
79 #define LINUX_O_APPEND 02000 | |
80 #define LINUX_O_EXCL 0200 | |
81 #define LINUX_O_NONBLOCK 04000 | |
82 #define LINUX_O_SYNC 04010000 | |
83 #define LINUX_O_ASYNC 020000 | |
84 | |
85 #if defined(__i386__) | |
86 # define LINUX_O_DIRECTORY 0200000 | |
87 #elif defined(__arm__) | |
88 # define LINUX_O_DIRECTORY 040000 | |
89 #else | |
90 # error Unsupported architecture | |
91 #endif | |
92 | |
93 #define LINUX_O_CLOEXEC 02000000 | |
94 | |
95 #define NACL_KNOWN_O_FLAGS (O_ACCMODE | O_CREAT | O_TRUNC | O_APPEND |\ | |
Mark Seaborn
2014/12/08 22:09:02
Nit: add space before '\'
hidehiko
2014/12/09 08:38:49
Done.
| |
96 O_EXCL | O_NONBLOCK | O_SYNC | O_ASYNC |\ | |
97 O_DIRECTORY | O_CLOEXEC) | |
98 | |
99 /* Converts open flags from NaCl's to Linux's ABI. */ | |
100 static inline int nacl_oflags_to_linux_oflags(int nacl_oflags) { | |
101 if (nacl_oflags & ~NACL_KNOWN_O_FLAGS) { | |
102 /* Unknown bit is found. */ | |
103 return -1; | |
104 } | |
105 #define NACL_TO_LINUX(name) ((nacl_oflags & name) ? LINUX_ ## name : 0) | |
106 return (NACL_TO_LINUX(O_WRONLY) | | |
107 NACL_TO_LINUX(O_RDWR) | | |
108 NACL_TO_LINUX(O_CREAT) | | |
109 NACL_TO_LINUX(O_TRUNC) | | |
110 NACL_TO_LINUX(O_APPEND) | | |
111 NACL_TO_LINUX(O_EXCL) | | |
112 NACL_TO_LINUX(O_NONBLOCK) | | |
113 NACL_TO_LINUX(O_SYNC) | | |
114 NACL_TO_LINUX(O_ASYNC) | | |
115 NACL_TO_LINUX(O_DIRECTORY) | | |
116 NACL_TO_LINUX(O_CLOEXEC)); | |
117 #undef NACL_TO_LINUX | |
118 } | |
119 | |
120 /* Converts open flags from Linux's to NaCl's ABI. */ | |
121 static inline int linux_oflags_to_nacl_oflags(int linux_oflags) { | |
122 /* | |
123 * Because O_SYNC has two 1-bits. So we cannot use the same validation | |
124 * check. We ignore unknown flags in this case. | |
125 */ | |
126 #define LINUX_TO_NACL(name) \ | |
127 (((linux_oflags & LINUX_ ## name) == LINUX_ ## name) ? name : 0) | |
Mark Seaborn
2014/12/08 22:09:02
Nit: indent by 2 more spaces so that this doesn't
hidehiko
2014/12/09 08:38:49
Done.
| |
128 return (LINUX_TO_NACL(O_WRONLY) | | |
129 LINUX_TO_NACL(O_RDWR) | | |
130 LINUX_TO_NACL(O_CREAT) | | |
131 LINUX_TO_NACL(O_TRUNC) | | |
132 LINUX_TO_NACL(O_APPEND) | | |
133 LINUX_TO_NACL(O_EXCL) | | |
134 LINUX_TO_NACL(O_NONBLOCK) | | |
135 LINUX_TO_NACL(O_SYNC) | | |
136 LINUX_TO_NACL(O_ASYNC) | | |
137 LINUX_TO_NACL(O_DIRECTORY) | | |
138 LINUX_TO_NACL(O_CLOEXEC)); | |
139 #undef LINUX_TO_NACL | |
140 } | |
141 | |
73 /* Converts the timespec struct from NaCl's to Linux's ABI. */ | 142 /* Converts the timespec struct from NaCl's to Linux's ABI. */ |
74 static inline void nacl_timespec_to_linux_timespec( | 143 static inline void nacl_timespec_to_linux_timespec( |
75 const struct timespec *nacl_timespec, | 144 const struct timespec *nacl_timespec, |
76 struct linux_abi_timespec *linux_timespec) { | 145 struct linux_abi_timespec *linux_timespec) { |
77 linux_timespec->tv_sec = nacl_timespec->tv_sec; | 146 linux_timespec->tv_sec = nacl_timespec->tv_sec; |
78 linux_timespec->tv_nsec = nacl_timespec->tv_nsec; | 147 linux_timespec->tv_nsec = nacl_timespec->tv_nsec; |
79 } | 148 } |
80 | 149 |
81 /* Converts the timespec struct from Linux's to NaCl's ABI. */ | 150 /* Converts the timespec struct from Linux's to NaCl's ABI. */ |
82 static inline void linux_timespec_to_nacl_timespec( | 151 static inline void linux_timespec_to_nacl_timespec( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 nacl_stat->st_rdev = 0; | 183 nacl_stat->st_rdev = 0; |
115 nacl_stat->st_size = linux_stat->st_size; | 184 nacl_stat->st_size = linux_stat->st_size; |
116 nacl_stat->st_blksize = 0; | 185 nacl_stat->st_blksize = 0; |
117 nacl_stat->st_blocks = 0; | 186 nacl_stat->st_blocks = 0; |
118 nacl_stat->st_atime = linux_stat->st_atime; | 187 nacl_stat->st_atime = linux_stat->st_atime; |
119 nacl_stat->st_mtime = linux_stat->st_mtime; | 188 nacl_stat->st_mtime = linux_stat->st_mtime; |
120 nacl_stat->st_ctime = linux_stat->st_ctime; | 189 nacl_stat->st_ctime = linux_stat->st_ctime; |
121 } | 190 } |
122 | 191 |
123 #endif | 192 #endif |
OLD | NEW |