Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "nacl_io/kernel_proxy.h" | 5 #include "nacl_io/kernel_proxy.h" |
| 6 | 6 |
| 7 | 7 |
| 8 #include <assert.h> | 8 #include <assert.h> |
| 9 #include <errno.h> | 9 #include <errno.h> |
| 10 #include <fcntl.h> | 10 #include <fcntl.h> |
| 11 #include <limits.h> | 11 #include <limits.h> |
| 12 #include <poll.h> | 12 #include <poll.h> |
| 13 #include <pthread.h> | 13 #include <pthread.h> |
| 14 #include <stdio.h> | 14 #include <stdio.h> |
| 15 #include <string.h> | 15 #include <string.h> |
| 16 #include <sys/time.h> | 16 #include <sys/time.h> |
| 17 #include <unistd.h> | |
| 17 | 18 |
| 18 #include <iterator> | 19 #include <iterator> |
| 19 #include <string> | 20 #include <string> |
| 20 | 21 |
| 22 #include "nacl_io/dbgprint.h" | |
| 21 #include "nacl_io/host_resolver.h" | 23 #include "nacl_io/host_resolver.h" |
| 22 #include "nacl_io/kernel_handle.h" | 24 #include "nacl_io/kernel_handle.h" |
| 23 #include "nacl_io/kernel_wrap_real.h" | 25 #include "nacl_io/kernel_wrap_real.h" |
| 24 #include "nacl_io/mount.h" | 26 #include "nacl_io/mount.h" |
| 25 #include "nacl_io/mount_dev.h" | 27 #include "nacl_io/mount_dev.h" |
| 26 #include "nacl_io/mount_html5fs.h" | 28 #include "nacl_io/mount_html5fs.h" |
| 27 #include "nacl_io/mount_http.h" | 29 #include "nacl_io/mount_http.h" |
| 28 #include "nacl_io/mount_mem.h" | 30 #include "nacl_io/mount_mem.h" |
| 29 #include "nacl_io/mount_node.h" | 31 #include "nacl_io/mount_node.h" |
| 30 #include "nacl_io/mount_node_tcp.h" | 32 #include "nacl_io/mount_node_tcp.h" |
| 31 #include "nacl_io/mount_node_udp.h" | 33 #include "nacl_io/mount_node_udp.h" |
| 32 #include "nacl_io/mount_passthrough.h" | 34 #include "nacl_io/mount_passthrough.h" |
| 33 #include "nacl_io/osmman.h" | 35 #include "nacl_io/osmman.h" |
| 34 #include "nacl_io/ossocket.h" | 36 #include "nacl_io/ossocket.h" |
| 35 #include "nacl_io/osstat.h" | 37 #include "nacl_io/osstat.h" |
| 36 #include "nacl_io/path.h" | 38 #include "nacl_io/path.h" |
| 37 #include "nacl_io/pepper_interface.h" | 39 #include "nacl_io/pepper_interface.h" |
| 38 #include "nacl_io/typed_mount_factory.h" | 40 #include "nacl_io/typed_mount_factory.h" |
| 39 #include "sdk_util/auto_lock.h" | 41 #include "sdk_util/auto_lock.h" |
| 40 #include "sdk_util/ref_object.h" | 42 #include "sdk_util/ref_object.h" |
| 41 | 43 |
| 42 #ifndef MAXPATHLEN | 44 #ifndef MAXPATHLEN |
| 43 #define MAXPATHLEN 256 | 45 #define MAXPATHLEN 256 |
| 44 #endif | 46 #endif |
| 45 | 47 |
| 46 namespace nacl_io { | 48 namespace nacl_io { |
| 47 | 49 |
| 48 KernelProxy::KernelProxy() : dev_(0), ppapi_(NULL) { | 50 KernelProxy::KernelProxy() : dev_(0), ppapi_(NULL), |
| 51 sigwinch_handler_(SIG_IGN) { | |
| 49 } | 52 } |
| 50 | 53 |
| 51 KernelProxy::~KernelProxy() { | 54 KernelProxy::~KernelProxy() { |
| 52 // Clean up the MountFactories. | 55 // Clean up the MountFactories. |
| 53 for (MountFactoryMap_t::iterator i = factories_.begin(); | 56 for (MountFactoryMap_t::iterator i = factories_.begin(); |
| 54 i != factories_.end(); | 57 i != factories_.end(); |
| 55 ++i) { | 58 ++i) { |
| 56 delete i->second; | 59 delete i->second; |
| 57 } | 60 } |
| 58 | 61 |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 | 706 |
| 704 error = handle->node()->Tcsetattr(optional_actions, termios_p); | 707 error = handle->node()->Tcsetattr(optional_actions, termios_p); |
| 705 if (error) { | 708 if (error) { |
| 706 errno = error; | 709 errno = error; |
| 707 return -1; | 710 return -1; |
| 708 } | 711 } |
| 709 | 712 |
| 710 return 0; | 713 return 0; |
| 711 } | 714 } |
| 712 | 715 |
| 716 int KernelProxy::kill(pid_t pid, int sig) { | |
| 717 // Currently we don't even pretend that other processes exist | |
| 718 // so we can only send a signal to outselves. For kill(2) | |
| 719 // pid 0 means the current process group and -1 means all the | |
| 720 // processes we have permission to send signals to. | |
| 721 if (pid != getpid() && pid != -1 && pid != 0) { | |
| 722 errno = ESRCH; | |
| 723 return -1; | |
| 724 } | |
| 725 | |
| 726 switch (sig) { | |
|
binji
2013/08/21 17:42:01
is there danger in calling default handlers if the
Sam Clegg
2013/08/22 03:32:45
I'm not sure what you mean.
binji
2013/08/22 18:09:36
I just mean, if we had a generic SignalHandler cla
| |
| 727 case SIGWINCH: | |
| 728 //dbgprintf("kill SIGWINCH handler=%p\n", sigwinch_handler_); | |
| 729 if (sigwinch_handler_ != SIG_IGN) | |
| 730 sigwinch_handler_(SIGWINCH); | |
| 731 break; | |
| 732 | |
| 733 case SIGUSR1: | |
| 734 case SIGUSR2: | |
| 735 break; | |
| 736 | |
| 737 default: | |
| 738 errno = EINVAL; | |
| 739 return -1; | |
| 740 } | |
| 741 | |
| 742 return 0; | |
| 743 } | |
| 744 | |
| 745 sighandler_t KernelProxy::signal(int signum, sighandler_t handler) { | |
| 746 return sigset(signum, handler); | |
|
binji
2013/08/21 17:42:01
if sigset and signal are identical, I'd rather see
Sam Clegg
2013/08/22 03:32:45
They are not quite identical. But the differences
| |
| 747 } | |
| 748 | |
| 749 sighandler_t KernelProxy::sigset(int signum, sighandler_t handler) { | |
| 750 switch (signum) { | |
| 751 // Handled signals. | |
| 752 case SIGWINCH: { | |
| 753 sighandler_t old_value = sigwinch_handler_; | |
|
binji
2013/08/21 17:42:01
I know you're only handling SIGWINCH, but you migh
Sam Clegg
2013/08/22 03:32:45
KILL and STOP can never be handled, aside from tha
| |
| 754 if (handler == SIG_DFL) | |
| 755 handler = SIG_IGN; | |
| 756 //dbgprintf("registering handler: %p\n", handler); | |
|
binji
2013/08/21 17:42:01
remove
Sam Clegg
2013/08/22 03:32:45
Done.
| |
| 757 sigwinch_handler_ = handler; | |
| 758 return old_value; | |
| 759 } | |
| 760 | |
| 761 // Known signals | |
| 762 case SIGHUP: | |
| 763 case SIGINT: | |
| 764 case SIGKILL: | |
| 765 case SIGPIPE: | |
| 766 case SIGPOLL: | |
| 767 case SIGPROF: | |
| 768 case SIGTERM: | |
| 769 case SIGCHLD: | |
| 770 case SIGURG: | |
| 771 case SIGFPE: | |
| 772 case SIGILL: | |
| 773 case SIGQUIT: | |
| 774 case SIGSEGV: | |
| 775 case SIGTRAP: | |
| 776 if (handler == SIG_DFL) | |
| 777 return SIG_DFL; | |
| 778 break; | |
| 779 } | |
| 780 | |
| 781 errno = EINVAL; | |
| 782 return SIG_ERR; | |
| 783 } | |
| 784 | |
| 713 #ifdef PROVIDES_SOCKET_API | 785 #ifdef PROVIDES_SOCKET_API |
| 714 | 786 |
| 715 int KernelProxy::select(int nfds, fd_set* readfds, fd_set* writefds, | 787 int KernelProxy::select(int nfds, fd_set* readfds, fd_set* writefds, |
| 716 fd_set* exceptfds, struct timeval* timeout) { | 788 fd_set* exceptfds, struct timeval* timeout) { |
| 717 ScopedEventListener listener(new EventListener); | 789 ScopedEventListener listener(new EventListener); |
| 718 std::vector<struct pollfd> fds; | 790 std::vector<struct pollfd> fds; |
| 719 | 791 |
| 720 fd_set readout, writeout, exceptout; | 792 fd_set readout, writeout, exceptout; |
| 721 | 793 |
| 722 FD_ZERO(&readout); | 794 FD_ZERO(&readout); |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1246 errno = ENOTSOCK; | 1318 errno = ENOTSOCK; |
| 1247 return -1; | 1319 return -1; |
| 1248 } | 1320 } |
| 1249 | 1321 |
| 1250 return 0; | 1322 return 0; |
| 1251 } | 1323 } |
| 1252 | 1324 |
| 1253 #endif // PROVIDES_SOCKET_API | 1325 #endif // PROVIDES_SOCKET_API |
| 1254 | 1326 |
| 1255 } // namespace_nacl_io | 1327 } // namespace_nacl_io |
| OLD | NEW |