Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(519)

Side by Side Diff: src/nonsfi/linux/abi_conversion.h

Issue 744803003: Non-SFI mode: Add syscalls which are needed for nacl_helper_nonsfi's sandbox. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
16 #include <stdio.h>
Mark Seaborn 2014/11/27 16:12:16 Left over from debugging?
hidehiko 2014/11/28 16:58:15 Good catch. Removed.
15 17
16 #include "native_client/src/nonsfi/linux/linux_syscall_defines.h" 18 #include "native_client/src/nonsfi/linux/linux_syscall_defines.h"
17 #include "native_client/src/trusted/service_runtime/nacl_config.h" 19 #include "native_client/src/trusted/service_runtime/nacl_config.h"
18 20
19 #if defined(__i386__) || defined(__arm__) 21 #if defined(__i386__) || defined(__arm__)
20 22
21 struct linux_abi_timeval { 23 struct linux_abi_timeval {
22 int32_t tv_sec; 24 int32_t tv_sec;
23 int32_t tv_usec; 25 int32_t tv_usec;
24 }; 26 };
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 * We control the layout of this struct explicitly because PNaCl 65 * We control the layout of this struct explicitly because PNaCl
64 * clang inserts extra paddings even for the i386 target without 66 * clang inserts extra paddings even for the i386 target without
65 * this. 67 * this.
66 */ 68 */
67 } __attribute__((packed)); 69 } __attribute__((packed));
68 70
69 #else 71 #else
70 # error Unsupported architecture 72 # error Unsupported architecture
71 #endif 73 #endif
72 74
75 /* We do not use O_RDONLY for abi conversion because it is 0. */
76 #define LINUX_O_WRONLY 01
Mark Seaborn 2014/11/27 16:12:17 Which of these flags are different from NaCl/newli
hidehiko 2014/11/28 16:58:15 O_SYNC and O_DIRECTORY. O_SYNC is 010000 in NaCl
77 #define LINUX_O_RDWR 02
78 #define LINUX_O_CREAT 0100
79 #define LINUX_O_TRUNC 01000
80 #define LINUX_O_APPEND 02000
81 #define LINUX_O_EXCL 0200
82 #define LINUX_O_NONBLOCK 04000
83 #define LINUX_O_SYNC 04010000
84 #define LINUX_O_ASYNC 020000
85
86 #if defined(__i386__)
87 # define LINUX_O_DIRECTORY 0200000
88 #elif defined(__arm__)
89 # define LINUX_O_DIRECTORY 040000
90 #else
91 # error Unsupported architecture
92 #endif
93
94 #define LINUX_O_CLOEXEC 02000000
95
96 #define NACL_KNOWN_O_FLAGS (O_ACCMODE | O_CREAT | O_TRUNC | O_APPEND |\
97 O_EXCL | O_NONBLOCK | O_SYNC | O_ASYNC |\
98 O_DIRECTORY | O_CLOEXEC)
99
100 /* Converts open flags from NaCl's to Linux's ABI. */
101 static inline int nacl_oflags_to_linux_oflags(int nacl_oflags) {
102 if (nacl_oflags & ~NACL_KNOWN_O_FLAGS) {
103 /* Unknown bit is found. */
104 return -1;
105 }
106 #define NACL_TO_LINUX(name) ((nacl_oflags & name) ? LINUX_ ## name : 0)
107 return (NACL_TO_LINUX(O_WRONLY) |
108 NACL_TO_LINUX(O_RDWR) |
109 NACL_TO_LINUX(O_CREAT) |
110 NACL_TO_LINUX(O_TRUNC) |
111 NACL_TO_LINUX(O_APPEND) |
112 NACL_TO_LINUX(O_EXCL) |
113 NACL_TO_LINUX(O_NONBLOCK) |
114 NACL_TO_LINUX(O_SYNC) |
115 NACL_TO_LINUX(O_ASYNC) |
116 NACL_TO_LINUX(O_DIRECTORY) |
117 NACL_TO_LINUX(O_CLOEXEC));
118 #undef NACL_TO_LINUX
119 }
120
121 /* Converts open flags from Linux's to NaCl's ABI. */
122 static inline int linux_oflags_to_nacl_oflags(int linux_oflags) {
123 /*
124 * Because O_SYNC has two 1-bits. So we cannot use the same validation
125 * check. We ignore unknown flags in this case.
126 */
127 #define LINUX_TO_NACL(name) \
128 (((linux_oflags & LINUX_ ## name) == LINUX_ ## name) ? name : 0)
129 return (LINUX_TO_NACL(O_WRONLY) |
130 LINUX_TO_NACL(O_RDWR) |
131 LINUX_TO_NACL(O_CREAT) |
132 LINUX_TO_NACL(O_TRUNC) |
133 LINUX_TO_NACL(O_APPEND) |
134 LINUX_TO_NACL(O_EXCL) |
135 LINUX_TO_NACL(O_NONBLOCK) |
136 LINUX_TO_NACL(O_SYNC) |
137 LINUX_TO_NACL(O_ASYNC) |
138 LINUX_TO_NACL(O_DIRECTORY) |
139 LINUX_TO_NACL(O_CLOEXEC));
140 #undef LINUX_TO_NACL
141 }
142
73 /* Converts the timespec struct from NaCl's to Linux's ABI. */ 143 /* Converts the timespec struct from NaCl's to Linux's ABI. */
74 static inline void nacl_timespec_to_linux_timespec( 144 static inline void nacl_timespec_to_linux_timespec(
75 const struct timespec *nacl_timespec, 145 const struct timespec *nacl_timespec,
76 struct linux_abi_timespec *linux_timespec) { 146 struct linux_abi_timespec *linux_timespec) {
77 linux_timespec->tv_sec = nacl_timespec->tv_sec; 147 linux_timespec->tv_sec = nacl_timespec->tv_sec;
78 linux_timespec->tv_nsec = nacl_timespec->tv_nsec; 148 linux_timespec->tv_nsec = nacl_timespec->tv_nsec;
79 } 149 }
80 150
81 /* Converts the timespec struct from Linux's to NaCl's ABI. */ 151 /* Converts the timespec struct from Linux's to NaCl's ABI. */
82 static inline void linux_timespec_to_nacl_timespec( 152 static inline void linux_timespec_to_nacl_timespec(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 nacl_stat->st_rdev = 0; 184 nacl_stat->st_rdev = 0;
115 nacl_stat->st_size = linux_stat->st_size; 185 nacl_stat->st_size = linux_stat->st_size;
116 nacl_stat->st_blksize = 0; 186 nacl_stat->st_blksize = 0;
117 nacl_stat->st_blocks = 0; 187 nacl_stat->st_blocks = 0;
118 nacl_stat->st_atime = linux_stat->st_atime; 188 nacl_stat->st_atime = linux_stat->st_atime;
119 nacl_stat->st_mtime = linux_stat->st_mtime; 189 nacl_stat->st_mtime = linux_stat->st_mtime;
120 nacl_stat->st_ctime = linux_stat->st_ctime; 190 nacl_stat->st_ctime = linux_stat->st_ctime;
121 } 191 }
122 192
123 #endif 193 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698