30#if __has_include("google/protobuf/io/coded_stream.h")
31#include "google/protobuf/io/coded_stream.h"
48#if __has_include(<print>)
58static inline void* mempcpy(
void* dst,
const void* src,
size_t n) {
59 return static_cast<char*
>(memcpy(dst, src, n)) + n;
85#define OS_PATH_SEPARATORS "\\/"
86#define OS_PATH_SEPARATOR '\\'
87#define OS_PATH_SEPARATOR_STR "\\"
88#define ENV_PATH_SEPARATOR_STR ";"
91 return c ==
'\\' || c ==
'/';
102#define unlink ___xxx_unlink
104extern int adb_mkdir(
const std::string& path,
int mode);
106#define mkdir ___xxx_mkdir
108extern int adb_rename(
const char* oldpath,
const char* newpath);
111extern int adb_open(
const char* path,
int options);
112extern int adb_creat(
const char* path,
int mode);
131#define close ____xxx_close
142#define read ___xxx_read
145#define pread ___xxx_pread
152#define write ___xxx_write
155#define pwrite ___xxx_pwrite
162#define lseek ___xxx_lseek
165static inline int adb_open_mode(
const char* path,
int options,
int mode) {
170extern int unix_open(std::string_view path,
int options, ...);
171#define open ___xxx_unix_open
183#define isatty ___xxx_isatty
201#define accept ___xxx_accept
212#define setsockopt ___xxx_setsockopt
225 socklen_t msg_namelen;
229 size_t msg_controllen;
248#define poll ___xxx_poll
251 return isalpha(path[0]) && path[1] ==
':' && path[2] ==
'\\';
255extern DIR* adb_opendir(
const char* dirname);
256extern struct dirent* adb_readdir(DIR* dir);
257extern int adb_closedir(DIR* dir);
259extern int adb_utime(
const char *,
struct utimbuf *);
260extern int adb_chmod(
const char *,
int);
262extern int adb_vfprintf(FILE* stream,
const char*
format, va_list ap)
264extern int adb_vprintf(
const char*
format, va_list ap)
__attribute__((__format__(__printf__, 1, 0)));
265extern int adb_fprintf(FILE* stream,
const char*
format, ...)
267extern
int adb_printf(const
char*
format, ...)
__attribute__((__format__(__printf__, 1, 2)));
269extern
int adb_fputs(const
char* buf, FILE* stream);
270extern
int adb_fputc(
int ch, FILE* stream);
271extern
int adb_putchar(
int ch);
272extern
int adb_puts(const
char* buf);
273extern
size_t adb_fwrite(const
void* ptr,
size_t size,
size_t nmemb, FILE* stream);
275extern FILE* adb_fopen(const
char* f, const
char* m);
277extern
char* adb_getenv(const
char* name);
279extern
char* adb_getcwd(
char* buf,
int size);
282#define opendir adb_opendir
283#define readdir adb_readdir
284#define closedir adb_closedir
285#define rewinddir rewinddir_utf8_not_yet_implemented
286#define telldir telldir_utf8_not_yet_implemented
289inline void seekdir(DIR*,
long) {
290 extern int seekdir_utf8_not_yet_implemented;
291 seekdir_utf8_not_yet_implemented = 1;
294#define utime adb_utime
295#define chmod adb_chmod
297#define vfprintf adb_vfprintf
298#define vprintf adb_vprintf
299#define fprintf adb_fprintf
300#define printf adb_printf
301#define fputs adb_fputs
302#define fputc adb_fputc
305#define putc(c, s) adb_fputc(c, s)
306#define putchar adb_putchar
308#define fwrite adb_fwrite
310#define fopen adb_fopen
311#define freopen freopen_utf8_not_yet_implemented
313#define getenv adb_getenv
314#define putenv putenv_utf8_not_yet_implemented
315#define setenv setenv_utf8_not_yet_implemented
316#define unsetenv unsetenv_utf8_not_yet_implemented
318#define getcwd adb_getcwd
323 constexpr explicit Process(HANDLE h =
nullptr) : h_(h) {}
326 constexpr explicit operator bool()
const {
return h_ !=
nullptr; }
330 ::WaitForSingleObject(h_, INFINITE);
336 ::TerminateProcess(h_, -1);
354 std::initializer_list<int> fds_to_inherit = {});
360 NarrowArgs(
int argc,
wchar_t** argv);
363 inline char**
data() {
380 return static_cast<int>(
reinterpret_cast<INT_PTR
>(h));
383inline HANDLE cast_int_to_handle(
const int fd) {
385 return reinterpret_cast<HANDLE
>(
static_cast<INT_PTR
>(fd));
391class handle_deleter {
393 typedef HANDLE pointer;
395 void operator()(HANDLE h);
401typedef std::unique_ptr<HANDLE, handle_deleter> unique_handle;
405size_t ParseCompleteUTF8(
const char* first,
const char* last, std::vector<char>* remaining_bytes);
413#include <netinet/in.h>
414#include <netinet/tcp.h>
427#include <cutils/sockets.h>
429#define OS_PATH_SEPARATORS "/"
430#define OS_PATH_SEPARATOR '/'
431#define OS_PATH_SEPARATOR_STR "/"
432#define ENV_PATH_SEPARATOR_STR ":"
439 return fcntl(fd.
get(), F_GETFD);
444 if (flags >= 0 && (flags & FD_CLOEXEC) == 0) {
445 fcntl(fd.
get(), F_SETFD, flags | FD_CLOEXEC);
458static inline int unix_open(std::string_view path,
int options, ...) {
459 std::string zero_terminated(path.begin(), path.end());
460 if ((options & O_CREAT) == 0) {
465 va_start(args, options);
466 mode = va_arg(args,
int);
474static inline int adb_open_mode(
const char* pathname,
int options,
int mode) {
485static inline int adb_open(
const char* pathname,
int options) {
487 if (fd < 0)
return -1;
492#define open ___xxx_open
499#define shutdown ____xxx_shutdown
508#define close ____xxx_close
518 return gethostname(name, len);
522 return getlogin_r(buf, bufsize);
530#if defined(__APPLE__)
539 return read(fd.
get(), buf, len);
543#define read ___xxx_read
545#define pread ___xxx_pread
551static inline int adb_pwrite(
int fd,
const void* buf,
size_t len, off64_t offset) {
552#if defined(__APPLE__)
560#define write ___xxx_write
562#define pwrite ___xxx_pwrite
565#if defined(__APPLE__)
568 return lseek64(fd.
get(), pos, where);
572#define lseek ___xxx_lseek
578#define unlink ___xxx_unlink
580static inline int adb_creat(
const char* path,
int mode) {
583 if (fd < 0)
return -1;
589#define creat ___xxx_creat
594#define isatty ___xxx_isatty
599 *
error = strerror(errno);
619 socklen_t* addrlen) {
629#define accept ___xxx_accept
632 return getsockname(fd.
get(), sockaddr, addrlen);
636 return socket_get_local_port(fd.
get());
647#define unix_read adb_read
648#define unix_write adb_write
649#define unix_lseek adb_lseek
650#define unix_close adb_close
654 return pthread_setname_np(name.c_str());
659 strncpy(buf, name.c_str(),
sizeof(buf) - 1);
660 buf[
sizeof(buf) - 1] =
'\0';
661 return pthread_setname_np(pthread_self(), buf);
671#define setsockopt ___xxx_setsockopt
674 return socket(domain,
type, protocol);
678 return bind(fd.
get(), addr, namelen);
689 if (rc < 0)
return -1;
697#define socketpair ___xxx_socketpair
701 return sendmsg(fd.
get(), msg, flags);
705 ssize_t ret = recvmsg(fd.
get(), msg, flags);
715 return CMSG_FIRSTHDR(msgh);
719 return CMSG_NXTHDR(msgh, cmsg);
723 return CMSG_DATA(cmsg);
731#define poll ___xxx_poll
733static inline int adb_mkdir(
const std::string& path,
int mode) {
734 return mkdir(path.c_str(), mode);
738#define mkdir ___xxx_mkdir
740static inline int adb_rename(
const char* oldpath,
const char* newpath) {
741 return rename(oldpath, newpath);
745 return path[0] ==
'/';
762 constexpr explicit operator bool()
const {
return pid_ >= 0; }
784 std::initializer_list<int> fds_to_inherit = {});
Definition: sysdeps.h:757
pid_t pid_
Definition: sysdeps.h:780
void wait()
Definition: sysdeps.h:764
constexpr Process(pid_t pid)
Definition: sysdeps.h:759
void kill()
Definition: sysdeps.h:771
constexpr Process(Process &&other)
Definition: sysdeps.h:760
DISALLOW_COPY_AND_ASSIGN(Process)
#define error(format, args...)
Definition: fec_private.h:201
int status()
Definition: health.cpp:42
int SOCKET
Definition: in_process_tpm.cpp:29
char data[Size]
Definition: incremental_server.cpp:1
uint32_t size
Definition: io.h:2
#define PLOG(severity)
Definition: logging.h:235
#define TEMP_FAILURE_RETRY(exp)
Definition: macros.h:26
@ ERROR
Definition: logging.h:92
EventFormat format
Definition: kernel_log_server.cc:57
class incremental::File __attribute__
Definition: logging.h:464
uint8_t type
Definition: pairing_connection.h:0
Definition: unique_fd.h:292
int get() const
Definition: unique_fd.h:297
ssize_t adb_sendmsg(borrowed_fd fd, const adb_msghdr *msg, int flags)
Definition: sysdeps.h:700
static int adb_pread(borrowed_fd fd, void *buf, size_t len, off64_t offset)
Definition: sysdeps.h:529
cmsghdr adb_cmsghdr
Definition: sysdeps.h:712
ssize_t adb_recvmsg(borrowed_fd fd, adb_msghdr *msg, int flags)
Definition: sysdeps.h:704
#define creat
Definition: sysdeps.h:589
static int adb_rename(const char *oldpath, const char *newpath)
Definition: sysdeps.h:740
#define lseek
Definition: sysdeps.h:572
static bool adb_is_separator(char c)
Definition: sysdeps.h:434
static int adb_is_absolute_host_path(const char *path)
Definition: sysdeps.h:744
#define unlink
Definition: sysdeps.h:578
int network_connect(const std::string &host, int port, int type, int timeout, std::string *error)
Definition: network.cpp:136
static int adb_pwrite(int fd, const void *buf, size_t len, off64_t offset)
Definition: sysdeps.h:551
struct pollfd adb_pollfd
Definition: sysdeps.h:726
int adb_register_socket(int s)
Definition: sysdeps.h:513
static int adb_thread_setname(const std::string &name)
Definition: sysdeps.h:652
#define mkdir
Definition: sysdeps.h:738
#define setsockopt
Definition: sysdeps.h:671
#define accept
Definition: sysdeps.h:629
struct msghdr adb_msghdr
Definition: sysdeps.h:699
int network_inaddr_any_server(int port, int type, std::string *error)
Definition: sysdeps.h:604
static int adb_read(borrowed_fd fd, void *buf, size_t len)
Definition: sysdeps.h:525
#define pwrite
Definition: sysdeps.h:562
adb_cmsghdr * adb_CMSG_NXTHDR(adb_msghdr *msgh, adb_cmsghdr *cmsg)
Definition: sysdeps.h:718
#define pread
Definition: sysdeps.h:545
unsigned char * adb_CMSG_DATA(adb_cmsghdr *cmsg)
Definition: sysdeps.h:722
static int adb_poll(adb_pollfd *fds, size_t nfds, int timeout)
Definition: sysdeps.h:727
static int adb_setsockopt(borrowed_fd fd, int level, int optname, const void *optval, socklen_t optlen)
Definition: sysdeps.h:665
#define unix_write
Definition: sysdeps.h:648
#define unix_close
Definition: sysdeps.h:650
int _fd_set_error_str(int fd, std::string *error)
Definition: sysdeps.h:597
int adb_socket_get_local_port(borrowed_fd fd)
Definition: sysdeps.h:635
static int adb_get_os_handle(borrowed_fd fd)
Definition: sysdeps.h:748
static int adb_open_mode(const char *pathname, int options, int mode)
Definition: sysdeps.h:474
static int adb_socket(int domain, int type, int protocol)
Definition: sysdeps.h:673
int network_local_client(const char *name, int namespace_id, int type, std::string *error)
Definition: sysdeps.h:608
std::optional< ssize_t > network_peek(borrowed_fd fd)
Definition: sysdeps_unix.cpp:112
static int adb_bind(borrowed_fd fd, const sockaddr *addr, int namelen)
Definition: sysdeps.h:677
#define read
Definition: sysdeps.h:543
adb_cmsghdr * adb_CMSG_FIRSTHDR(adb_msghdr *msgh)
Definition: sysdeps.h:714
static int unix_open(std::string_view path, int options,...)
Definition: sysdeps.h:458
bool set_tcp_keepalive(borrowed_fd fd, int interval_sec)
Definition: sysdeps_unix.cpp:24
std::string GetOSVersion()
Definition: sysdeps_unix.cpp:105
#define poll
Definition: sysdeps.h:731
static int unix_socketpair(int d, int type, int protocol, int sv[2])
Definition: sysdeps.h:681
static int adb_open(const char *pathname, int options)
Definition: sysdeps.h:485
#define unix_read
Definition: sysdeps.h:647
Process adb_launch_process(std::string_view executable, std::vector< std::string > args, std::initializer_list< int > fds_to_inherit={})
Definition: sysdeps_unix.cpp:73
#define open
Definition: sysdeps.h:492
int adb_getsockname(borrowed_fd fd, struct sockaddr *sockaddr, socklen_t *addrlen)
Definition: sysdeps.h:631
static int unix_isatty(borrowed_fd fd)
Definition: sysdeps.h:591
static int cast_handle_to_int(int fd)
Definition: sysdeps.h:752
static int adb_creat(const char *path, int mode)
Definition: sysdeps.h:580
static void close_on_exec(borrowed_fd fd)
Definition: sysdeps.h:442
#define close
Definition: sysdeps.h:508
static int adb_unlink(const char *path)
Definition: sysdeps.h:574
int adb_close(int fd)
Definition: sysdeps.h:504
static int64_t adb_lseek(borrowed_fd fd, int64_t pos, int where)
Definition: sysdeps.h:564
#define socketpair
Definition: sysdeps.h:697
#define shutdown
Definition: sysdeps.h:499
static int adb_socket_accept(borrowed_fd serverfd, struct sockaddr *addr, socklen_t *addrlen)
Definition: sysdeps.h:618
#define write
Definition: sysdeps.h:560
#define unix_lseek
Definition: sysdeps.h:649
static int adb_socketpair(int sv[2])
Definition: sysdeps.h:685
static int adb_mkdir(const std::string &path, int mode)
Definition: sysdeps.h:733
static int unix_read_interruptible(borrowed_fd fd, void *buf, size_t len)
Definition: sysdeps.h:538
static int adb_write(borrowed_fd fd, const void *buf, size_t len)
Definition: sysdeps.h:547
static void disable_tcp_nagle(borrowed_fd fd)
Definition: sysdeps.h:788
#define isatty
Definition: sysdeps.h:594
int network_local_server(const char *name, int namespace_id, int type, std::string *error)
Definition: sysdeps.h:612
static int get_fd_flags(borrowed_fd fd)
Definition: sysdeps.h:438
static int adb_gethostname(char *name, size_t len)
Definition: sysdeps.h:517
static int adb_getlogin_r(char *buf, size_t bufsize)
Definition: sysdeps.h:521
static int adb_shutdown(borrowed_fd fd, int direction=SHUT_RDWR)
Definition: sysdeps.h:494
iovec adb_iovec
Definition: uio.h:38