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