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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc

Issue 23005005: [NaCl SDK] nacl_io: Add initial implementations of kill and signal (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <errno.h> 5 #include <errno.h>
6 6
7 #include "nacl_io/kernel_intercept.h" 7 #include "nacl_io/kernel_intercept.h"
8 #include "nacl_io/kernel_proxy.h" 8 #include "nacl_io/kernel_proxy.h"
9 #include "nacl_io/kernel_wrap.h" 9 #include "nacl_io/kernel_wrap.h"
10 #include "nacl_io/osmman.h" 10 #include "nacl_io/osmman.h"
11 #include "nacl_io/ossocket.h" 11 #include "nacl_io/ossocket.h"
12 #include "nacl_io/pepper_interface.h" 12 #include "nacl_io/pepper_interface.h"
13 #include "nacl_io/pepper_interface.h" 13 #include "nacl_io/pepper_interface.h"
14 #include "nacl_io/real_pepper_interface.h" 14 #include "nacl_io/real_pepper_interface.h"
15 15
16 using namespace nacl_io; 16 using namespace nacl_io;
17 17
18 #define ON_NOSYS_RETURN(x) \ 18 #define ON_NOSYS_RETURN(x) \
19 if (!ki_is_initialized()) { \ 19 if (!ki_is_initialized()) { \
20 errno = ENOSYS; \ 20 errno = ENOSYS; \
21 return x; \ 21 return x; \
22 } 22 }
23 23
24 static ScopedKernelProxy* s_scoped_kp;
24 static KernelProxy* s_kp; 25 static KernelProxy* s_kp;
26 static bool s_kp_owned;
25 27
26 void ki_init(void* kp) { 28 void ki_init(void* kp) {
27 ki_init_ppapi(kp, 0, NULL); 29 ki_init_ppapi(kp, 0, NULL);
28 } 30 }
29 31
30 void ki_init_ppapi(void* kp, 32 void ki_init_ppapi(void* kp,
31 PP_Instance instance, 33 PP_Instance instance,
32 PPB_GetInterface get_browser_interface) { 34 PPB_GetInterface get_browser_interface) {
33 kernel_wrap_init(); 35 kernel_wrap_init();
34 36
35 if (kp == NULL) kp = new KernelProxy(); 37 if (kp == NULL) {
36 s_kp = static_cast<KernelProxy*>(kp); 38 s_kp = new KernelProxy();
39 s_kp_owned = true;
40 } else {
41 s_kp = static_cast<KernelProxy*>(kp);
42 s_kp_owned = false;
43 }
44
45 s_scoped_kp = new ScopedKernelProxy(s_kp);
37 46
38 PepperInterface* ppapi = NULL; 47 PepperInterface* ppapi = NULL;
39 if (instance && get_browser_interface) 48 if (instance && get_browser_interface)
40 ppapi = new RealPepperInterface(instance, get_browser_interface); 49 ppapi = new RealPepperInterface(instance, get_browser_interface);
41 50
42 s_kp->Init(ppapi); 51 s_kp->Init(ppapi);
43 } 52 }
44 53
45 int ki_is_initialized() { 54 int ki_is_initialized() {
46 return s_kp != NULL; 55 return s_kp != NULL;
47 } 56 }
48 57
49 void ki_uninit() { 58 void ki_uninit() {
50 kernel_wrap_uninit(); 59 kernel_wrap_uninit();
60 if (s_kp_owned)
61 delete s_scoped_kp;
51 s_kp = NULL; 62 s_kp = NULL;
63 s_scoped_kp = NULL;
52 } 64 }
53 65
54 int ki_chdir(const char* path) { 66 int ki_chdir(const char* path) {
55 ON_NOSYS_RETURN(-1); 67 ON_NOSYS_RETURN(-1);
56 return s_kp->chdir(path); 68 return s_kp->chdir(path);
57 } 69 }
58 70
59 char* ki_getcwd(char* buf, size_t size) { 71 char* ki_getcwd(char* buf, size_t size) {
60 // gtest uses getcwd in a static initializer. If we haven't initialized the 72 // gtest uses getcwd in a static initializer. If we haven't initialized the
61 // kernel-intercept yet, just return ".". 73 // kernel-intercept yet, just return ".".
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 ON_NOSYS_RETURN(-1); 262 ON_NOSYS_RETURN(-1);
251 return s_kp->tcgetattr(fd, termios_p); 263 return s_kp->tcgetattr(fd, termios_p);
252 } 264 }
253 265
254 int ki_tcsetattr(int fd, int optional_actions, 266 int ki_tcsetattr(int fd, int optional_actions,
255 const struct termios *termios_p) { 267 const struct termios *termios_p) {
256 ON_NOSYS_RETURN(-1); 268 ON_NOSYS_RETURN(-1);
257 return s_kp->tcsetattr(fd, optional_actions, termios_p); 269 return s_kp->tcsetattr(fd, optional_actions, termios_p);
258 } 270 }
259 271
272 int ki_kill(pid_t pid, int sig) {
273 ON_NOSYS_RETURN(-1);
274 return s_kp->kill(pid, sig);
275 }
276
277 sighandler_t ki_signal(int signum, sighandler_t handler) {
278 ON_NOSYS_RETURN(SIG_ERR);
279 return s_kp->sigset(signum, handler);
280 }
281
282 sighandler_t ki_sigset(int signum, sighandler_t handler) {
283 ON_NOSYS_RETURN(SIG_ERR);
284 return s_kp->sigset(signum, handler);
285 }
286
260 #ifdef PROVIDES_SOCKET_API 287 #ifdef PROVIDES_SOCKET_API
261 // Socket Functions 288 // Socket Functions
262 int ki_accept(int fd, struct sockaddr* addr, socklen_t* len) { 289 int ki_accept(int fd, struct sockaddr* addr, socklen_t* len) {
263 return s_kp->accept(fd, addr, len); 290 return s_kp->accept(fd, addr, len);
264 } 291 }
265 292
266 int ki_bind(int fd, const struct sockaddr* addr, socklen_t len) { 293 int ki_bind(int fd, const struct sockaddr* addr, socklen_t len) {
267 return s_kp->bind(fd, addr, len); 294 return s_kp->bind(fd, addr, len);
268 } 295 }
269 296
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 } 353 }
327 354
328 int ki_socket(int domain, int type, int protocol) { 355 int ki_socket(int domain, int type, int protocol) {
329 return s_kp->socket(domain, type, protocol); 356 return s_kp->socket(domain, type, protocol);
330 } 357 }
331 358
332 int ki_socketpair(int domain, int type, int protocol, int* sv) { 359 int ki_socketpair(int domain, int type, int protocol, int* sv) {
333 return s_kp->socketpair(domain, type, protocol, sv); 360 return s_kp->socketpair(domain, type, protocol, sv);
334 } 361 }
335 #endif // PROVIDES_SOCKET_API 362 #endif // PROVIDES_SOCKET_API
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698