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/unix_socketpair_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 |
| 1817 if (AF_INET == domain || AF_INET6 == domain) { | |
| 1818 errno = EOPNOTSUPP; | |
| 1819 return -1; | |
| 1820 } | |
| 1821 | |
| 1816 // Catch-22: We don't support AF_UNIX, but any other AF doesn't support | 1822 // Catch-22: We don't support AF_UNIX, but any other AF doesn't support |
| 1817 // socket pairs. Thus, this function always fails. | 1823 // socket pairs. Thus, this function always fails. |
| 1818 if (AF_UNIX != domain) { | 1824 if (AF_UNIX == domain) { |
| 1825 int open_flags = O_RDWR; | |
| 1826 | |
| 1827 #if defined(SOCK_CLOEXEC) | |
| 1828 if (type & SOCK_CLOEXEC) { | |
| 1829 #if defined(O_CLOEXEC) | |
| 1830 // The NaCl newlib version of fcntl.h doesn't currently define | |
| 1831 // O_CLOEXEC. | |
| 1832 // TODO(sbc): remove this guard once it gets added. | |
| 1833 open_flags |= O_CLOEXEC; | |
| 1834 #endif | |
| 1835 type &= ~SOCK_CLOEXEC; | |
| 1836 } | |
| 1837 #endif | |
| 1838 | |
| 1839 #if defined(SOCK_NONBLOCK) | |
| 1840 if (type & SOCK_NONBLOCK) { | |
| 1841 open_flags |= O_NONBLOCK; | |
| 1842 type &= ~SOCK_NONBLOCK; | |
| 1843 } | |
| 1844 #endif | |
| 1845 | |
| 1846 UnixSocketpairNode* socket = new UnixSocketpairNode(stream_fs_.get()); | |
| 1847 Error rtn = socket->Init(O_RDWR); | |
| 1848 if (rtn != 0) { | |
| 1849 errno = rtn; | |
| 1850 return -1; | |
| 1851 } | |
| 1852 ScopedNode node0(socket); | |
| 1853 socket = new UnixSocketpairNode(stream_fs_.get(), *socket); | |
| 1854 rtn = socket->Init(O_RDWR); | |
| 1855 if (rtn != 0) { | |
| 1856 errno = rtn; | |
| 1857 return -1; | |
| 1858 } | |
| 1859 ScopedNode node1(socket); | |
| 1860 ScopedKernelHandle handle0(new KernelHandle(stream_fs_, node0)); | |
| 1861 rtn = handle0->Init(open_flags); | |
| 1862 if (rtn != 0) { | |
| 1863 errno = rtn; | |
| 1864 return -1; | |
| 1865 } | |
| 1866 ScopedKernelHandle handle1(new KernelHandle(stream_fs_, node1)); | |
| 1867 rtn = handle1->Init(open_flags); | |
| 1868 if (rtn != 0) { | |
| 1869 errno = rtn; | |
| 1870 return -1; | |
| 1871 } | |
| 1872 | |
| 1873 sv[0] = AllocateFD(handle0); | |
| 1874 sv[1] = AllocateFD(handle1); | |
| 1875 | |
| 1876 return 0; | |
| 1877 } else { | |
| 1819 errno = EPROTONOSUPPORT; | 1878 errno = EPROTONOSUPPORT; |
| 1820 return -1; | 1879 return -1; |
|
Sam Clegg
2015/09/17 09:40:39
Can you use early return if domain != AF_UNIX then
avallee
2015/09/17 19:00:31
Done.
| |
| 1821 } | 1880 } |
| 1822 | 1881 |
| 1823 if (AF_INET != domain && AF_INET6 != domain) { | |
| 1824 errno = EAFNOSUPPORT; | |
| 1825 return -1; | |
| 1826 } | |
| 1827 | |
| 1828 // We cannot reach this point. | 1882 // We cannot reach this point. |
| 1829 errno = ENOSYS; | 1883 errno = ENOSYS; |
| 1830 return -1; | 1884 return -1; |
| 1831 } | 1885 } |
| 1832 | 1886 |
| 1833 int KernelProxy::AcquireSocketHandle(int fd, ScopedKernelHandle* handle) { | 1887 int KernelProxy::AcquireSocketHandle(int fd, ScopedKernelHandle* handle) { |
| 1834 Error error = AcquireHandle(fd, handle); | 1888 Error error = AcquireHandle(fd, handle); |
| 1835 | 1889 |
| 1836 if (error) { | 1890 if (error) { |
| 1837 errno = error; | 1891 errno = error; |
| 1838 return -1; | 1892 return -1; |
| 1839 } | 1893 } |
| 1840 | 1894 |
| 1841 if ((handle->get()->node_->GetType() & S_IFSOCK) == 0) { | 1895 if ((handle->get()->node_->GetType() & S_IFSOCK) == 0) { |
| 1842 errno = ENOTSOCK; | 1896 errno = ENOTSOCK; |
| 1843 return -1; | 1897 return -1; |
| 1844 } | 1898 } |
| 1845 | 1899 |
| 1846 return 0; | 1900 return 0; |
| 1847 } | 1901 } |
| 1848 | 1902 |
| 1849 #endif // PROVIDES_SOCKET_API | 1903 #endif // PROVIDES_SOCKET_API |
| 1850 | 1904 |
| 1851 } // namespace_nacl_io | 1905 } // namespace_nacl_io |
| OLD | NEW |