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 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <limits.h> | 10 #include <limits.h> |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "nacl_io/osinttypes.h" | 32 #include "nacl_io/osinttypes.h" |
| 33 #include "nacl_io/osmman.h" | 33 #include "nacl_io/osmman.h" |
| 34 #include "nacl_io/ossocket.h" | 34 #include "nacl_io/ossocket.h" |
| 35 #include "nacl_io/osstat.h" | 35 #include "nacl_io/osstat.h" |
| 36 #include "nacl_io/passthroughfs/passthrough_fs.h" | 36 #include "nacl_io/passthroughfs/passthrough_fs.h" |
| 37 #include "nacl_io/path.h" | 37 #include "nacl_io/path.h" |
| 38 #include "nacl_io/pepper_interface.h" | 38 #include "nacl_io/pepper_interface.h" |
| 39 #include "nacl_io/pipe/pipe_node.h" | 39 #include "nacl_io/pipe/pipe_node.h" |
| 40 #include "nacl_io/socket/tcp_node.h" | 40 #include "nacl_io/socket/tcp_node.h" |
| 41 #include "nacl_io/socket/udp_node.h" | 41 #include "nacl_io/socket/udp_node.h" |
| 42 #include "nacl_io/socket/unixsocket_node.h" | |
| 42 #include "nacl_io/stream/stream_fs.h" | 43 #include "nacl_io/stream/stream_fs.h" |
| 43 #include "nacl_io/typed_fs_factory.h" | 44 #include "nacl_io/typed_fs_factory.h" |
| 44 #include "sdk_util/auto_lock.h" | 45 #include "sdk_util/auto_lock.h" |
| 45 #include "sdk_util/ref_object.h" | 46 #include "sdk_util/ref_object.h" |
| 46 #include "sdk_util/string_util.h" | 47 #include "sdk_util/string_util.h" |
| 47 | 48 |
| 48 #ifndef MAXPATHLEN | 49 #ifndef MAXPATHLEN |
| 49 #define MAXPATHLEN 256 | 50 #define MAXPATHLEN 256 |
| 50 #endif | 51 #endif |
| 51 | 52 |
| (...skipping 1754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1806 | 1807 |
| 1807 return AllocateFD(handle); | 1808 return AllocateFD(handle); |
| 1808 } | 1809 } |
| 1809 | 1810 |
| 1810 int KernelProxy::socketpair(int domain, int type, int protocol, int* sv) { | 1811 int KernelProxy::socketpair(int domain, int type, int protocol, int* sv) { |
| 1811 if (NULL == sv) { | 1812 if (NULL == sv) { |
| 1812 errno = EFAULT; | 1813 errno = EFAULT; |
| 1813 return -1; | 1814 return -1; |
| 1814 } | 1815 } |
| 1815 | 1816 |
| 1816 // Catch-22: We don't support AF_UNIX, but any other AF doesn't support | 1817 if (AF_INET == domain || AF_INET6 == domain) { |
| 1817 // socket pairs. Thus, this function always fails. | 1818 errno = EOPNOTSUPP; |
| 1819 return -1; | |
| 1820 } | |
| 1821 | |
| 1818 if (AF_UNIX != domain) { | 1822 if (AF_UNIX != domain) { |
| 1819 errno = EPROTONOSUPPORT; | 1823 errno = EPROTONOSUPPORT; |
|
Sam Clegg
2015/09/22 17:53:44
Can you combine the these two conditionals? Is E
avallee
2015/09/22 20:25:06
Good point, I read the socketpair page many times
| |
| 1820 return -1; | 1824 return -1; |
| 1821 } | 1825 } |
| 1822 | 1826 |
| 1823 if (AF_INET != domain && AF_INET6 != domain) { | 1827 int open_flags = O_RDWR; |
| 1824 errno = EAFNOSUPPORT; | 1828 |
| 1829 #if defined(SOCK_CLOEXEC) | |
| 1830 if (type & SOCK_CLOEXEC) { | |
| 1831 #if defined(O_CLOEXEC) | |
| 1832 // The NaCl newlib version of fcntl.h doesn't currently define | |
| 1833 // O_CLOEXEC. | |
| 1834 // TODO(sbc): remove this guard once it gets added. | |
| 1835 open_flags |= O_CLOEXEC; | |
| 1836 #endif | |
| 1837 type &= ~SOCK_CLOEXEC; | |
| 1838 } | |
| 1839 #endif | |
| 1840 | |
| 1841 #if defined(SOCK_NONBLOCK) | |
| 1842 if (type & SOCK_NONBLOCK) { | |
| 1843 open_flags |= O_NONBLOCK; | |
| 1844 type &= ~SOCK_NONBLOCK; | |
| 1845 } | |
| 1846 #endif | |
| 1847 | |
| 1848 UnixSocketNode* socket = new UnixSocketNode(stream_fs_.get()); | |
| 1849 Error rtn = socket->Init(O_RDWR); | |
| 1850 if (rtn != 0) { | |
| 1851 errno = rtn; | |
| 1852 return -1; | |
| 1853 } | |
| 1854 ScopedNode node0(socket); | |
| 1855 socket = new UnixSocketNode(stream_fs_.get(), *socket); | |
| 1856 rtn = socket->Init(O_RDWR); | |
| 1857 if (rtn != 0) { | |
| 1858 errno = rtn; | |
| 1859 return -1; | |
| 1860 } | |
| 1861 ScopedNode node1(socket); | |
| 1862 ScopedKernelHandle handle0(new KernelHandle(stream_fs_, node0)); | |
| 1863 rtn = handle0->Init(open_flags); | |
| 1864 if (rtn != 0) { | |
| 1865 errno = rtn; | |
| 1866 return -1; | |
| 1867 } | |
| 1868 ScopedKernelHandle handle1(new KernelHandle(stream_fs_, node1)); | |
| 1869 rtn = handle1->Init(open_flags); | |
| 1870 if (rtn != 0) { | |
| 1871 errno = rtn; | |
| 1825 return -1; | 1872 return -1; |
| 1826 } | 1873 } |
| 1827 | 1874 |
| 1828 // We cannot reach this point. | 1875 sv[0] = AllocateFD(handle0); |
| 1829 errno = ENOSYS; | 1876 sv[1] = AllocateFD(handle1); |
| 1830 return -1; | 1877 |
| 1878 return 0; | |
| 1831 } | 1879 } |
| 1832 | 1880 |
| 1833 int KernelProxy::AcquireSocketHandle(int fd, ScopedKernelHandle* handle) { | 1881 int KernelProxy::AcquireSocketHandle(int fd, ScopedKernelHandle* handle) { |
| 1834 Error error = AcquireHandle(fd, handle); | 1882 Error error = AcquireHandle(fd, handle); |
| 1835 | 1883 |
| 1836 if (error) { | 1884 if (error) { |
| 1837 errno = error; | 1885 errno = error; |
| 1838 return -1; | 1886 return -1; |
| 1839 } | 1887 } |
| 1840 | 1888 |
| 1841 if ((handle->get()->node_->GetType() & S_IFSOCK) == 0) { | 1889 if ((handle->get()->node_->GetType() & S_IFSOCK) == 0) { |
| 1842 errno = ENOTSOCK; | 1890 errno = ENOTSOCK; |
| 1843 return -1; | 1891 return -1; |
| 1844 } | 1892 } |
| 1845 | 1893 |
| 1846 return 0; | 1894 return 0; |
| 1847 } | 1895 } |
| 1848 | 1896 |
| 1849 #endif // PROVIDES_SOCKET_API | 1897 #endif // PROVIDES_SOCKET_API |
| 1850 | 1898 |
| 1851 } // namespace_nacl_io | 1899 } // namespace_nacl_io |
| OLD | NEW |