Loading adb/sysdeps.h +30 −0 Original line number Original line Diff line number Diff line Loading @@ -91,11 +91,14 @@ extern int adb_mkdir(const std::string& path, int mode); extern int adb_open(const char* path, int options); extern int adb_open(const char* path, int options); extern int adb_creat(const char* path, int mode); extern int adb_creat(const char* path, int mode); extern int adb_read(borrowed_fd fd, void* buf, int len); extern int adb_read(borrowed_fd fd, void* buf, int len); extern int adb_pread(borrowed_fd fd, void* buf, int len, off64_t offset); extern int adb_write(borrowed_fd fd, const void* buf, int len); extern int adb_write(borrowed_fd fd, const void* buf, int len); extern int adb_pwrite(borrowed_fd fd, const void* buf, int len, off64_t offset); extern int64_t adb_lseek(borrowed_fd fd, int64_t pos, int where); extern int64_t adb_lseek(borrowed_fd fd, int64_t pos, int where); extern int adb_shutdown(borrowed_fd fd, int direction = SHUT_RDWR); extern int adb_shutdown(borrowed_fd fd, int direction = SHUT_RDWR); extern int adb_close(int fd); extern int adb_close(int fd); extern int adb_register_socket(SOCKET s); extern int adb_register_socket(SOCKET s); extern HANDLE adb_get_os_handle(borrowed_fd fd); // See the comments for the !defined(_WIN32) version of unix_close(). // See the comments for the !defined(_WIN32) version of unix_close(). static __inline__ int unix_close(int fd) { static __inline__ int unix_close(int fd) { Loading @@ -115,6 +118,9 @@ static __inline__ int unix_read(borrowed_fd fd, void* buf, size_t len) { #undef read #undef read #define read ___xxx_read #define read ___xxx_read #undef pread #define pread ___xxx_pread // See the comments for the !defined(_WIN32) version of unix_write(). // See the comments for the !defined(_WIN32) version of unix_write(). static __inline__ int unix_write(borrowed_fd fd, const void* buf, size_t len) { static __inline__ int unix_write(borrowed_fd fd, const void* buf, size_t len) { return write(fd.get(), buf, len); return write(fd.get(), buf, len); Loading @@ -122,6 +128,9 @@ static __inline__ int unix_write(borrowed_fd fd, const void* buf, size_t len) { #undef write #undef write #define write ___xxx_write #define write ___xxx_write #undef pwrite #define pwrite ___xxx_pwrite // See the comments for the !defined(_WIN32) version of unix_lseek(). // See the comments for the !defined(_WIN32) version of unix_lseek(). static __inline__ int unix_lseek(borrowed_fd fd, int pos, int where) { static __inline__ int unix_lseek(borrowed_fd fd, int pos, int where) { return lseek(fd.get(), pos, where); return lseek(fd.get(), pos, where); Loading Loading @@ -415,6 +424,14 @@ static __inline__ int adb_read(borrowed_fd fd, void* buf, size_t len) { return TEMP_FAILURE_RETRY(read(fd.get(), buf, len)); return TEMP_FAILURE_RETRY(read(fd.get(), buf, len)); } } static __inline__ int adb_pread(int fd, void* buf, size_t len, off64_t offset) { #if defined(__APPLE__) return TEMP_FAILURE_RETRY(pread(fd, buf, len, offset)); #else return TEMP_FAILURE_RETRY(pread64(fd, buf, len, offset)); #endif } // Like unix_read(), but does not handle EINTR. // Like unix_read(), but does not handle EINTR. static __inline__ int unix_read_interruptible(borrowed_fd fd, void* buf, size_t len) { static __inline__ int unix_read_interruptible(borrowed_fd fd, void* buf, size_t len) { return read(fd.get(), buf, len); return read(fd.get(), buf, len); Loading @@ -422,12 +439,25 @@ static __inline__ int unix_read_interruptible(borrowed_fd fd, void* buf, size_t #undef read #undef read #define read ___xxx_read #define read ___xxx_read #undef pread #define pread ___xxx_pread static __inline__ int adb_write(borrowed_fd fd, const void* buf, size_t len) { static __inline__ int adb_write(borrowed_fd fd, const void* buf, size_t len) { return TEMP_FAILURE_RETRY(write(fd.get(), buf, len)); return TEMP_FAILURE_RETRY(write(fd.get(), buf, len)); } } static __inline__ int adb_pwrite(int fd, const void* buf, size_t len, off64_t offset) { #if defined(__APPLE__) return TEMP_FAILURE_RETRY(pwrite(fd, buf, len, offset)); #else return TEMP_FAILURE_RETRY(pwrite64(fd, buf, len, offset)); #endif } #undef write #undef write #define write ___xxx_write #define write ___xxx_write #undef pwrite #define pwrite ___xxx_pwrite static __inline__ int64_t adb_lseek(borrowed_fd fd, int64_t pos, int where) { static __inline__ int64_t adb_lseek(borrowed_fd fd, int64_t pos, int where) { #if defined(__APPLE__) #if defined(__APPLE__) Loading adb/sysdeps_win32.cpp +68 −12 Original line number Original line Diff line number Diff line Loading @@ -60,6 +60,7 @@ typedef struct FHClassRec_ { int (*_fh_read)(FH, void*, int); int (*_fh_read)(FH, void*, int); int (*_fh_write)(FH, const void*, int); int (*_fh_write)(FH, const void*, int); int (*_fh_writev)(FH, const adb_iovec*, int); int (*_fh_writev)(FH, const adb_iovec*, int); intptr_t (*_fh_get_os_handle)(FH); } FHClassRec; } FHClassRec; static void _fh_file_init(FH); static void _fh_file_init(FH); Loading @@ -68,14 +69,11 @@ static int64_t _fh_file_lseek(FH, int64_t, int); static int _fh_file_read(FH, void*, int); static int _fh_file_read(FH, void*, int); static int _fh_file_write(FH, const void*, int); static int _fh_file_write(FH, const void*, int); static int _fh_file_writev(FH, const adb_iovec*, int); static int _fh_file_writev(FH, const adb_iovec*, int); static intptr_t _fh_file_get_os_handle(FH f); static const FHClassRec _fh_file_class = { static const FHClassRec _fh_file_class = { _fh_file_init, _fh_file_init, _fh_file_close, _fh_file_lseek, _fh_file_read, _fh_file_close, _fh_file_write, _fh_file_writev, _fh_file_get_os_handle, _fh_file_lseek, _fh_file_read, _fh_file_write, _fh_file_writev, }; }; static void _fh_socket_init(FH); static void _fh_socket_init(FH); Loading @@ -84,14 +82,11 @@ static int64_t _fh_socket_lseek(FH, int64_t, int); static int _fh_socket_read(FH, void*, int); static int _fh_socket_read(FH, void*, int); static int _fh_socket_write(FH, const void*, int); static int _fh_socket_write(FH, const void*, int); static int _fh_socket_writev(FH, const adb_iovec*, int); static int _fh_socket_writev(FH, const adb_iovec*, int); static intptr_t _fh_socket_get_os_handle(FH f); static const FHClassRec _fh_socket_class = { static const FHClassRec _fh_socket_class = { _fh_socket_init, _fh_socket_init, _fh_socket_close, _fh_socket_lseek, _fh_socket_read, _fh_socket_close, _fh_socket_write, _fh_socket_writev, _fh_socket_get_os_handle, _fh_socket_lseek, _fh_socket_read, _fh_socket_write, _fh_socket_writev, }; }; #if defined(assert) #if defined(assert) Loading Loading @@ -331,6 +326,10 @@ static int64_t _fh_file_lseek(FH f, int64_t pos, int origin) { return li.QuadPart; return li.QuadPart; } } static intptr_t _fh_file_get_os_handle(FH f) { return reinterpret_cast<intptr_t>(f->u.handle); } /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /***** *****/ /***** *****/ Loading Loading @@ -456,6 +455,26 @@ int adb_read(borrowed_fd fd, void* buf, int len) { return f->clazz->_fh_read(f, buf, len); return f->clazz->_fh_read(f, buf, len); } } int adb_pread(borrowed_fd fd, void* buf, int len, off64_t offset) { OVERLAPPED overlapped = {}; overlapped.Offset = static_cast<DWORD>(offset); overlapped.OffsetHigh = static_cast<DWORD>(offset >> 32); DWORD bytes_read; if (!::ReadFile(adb_get_os_handle(fd), buf, static_cast<DWORD>(len), &bytes_read, &overlapped)) { D("adb_pread: could not read %d bytes from FD %d", len, fd.get()); switch (::GetLastError()) { case ERROR_IO_PENDING: errno = EAGAIN; return -1; default: errno = EINVAL; return -1; } } return static_cast<int>(bytes_read); } int adb_write(borrowed_fd fd, const void* buf, int len) { int adb_write(borrowed_fd fd, const void* buf, int len) { FH f = _fh_from_int(fd, __func__); FH f = _fh_from_int(fd, __func__); Loading @@ -478,6 +497,25 @@ ssize_t adb_writev(borrowed_fd fd, const adb_iovec* iov, int iovcnt) { return f->clazz->_fh_writev(f, iov, iovcnt); return f->clazz->_fh_writev(f, iov, iovcnt); } } int adb_pwrite(borrowed_fd fd, const void* buf, int len, off64_t offset) { OVERLAPPED params = {}; params.Offset = static_cast<DWORD>(offset); params.OffsetHigh = static_cast<DWORD>(offset >> 32); DWORD bytes_written = 0; if (!::WriteFile(adb_get_os_handle(fd), buf, len, &bytes_written, ¶ms)) { D("adb_pwrite: could not write %d bytes to FD %d", len, fd.get()); switch (::GetLastError()) { case ERROR_IO_PENDING: errno = EAGAIN; return -1; default: errno = EINVAL; return -1; } } return static_cast<int>(bytes_written); } int64_t adb_lseek(borrowed_fd fd, int64_t pos, int where) { int64_t adb_lseek(borrowed_fd fd, int64_t pos, int where) { FH f = _fh_from_int(fd, __func__); FH f = _fh_from_int(fd, __func__); if (!f) { if (!f) { Loading @@ -500,6 +538,20 @@ int adb_close(int fd) { return 0; return 0; } } HANDLE adb_get_os_handle(borrowed_fd fd) { FH f = _fh_from_int(fd, __func__); if (!f) { errno = EBADF; return nullptr; } D("adb_get_os_handle: %s", f->name); const intptr_t intptr_handle = f->clazz->_fh_get_os_handle(f); const HANDLE handle = reinterpret_cast<const HANDLE>(intptr_handle); return handle; } /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /***** *****/ /***** *****/ Loading Loading @@ -694,6 +746,10 @@ static int _fh_socket_writev(FH f, const adb_iovec* iov, int iovcnt) { return static_cast<int>(bytes_written); return static_cast<int>(bytes_written); } } static intptr_t _fh_socket_get_os_handle(FH f) { return f->u.socket; } /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /***** *****/ /***** *****/ Loading Loading
adb/sysdeps.h +30 −0 Original line number Original line Diff line number Diff line Loading @@ -91,11 +91,14 @@ extern int adb_mkdir(const std::string& path, int mode); extern int adb_open(const char* path, int options); extern int adb_open(const char* path, int options); extern int adb_creat(const char* path, int mode); extern int adb_creat(const char* path, int mode); extern int adb_read(borrowed_fd fd, void* buf, int len); extern int adb_read(borrowed_fd fd, void* buf, int len); extern int adb_pread(borrowed_fd fd, void* buf, int len, off64_t offset); extern int adb_write(borrowed_fd fd, const void* buf, int len); extern int adb_write(borrowed_fd fd, const void* buf, int len); extern int adb_pwrite(borrowed_fd fd, const void* buf, int len, off64_t offset); extern int64_t adb_lseek(borrowed_fd fd, int64_t pos, int where); extern int64_t adb_lseek(borrowed_fd fd, int64_t pos, int where); extern int adb_shutdown(borrowed_fd fd, int direction = SHUT_RDWR); extern int adb_shutdown(borrowed_fd fd, int direction = SHUT_RDWR); extern int adb_close(int fd); extern int adb_close(int fd); extern int adb_register_socket(SOCKET s); extern int adb_register_socket(SOCKET s); extern HANDLE adb_get_os_handle(borrowed_fd fd); // See the comments for the !defined(_WIN32) version of unix_close(). // See the comments for the !defined(_WIN32) version of unix_close(). static __inline__ int unix_close(int fd) { static __inline__ int unix_close(int fd) { Loading @@ -115,6 +118,9 @@ static __inline__ int unix_read(borrowed_fd fd, void* buf, size_t len) { #undef read #undef read #define read ___xxx_read #define read ___xxx_read #undef pread #define pread ___xxx_pread // See the comments for the !defined(_WIN32) version of unix_write(). // See the comments for the !defined(_WIN32) version of unix_write(). static __inline__ int unix_write(borrowed_fd fd, const void* buf, size_t len) { static __inline__ int unix_write(borrowed_fd fd, const void* buf, size_t len) { return write(fd.get(), buf, len); return write(fd.get(), buf, len); Loading @@ -122,6 +128,9 @@ static __inline__ int unix_write(borrowed_fd fd, const void* buf, size_t len) { #undef write #undef write #define write ___xxx_write #define write ___xxx_write #undef pwrite #define pwrite ___xxx_pwrite // See the comments for the !defined(_WIN32) version of unix_lseek(). // See the comments for the !defined(_WIN32) version of unix_lseek(). static __inline__ int unix_lseek(borrowed_fd fd, int pos, int where) { static __inline__ int unix_lseek(borrowed_fd fd, int pos, int where) { return lseek(fd.get(), pos, where); return lseek(fd.get(), pos, where); Loading Loading @@ -415,6 +424,14 @@ static __inline__ int adb_read(borrowed_fd fd, void* buf, size_t len) { return TEMP_FAILURE_RETRY(read(fd.get(), buf, len)); return TEMP_FAILURE_RETRY(read(fd.get(), buf, len)); } } static __inline__ int adb_pread(int fd, void* buf, size_t len, off64_t offset) { #if defined(__APPLE__) return TEMP_FAILURE_RETRY(pread(fd, buf, len, offset)); #else return TEMP_FAILURE_RETRY(pread64(fd, buf, len, offset)); #endif } // Like unix_read(), but does not handle EINTR. // Like unix_read(), but does not handle EINTR. static __inline__ int unix_read_interruptible(borrowed_fd fd, void* buf, size_t len) { static __inline__ int unix_read_interruptible(borrowed_fd fd, void* buf, size_t len) { return read(fd.get(), buf, len); return read(fd.get(), buf, len); Loading @@ -422,12 +439,25 @@ static __inline__ int unix_read_interruptible(borrowed_fd fd, void* buf, size_t #undef read #undef read #define read ___xxx_read #define read ___xxx_read #undef pread #define pread ___xxx_pread static __inline__ int adb_write(borrowed_fd fd, const void* buf, size_t len) { static __inline__ int adb_write(borrowed_fd fd, const void* buf, size_t len) { return TEMP_FAILURE_RETRY(write(fd.get(), buf, len)); return TEMP_FAILURE_RETRY(write(fd.get(), buf, len)); } } static __inline__ int adb_pwrite(int fd, const void* buf, size_t len, off64_t offset) { #if defined(__APPLE__) return TEMP_FAILURE_RETRY(pwrite(fd, buf, len, offset)); #else return TEMP_FAILURE_RETRY(pwrite64(fd, buf, len, offset)); #endif } #undef write #undef write #define write ___xxx_write #define write ___xxx_write #undef pwrite #define pwrite ___xxx_pwrite static __inline__ int64_t adb_lseek(borrowed_fd fd, int64_t pos, int where) { static __inline__ int64_t adb_lseek(borrowed_fd fd, int64_t pos, int where) { #if defined(__APPLE__) #if defined(__APPLE__) Loading
adb/sysdeps_win32.cpp +68 −12 Original line number Original line Diff line number Diff line Loading @@ -60,6 +60,7 @@ typedef struct FHClassRec_ { int (*_fh_read)(FH, void*, int); int (*_fh_read)(FH, void*, int); int (*_fh_write)(FH, const void*, int); int (*_fh_write)(FH, const void*, int); int (*_fh_writev)(FH, const adb_iovec*, int); int (*_fh_writev)(FH, const adb_iovec*, int); intptr_t (*_fh_get_os_handle)(FH); } FHClassRec; } FHClassRec; static void _fh_file_init(FH); static void _fh_file_init(FH); Loading @@ -68,14 +69,11 @@ static int64_t _fh_file_lseek(FH, int64_t, int); static int _fh_file_read(FH, void*, int); static int _fh_file_read(FH, void*, int); static int _fh_file_write(FH, const void*, int); static int _fh_file_write(FH, const void*, int); static int _fh_file_writev(FH, const adb_iovec*, int); static int _fh_file_writev(FH, const adb_iovec*, int); static intptr_t _fh_file_get_os_handle(FH f); static const FHClassRec _fh_file_class = { static const FHClassRec _fh_file_class = { _fh_file_init, _fh_file_init, _fh_file_close, _fh_file_lseek, _fh_file_read, _fh_file_close, _fh_file_write, _fh_file_writev, _fh_file_get_os_handle, _fh_file_lseek, _fh_file_read, _fh_file_write, _fh_file_writev, }; }; static void _fh_socket_init(FH); static void _fh_socket_init(FH); Loading @@ -84,14 +82,11 @@ static int64_t _fh_socket_lseek(FH, int64_t, int); static int _fh_socket_read(FH, void*, int); static int _fh_socket_read(FH, void*, int); static int _fh_socket_write(FH, const void*, int); static int _fh_socket_write(FH, const void*, int); static int _fh_socket_writev(FH, const adb_iovec*, int); static int _fh_socket_writev(FH, const adb_iovec*, int); static intptr_t _fh_socket_get_os_handle(FH f); static const FHClassRec _fh_socket_class = { static const FHClassRec _fh_socket_class = { _fh_socket_init, _fh_socket_init, _fh_socket_close, _fh_socket_lseek, _fh_socket_read, _fh_socket_close, _fh_socket_write, _fh_socket_writev, _fh_socket_get_os_handle, _fh_socket_lseek, _fh_socket_read, _fh_socket_write, _fh_socket_writev, }; }; #if defined(assert) #if defined(assert) Loading Loading @@ -331,6 +326,10 @@ static int64_t _fh_file_lseek(FH f, int64_t pos, int origin) { return li.QuadPart; return li.QuadPart; } } static intptr_t _fh_file_get_os_handle(FH f) { return reinterpret_cast<intptr_t>(f->u.handle); } /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /***** *****/ /***** *****/ Loading Loading @@ -456,6 +455,26 @@ int adb_read(borrowed_fd fd, void* buf, int len) { return f->clazz->_fh_read(f, buf, len); return f->clazz->_fh_read(f, buf, len); } } int adb_pread(borrowed_fd fd, void* buf, int len, off64_t offset) { OVERLAPPED overlapped = {}; overlapped.Offset = static_cast<DWORD>(offset); overlapped.OffsetHigh = static_cast<DWORD>(offset >> 32); DWORD bytes_read; if (!::ReadFile(adb_get_os_handle(fd), buf, static_cast<DWORD>(len), &bytes_read, &overlapped)) { D("adb_pread: could not read %d bytes from FD %d", len, fd.get()); switch (::GetLastError()) { case ERROR_IO_PENDING: errno = EAGAIN; return -1; default: errno = EINVAL; return -1; } } return static_cast<int>(bytes_read); } int adb_write(borrowed_fd fd, const void* buf, int len) { int adb_write(borrowed_fd fd, const void* buf, int len) { FH f = _fh_from_int(fd, __func__); FH f = _fh_from_int(fd, __func__); Loading @@ -478,6 +497,25 @@ ssize_t adb_writev(borrowed_fd fd, const adb_iovec* iov, int iovcnt) { return f->clazz->_fh_writev(f, iov, iovcnt); return f->clazz->_fh_writev(f, iov, iovcnt); } } int adb_pwrite(borrowed_fd fd, const void* buf, int len, off64_t offset) { OVERLAPPED params = {}; params.Offset = static_cast<DWORD>(offset); params.OffsetHigh = static_cast<DWORD>(offset >> 32); DWORD bytes_written = 0; if (!::WriteFile(adb_get_os_handle(fd), buf, len, &bytes_written, ¶ms)) { D("adb_pwrite: could not write %d bytes to FD %d", len, fd.get()); switch (::GetLastError()) { case ERROR_IO_PENDING: errno = EAGAIN; return -1; default: errno = EINVAL; return -1; } } return static_cast<int>(bytes_written); } int64_t adb_lseek(borrowed_fd fd, int64_t pos, int where) { int64_t adb_lseek(borrowed_fd fd, int64_t pos, int where) { FH f = _fh_from_int(fd, __func__); FH f = _fh_from_int(fd, __func__); if (!f) { if (!f) { Loading @@ -500,6 +538,20 @@ int adb_close(int fd) { return 0; return 0; } } HANDLE adb_get_os_handle(borrowed_fd fd) { FH f = _fh_from_int(fd, __func__); if (!f) { errno = EBADF; return nullptr; } D("adb_get_os_handle: %s", f->name); const intptr_t intptr_handle = f->clazz->_fh_get_os_handle(f); const HANDLE handle = reinterpret_cast<const HANDLE>(intptr_handle); return handle; } /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /***** *****/ /***** *****/ Loading Loading @@ -694,6 +746,10 @@ static int _fh_socket_writev(FH f, const adb_iovec* iov, int iovcnt) { return static_cast<int>(bytes_written); return static_cast<int>(bytes_written); } } static intptr_t _fh_socket_get_os_handle(FH f) { return f->u.socket; } /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /**************************************************************************/ /***** *****/ /***** *****/ Loading