diff options
96 files changed, 810 insertions, 1052 deletions
diff --git a/adb/SERVICES.TXT b/adb/SERVICES.TXT index 7f85dc3..63000f2 100644 --- a/adb/SERVICES.TXT +++ b/adb/SERVICES.TXT @@ -240,3 +240,20 @@ sync: This starts the file synchronisation service, used to implement "adb push" and "adb pull". Since this service is pretty complex, it will be detailed in a companion document named SYNC.TXT + +reverse:<forward-command> + This implements the 'adb reverse' feature, i.e. the ability to reverse + socket connections from a device to the host. <forward-command> is one + of the forwarding commands that are described above, as in: + + list-forward + forward:<local>;<remote> + forward:norebind:<local>;<remote> + killforward-all + killforward:<local> + + Note that in this case, <local> corresponds to the socket on the device + and <remote> corresponds to the socket on the host. + + The output of reverse:list-forward is the same as host:list-forward + except that <serial> will be just 'host'. @@ -318,7 +318,18 @@ static size_t fill_connect_data(char *buf, size_t bufsize) #endif } -static void send_msg_with_okay(int fd, char* msg, size_t msglen) { +#if !ADB_HOST +static void send_msg_with_header(int fd, const char* msg, size_t msglen) { + char header[5]; + if (msglen > 0xffff) + msglen = 0xffff; + snprintf(header, sizeof(header), "%04x", (unsigned)msglen); + writex(fd, header, 4); + writex(fd, msg, msglen); +} +#endif + +static void send_msg_with_okay(int fd, const char* msg, size_t msglen) { char header[9]; if (msglen > 0xffff) msglen = 0xffff; @@ -1428,6 +1439,120 @@ int adb_main(int is_daemon, int server_port) return 0; } +// Try to handle a network forwarding request. +// This returns 1 on success, 0 on failure, and -1 to indicate this is not +// a forwarding-related request. +int handle_forward_request(const char* service, transport_type ttype, char* serial, int reply_fd) +{ + if (!strcmp(service, "list-forward")) { + // Create the list of forward redirections. + int buffer_size = format_listeners(NULL, 0); + // Add one byte for the trailing zero. + char* buffer = malloc(buffer_size + 1); + if (buffer == NULL) { + sendfailmsg(reply_fd, "not enough memory"); + return 1; + } + (void) format_listeners(buffer, buffer_size + 1); +#if ADB_HOST + send_msg_with_okay(reply_fd, buffer, buffer_size); +#else + send_msg_with_header(reply_fd, buffer, buffer_size); +#endif + free(buffer); + return 1; + } + + if (!strcmp(service, "killforward-all")) { + remove_all_listeners(); +#if ADB_HOST + /* On the host: 1st OKAY is connect, 2nd OKAY is status */ + adb_write(reply_fd, "OKAY", 4); +#endif + adb_write(reply_fd, "OKAY", 4); + return 1; + } + + if (!strncmp(service, "forward:",8) || + !strncmp(service, "killforward:",12)) { + char *local, *remote, *err; + int r; + atransport *transport; + + int createForward = strncmp(service, "kill", 4); + int no_rebind = 0; + + local = strchr(service, ':') + 1; + + // Handle forward:norebind:<local>... here + if (createForward && !strncmp(local, "norebind:", 9)) { + no_rebind = 1; + local = strchr(local, ':') + 1; + } + + remote = strchr(local,';'); + + if (createForward) { + // Check forward: parameter format: '<local>;<remote>' + if(remote == 0) { + sendfailmsg(reply_fd, "malformed forward spec"); + return 1; + } + + *remote++ = 0; + if((local[0] == 0) || (remote[0] == 0) || (remote[0] == '*')) { + sendfailmsg(reply_fd, "malformed forward spec"); + return 1; + } + } else { + // Check killforward: parameter format: '<local>' + if (local[0] == 0) { + sendfailmsg(reply_fd, "malformed forward spec"); + return 1; + } + } + + transport = acquire_one_transport(CS_ANY, ttype, serial, &err); + if (!transport) { + sendfailmsg(reply_fd, err); + return 1; + } + + if (createForward) { + r = install_listener(local, remote, transport, no_rebind); + } else { + r = remove_listener(local, transport); + } + if(r == 0) { +#if ADB_HOST + /* On the host: 1st OKAY is connect, 2nd OKAY is status */ + writex(reply_fd, "OKAY", 4); +#endif + writex(reply_fd, "OKAY", 4); + return 1; + } + + if (createForward) { + const char* message; + switch (r) { + case INSTALL_STATUS_CANNOT_BIND: + message = "cannot bind to socket"; + break; + case INSTALL_STATUS_CANNOT_REBIND: + message = "cannot rebind existing socket"; + break; + default: + message = "internal error"; + } + sendfailmsg(reply_fd, message); + } else { + sendfailmsg(reply_fd, "cannot remove listener"); + } + return 1; + } + return 0; +} + int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s) { atransport *transport = NULL; @@ -1548,97 +1673,9 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r } #endif // ADB_HOST - if(!strcmp(service,"list-forward")) { - // Create the list of forward redirections. - int buffer_size = format_listeners(NULL, 0); - // Add one byte for the trailing zero. - char* buffer = malloc(buffer_size+1); - (void) format_listeners(buffer, buffer_size+1); - send_msg_with_okay(reply_fd, buffer, buffer_size); - free(buffer); - return 0; - } - - if (!strcmp(service,"killforward-all")) { - remove_all_listeners(); - adb_write(reply_fd, "OKAYOKAY", 8); - return 0; - } - - if(!strncmp(service,"forward:",8) || - !strncmp(service,"killforward:",12)) { - char *local, *remote, *err; - int r; - atransport *transport; - - int createForward = strncmp(service,"kill",4); - int no_rebind = 0; - - local = strchr(service, ':') + 1; - - // Handle forward:norebind:<local>... here - if (createForward && !strncmp(local, "norebind:", 9)) { - no_rebind = 1; - local = strchr(local, ':') + 1; - } - - remote = strchr(local,';'); - - if (createForward) { - // Check forward: parameter format: '<local>;<remote>' - if(remote == 0) { - sendfailmsg(reply_fd, "malformed forward spec"); - return 0; - } - - *remote++ = 0; - if((local[0] == 0) || (remote[0] == 0) || (remote[0] == '*')){ - sendfailmsg(reply_fd, "malformed forward spec"); - return 0; - } - } else { - // Check killforward: parameter format: '<local>' - if (local[0] == 0) { - sendfailmsg(reply_fd, "malformed forward spec"); - return 0; - } - } - - transport = acquire_one_transport(CS_ANY, ttype, serial, &err); - if (!transport) { - sendfailmsg(reply_fd, err); - return 0; - } - - if (createForward) { - r = install_listener(local, remote, transport, no_rebind); - } else { - r = remove_listener(local, transport); - } - if(r == 0) { - /* 1st OKAY is connect, 2nd OKAY is status */ - writex(reply_fd, "OKAYOKAY", 8); - return 0; - } - - if (createForward) { - const char* message; - switch (r) { - case INSTALL_STATUS_CANNOT_BIND: - message = "cannot bind to socket"; - break; - case INSTALL_STATUS_CANNOT_REBIND: - message = "cannot rebind existing socket"; - break; - default: - message = "internal error"; - } - sendfailmsg(reply_fd, message); - } else { - sendfailmsg(reply_fd, "cannot remove listener"); - } - return 0; - } + int ret = handle_forward_request(service, ttype, serial, reply_fd); + if (ret >= 0) + return ret - 1; if(!strncmp(service,"get-state",strlen("get-state"))) { transport = acquire_one_transport(CS_ANY, ttype, serial, NULL); @@ -323,6 +323,8 @@ asocket* create_jdwp_tracker_service_socket(); int create_jdwp_connection_fd(int jdwp_pid); #endif +int handle_forward_request(const char* service, transport_type ttype, char* serial, int reply_fd); + #if !ADB_HOST typedef enum { BACKUP, diff --git a/adb/commandline.c b/adb/commandline.c index 241cefc..3970ab1 100644 --- a/adb/commandline.c +++ b/adb/commandline.c @@ -136,6 +136,19 @@ void help() " if <local> is already forwarded\n" " adb forward --remove <local> - remove a specific forward socket connection\n" " adb forward --remove-all - remove all forward socket connections\n" + " adb reverse --list - list all reverse socket connections from device\n" + " adb reverse <remote> <local> - reverse socket connections\n" + " reverse specs are one of:\n" + " tcp:<port>\n" + " localabstract:<unix domain socket name>\n" + " localreserved:<unix domain socket name>\n" + " localfilesystem:<unix domain socket name>\n" + " adb reverse --norebind <remote> <local>\n" + " - same as 'adb reverse <remote> <local>' but fails\n" + " if <remote> is already reversed.\n" + " adb reverse --remove <remote>\n" + " - remove a specific reversed socket connection\n" + " adb reverse --remove-all - remove all reversed socket connections from device\n" " adb jdwp - list PIDs of processes hosting a JDWP transport\n" " adb install [-l] [-r] [-s] [--algo <algorithm name> --key <hex-encoded key> --iv <hex-encoded iv>] <file>\n" " - push this package file to the device and install it\n" @@ -1299,8 +1312,11 @@ top: return 0; } - if(!strcmp(argv[0], "forward")) { + if(!strcmp(argv[0], "forward") || + !strcmp(argv[0], "reverse")) + { char host_prefix[64]; + char reverse = (char) !strcmp(argv[0], "reverse"); char remove = 0; char remove_all = 0; char list = 0; @@ -1329,15 +1345,19 @@ top: } // Determine the <host-prefix> for this command. - if (serial) { - snprintf(host_prefix, sizeof host_prefix, "host-serial:%s", - serial); - } else if (ttype == kTransportUsb) { - snprintf(host_prefix, sizeof host_prefix, "host-usb"); - } else if (ttype == kTransportLocal) { - snprintf(host_prefix, sizeof host_prefix, "host-local"); + if (reverse) { + snprintf(host_prefix, sizeof host_prefix, "reverse"); } else { - snprintf(host_prefix, sizeof host_prefix, "host"); + if (serial) { + snprintf(host_prefix, sizeof host_prefix, "host-serial:%s", + serial); + } else if (ttype == kTransportUsb) { + snprintf(host_prefix, sizeof host_prefix, "host-usb"); + } else if (ttype == kTransportLocal) { + snprintf(host_prefix, sizeof host_prefix, "host-local"); + } else { + snprintf(host_prefix, sizeof host_prefix, "host"); + } } // Implement forward --list diff --git a/adb/services.c b/adb/services.c index 5b63a43..ebe84bb 100644 --- a/adb/services.c +++ b/adb/services.c @@ -154,6 +154,17 @@ cleanup: adb_close(fd); } +void reverse_service(int fd, void* arg) +{ + const char* command = arg; + + if (handle_forward_request(command, kTransportAny, NULL, fd) < 0) { + sendfailmsg(fd, "not a reverse forwarding command"); + } + free(arg); + adb_close(fd); +} + #endif static int create_service_thread(void (*func)(int, void *), void *cookie) @@ -398,6 +409,16 @@ int service_to_fd(const char *name) ret = create_service_thread(restart_tcp_service, (void *) (uintptr_t) port); } else if(!strncmp(name, "usb:", 4)) { ret = create_service_thread(restart_usb_service, NULL); + } else if (!strncmp(name, "reverse:", 8)) { + char* cookie = strdup(name + 8); + if (cookie == NULL) { + ret = -1; + } else { + ret = create_service_thread(reverse_service, cookie); + if (ret < 0) { + free(cookie); + } + } #endif } if (ret >= 0) { @@ -460,7 +481,7 @@ static void connect_device(char* host, char* buffer, int buffer_size) snprintf(serial, sizeof(serial), "%s:%d", hostbuf, port); - fd = socket_network_client(hostbuf, port, SOCK_STREAM); + fd = socket_network_client_timeout(hostbuf, port, SOCK_STREAM, 10); if (fd < 0) { snprintf(buffer, buffer_size, "unable to connect to %s:%d", host, port); return; diff --git a/adb/sysdeps.h b/adb/sysdeps.h index 4033b72..ba4306f 100644 --- a/adb/sysdeps.h +++ b/adb/sysdeps.h @@ -169,6 +169,8 @@ extern void* load_file(const char* pathname, unsigned* psize); /* normally provided by <cutils/sockets.h> */ extern int socket_loopback_client(int port, int type); extern int socket_network_client(const char *host, int port, int type); +extern int socket_network_client_timeout(const char *host, int port, int type, + int timeout); extern int socket_loopback_server(int port, int type); extern int socket_inaddr_any_server(int port, int type); diff --git a/adb/sysdeps_win32.c b/adb/sysdeps_win32.c index b0cb048..29f58ec 100644 --- a/adb/sysdeps_win32.c +++ b/adb/sysdeps_win32.c @@ -701,6 +701,13 @@ int socket_network_client(const char *host, int port, int type) } +int socket_network_client_timeout(const char *host, int port, int type, int timeout) +{ + // TODO: implement timeouts for Windows. + return socket_network_client(host, port, type); +} + + int socket_inaddr_any_server(int port, int type) { FH f = _fh_alloc( &_fh_socket_class ); diff --git a/adb/usb_vendors.c b/adb/usb_vendors.c index 0c46a0c..c7e0ad5 100755 --- a/adb/usb_vendors.c +++ b/adb/usb_vendors.c @@ -51,7 +51,9 @@ // BYD's USB Vendor ID #define VENDOR_ID_BYD 0x1D91 // Compal's USB Vendor ID -#define VENDOR_ID_COMPAL 0x1219 +#define VENDOR_ID_COMPAL 0x04B7 +// Compalcomm's USB Vendor ID +#define VENDOR_ID_COMPALCOMM 0x1219 // Dell's USB Vendor ID #define VENDOR_ID_DELL 0x413c // ECS's USB Vendor ID @@ -170,6 +172,8 @@ #define VENDOR_ID_TI 0x0451 // Toshiba's USB Vendor ID #define VENDOR_ID_TOSHIBA 0x0930 +// Unowhy's USB Vendor ID +#define VENDOR_ID_UNOWHY 0x2A49 // Vizio's USB Vendor ID #define VENDOR_ID_VIZIO 0xE040 // Wacom's USB Vendor ID @@ -195,6 +199,7 @@ int builtInVendorIds[] = { VENDOR_ID_ASUS, VENDOR_ID_BYD, VENDOR_ID_COMPAL, + VENDOR_ID_COMPALCOMM, VENDOR_ID_DELL, VENDOR_ID_ECS, VENDOR_ID_EMERGING_TECH, @@ -254,6 +259,7 @@ int builtInVendorIds[] = { VENDOR_ID_TELEEPOCH, VENDOR_ID_TI, VENDOR_ID_TOSHIBA, + VENDOR_ID_UNOWHY, VENDOR_ID_VIZIO, VENDOR_ID_WACOM, VENDOR_ID_XIAOMI, diff --git a/cpio/Android.mk b/cpio/Android.mk index 5184463..575beb2 100644 --- a/cpio/Android.mk +++ b/cpio/Android.mk @@ -8,6 +8,8 @@ LOCAL_SRC_FILES := \ LOCAL_MODULE := mkbootfs +LOCAL_CFLAGS := -Werror + include $(BUILD_HOST_EXECUTABLE) $(call dist-for-goals,dist_files,$(LOCAL_BUILT_MODULE)) diff --git a/cpio/mkbootfs.c b/cpio/mkbootfs.c index 7d3740c..7175749 100644 --- a/cpio/mkbootfs.c +++ b/cpio/mkbootfs.c @@ -78,8 +78,9 @@ static void fix_stat(const char *path, struct stat *s) s->st_mode = empty_path_config->mode | (s->st_mode & ~07777); } else { // Use the compiled-in fs_config() function. - - fs_config(path, S_ISDIR(s->st_mode), &s->st_uid, &s->st_gid, &s->st_mode, &capabilities); + unsigned st_mode = s->st_mode; + fs_config(path, S_ISDIR(s->st_mode), &s->st_uid, &s->st_gid, &st_mode, &capabilities); + s->st_mode = (typeof(s->st_mode)) st_mode; } } diff --git a/debuggerd/crasher.c b/debuggerd/crasher.c index 01ce0be..4721da9 100644 --- a/debuggerd/crasher.c +++ b/debuggerd/crasher.c @@ -144,6 +144,9 @@ static int do_action(const char* arg) close(pipe_fds[0]); write(pipe_fds[1], "oops", 4); return EXIT_SUCCESS; + } else if (!strcmp(arg, "SIGTRAP")) { + raise(SIGTRAP); + return EXIT_SUCCESS; } else if (!strcmp(arg, "heap-usage")) { abuse_heap(); } @@ -164,6 +167,7 @@ static int do_action(const char* arg) fprintf(stderr, " LOG_ALWAYS_FATAL_IF call LOG_ALWAYS_FATAL\n"); fprintf(stderr, " SIGPIPE cause a SIGPIPE\n"); fprintf(stderr, " SIGSEGV cause a SIGSEGV (synonym: crash)\n"); + fprintf(stderr, " SIGTRAP cause a SIGTRAP\n"); fprintf(stderr, "prefix any of the above with 'thread-' to not run\n"); fprintf(stderr, "on the process' main thread.\n"); return EXIT_SUCCESS; diff --git a/debuggerd/debuggerd.cpp b/debuggerd/debuggerd.cpp index 76bd7a3..3726c38 100644 --- a/debuggerd/debuggerd.cpp +++ b/debuggerd/debuggerd.cpp @@ -54,97 +54,56 @@ struct debugger_request_t { int32_t original_si_code; }; -static int write_string(const char* file, const char* string) { - int len; - int fd; - ssize_t amt; - fd = open(file, O_RDWR); - len = strlen(string); - if (fd < 0) - return -errno; - amt = write(fd, string, len); - close(fd); - return amt >= 0 ? 0 : -errno; -} - -static void init_debug_led() { - // trout leds - write_string("/sys/class/leds/red/brightness", "0"); - write_string("/sys/class/leds/green/brightness", "0"); - write_string("/sys/class/leds/blue/brightness", "0"); - write_string("/sys/class/leds/red/device/blink", "0"); - // sardine leds - write_string("/sys/class/leds/left/cadence", "0,0"); -} +static void wait_for_user_action(pid_t pid) { + // Find out the name of the process that crashed. + char path[64]; + snprintf(path, sizeof(path), "/proc/%d/exe", pid); -static void enable_debug_led() { - // trout leds - write_string("/sys/class/leds/red/brightness", "255"); - // sardine leds - write_string("/sys/class/leds/left/cadence", "1,0"); -} + char exe[PATH_MAX]; + int count; + if ((count = readlink(path, exe, sizeof(exe) - 1)) == -1) { + LOG("readlink('%s') failed: %s", path, strerror(errno)); + strlcpy(exe, "unknown", sizeof(exe)); + } else { + exe[count] = '\0'; + } -static void disable_debug_led() { - // trout leds - write_string("/sys/class/leds/red/brightness", "0"); - // sardine leds - write_string("/sys/class/leds/left/cadence", "0,0"); -} + // Turn "/system/bin/app_process" into "app_process". + // gdbserver doesn't cope with full paths (though we should fix that + // and remove this). + char* name = strrchr(exe, '/'); + if (name == NULL) { + name = exe; // No '/' found. + } else { + ++name; // Skip the '/'. + } -static void wait_for_user_action(pid_t pid) { - // First log a helpful message + // Explain how to attach the debugger. LOG( "********************************************************\n" - "* Process %d has been suspended while crashing. To\n" - "* attach gdbserver for a gdb connection on port 5039\n" + "* Process %d has been suspended while crashing.\n" + "* To attach gdbserver for a gdb connection on port 5039\n" "* and start gdbclient:\n" "*\n" - "* gdbclient app_process :5039 %d\n" + "* gdbclient %s :5039 %d\n" "*\n" - "* Wait for gdb to start, then press HOME or VOLUME DOWN key\n" + "* Wait for gdb to start, then press the VOLUME DOWN key\n" "* to let the process continue crashing.\n" "********************************************************\n", - pid, pid); + pid, name, pid); - // wait for HOME or VOLUME DOWN key + // Wait for VOLUME DOWN. if (init_getevent() == 0) { - int ms = 1200 / 10; - int dit = 1; - int dah = 3*dit; - int _ = -dit; - int ___ = 3*_; - int _______ = 7*_; - const int codes[] = { - dit,_,dit,_,dit,___,dah,_,dah,_,dah,___,dit,_,dit,_,dit,_______ - }; - size_t s = 0; - input_event e; - bool done = false; - init_debug_led(); - enable_debug_led(); - do { - int timeout = abs(codes[s]) * ms; - int res = get_event(&e, timeout); - if (res == 0) { - if (e.type == EV_KEY - && (e.code == KEY_HOME || e.code == KEY_VOLUMEDOWN) - && e.value == 0) { - done = true; - } - } else if (res == 1) { - if (++s >= sizeof(codes)/sizeof(*codes)) - s = 0; - if (codes[s] > 0) { - enable_debug_led(); - } else { - disable_debug_led(); + while (true) { + input_event e; + if (get_event(&e, -1) == 0) { + if (e.type == EV_KEY && e.code == KEY_VOLUMEDOWN && e.value == 0) { + break; } } - } while (!done); + } uninit_getevent(); } - // don't forget to turn debug led off - disable_debug_led(); LOG("debuggerd resuming process %d", pid); } @@ -322,15 +281,16 @@ static void handle_request(int fd) { } break; - case SIGILL: case SIGABRT: case SIGBUS: case SIGFPE: - case SIGSEGV: + case SIGILL: case SIGPIPE: + case SIGSEGV: #ifdef SIGSTKFLT case SIGSTKFLT: #endif + case SIGTRAP: XLOG("stopped -- fatal signal\n"); // Send a SIGSTOP to the process to make all of // the non-signaled threads stop moving. Without @@ -406,38 +366,36 @@ static void handle_request(int fd) { } static int do_server() { - int s; - struct sigaction act; - int logsocket = -1; - - // debuggerd crashes can't be reported to debuggerd. Reset all of the - // crash handlers. - signal(SIGILL, SIG_DFL); + // debuggerd crashes can't be reported to debuggerd. + // Reset all of the crash handlers. signal(SIGABRT, SIG_DFL); signal(SIGBUS, SIG_DFL); signal(SIGFPE, SIG_DFL); + signal(SIGILL, SIG_DFL); signal(SIGSEGV, SIG_DFL); #ifdef SIGSTKFLT signal(SIGSTKFLT, SIG_DFL); #endif + signal(SIGTRAP, SIG_DFL); // Ignore failed writes to closed sockets signal(SIGPIPE, SIG_IGN); - logsocket = socket_local_client("logd", ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_DGRAM); + int logsocket = socket_local_client("logd", ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_DGRAM); if (logsocket < 0) { logsocket = -1; } else { fcntl(logsocket, F_SETFD, FD_CLOEXEC); } + struct sigaction act; act.sa_handler = SIG_DFL; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask,SIGCHLD); act.sa_flags = SA_NOCLDWAIT; sigaction(SIGCHLD, &act, 0); - s = socket_local_server(DEBUGGER_SOCKET_NAME, ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM); + int s = socket_local_server(DEBUGGER_SOCKET_NAME, ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM); if (s < 0) return 1; fcntl(s, F_SETFD, FD_CLOEXEC); diff --git a/debuggerd/mips/machine.cpp b/debuggerd/mips/machine.cpp index ab34182..5c82d4d 100644 --- a/debuggerd/mips/machine.cpp +++ b/debuggerd/mips/machine.cpp @@ -32,10 +32,22 @@ #define R(x) (static_cast<unsigned int>(x)) +// The MIPS uapi ptrace.h has the wrong definition for pt_regs. PTRACE_GETREGS +// writes 64-bit quantities even though the public struct uses 32-bit ones. +struct pt_regs_mips_t { + uint64_t regs[32]; + uint64_t lo; + uint64_t hi; + uint64_t cp0_epc; + uint64_t cp0_badvaddr; + uint64_t cp0_status; + uint64_t cp0_cause; +}; + // If configured to do so, dump memory around *all* registers // for the crashing thread. void dump_memory_and_code(log_t* log, pid_t tid, int scope_flags) { - pt_regs r; + pt_regs_mips_t r; if (ptrace(PTRACE_GETREGS, tid, 0, &r)) { return; } @@ -78,7 +90,7 @@ void dump_memory_and_code(log_t* log, pid_t tid, int scope_flags) { } void dump_registers(log_t* log, pid_t tid, int scope_flags) { - pt_regs r; + pt_regs_mips_t r; if(ptrace(PTRACE_GETREGS, tid, 0, &r)) { _LOG(log, scope_flags, "cannot get registers: %s\n", strerror(errno)); return; diff --git a/debuggerd/tombstone.cpp b/debuggerd/tombstone.cpp index d0cefc7..cdaa09f 100755 --- a/debuggerd/tombstone.cpp +++ b/debuggerd/tombstone.cpp @@ -31,9 +31,10 @@ #include <private/android_filesystem_config.h> +#include <cutils/properties.h> #include <log/log.h> #include <log/logger.h> -#include <cutils/properties.h> +#include <log/logprint.h> #include <backtrace/Backtrace.h> #include <backtrace/BacktraceMap.h> @@ -57,10 +58,10 @@ static bool signal_has_si_addr(int sig) { switch (sig) { - case SIGILL: + case SIGBUS: case SIGFPE: + case SIGILL: case SIGSEGV: - case SIGBUS: return true; default: return false; @@ -69,16 +70,17 @@ static bool signal_has_si_addr(int sig) { static const char* get_signame(int sig) { switch(sig) { - case SIGILL: return "SIGILL"; case SIGABRT: return "SIGABRT"; case SIGBUS: return "SIGBUS"; case SIGFPE: return "SIGFPE"; - case SIGSEGV: return "SIGSEGV"; + case SIGILL: return "SIGILL"; case SIGPIPE: return "SIGPIPE"; + case SIGSEGV: return "SIGSEGV"; #if defined(SIGSTKFLT) case SIGSTKFLT: return "SIGSTKFLT"; #endif case SIGSTOP: return "SIGSTOP"; + case SIGTRAP: return "SIGTRAP"; default: return "?"; } } @@ -459,6 +461,8 @@ static bool dump_sibling_thread_report( // that don't match the specified pid, and writes them to the tombstone file. // // If "tail" is set, we only print the last few lines. +static EventTagMap* g_eventTagMap = NULL; + static void dump_log_file(log_t* log, pid_t pid, const char* filename, unsigned int tail) { bool first = true; @@ -521,7 +525,28 @@ static void dump_log_file(log_t* log, pid_t pid, const char* filename, if (!hdr_size) { hdr_size = sizeof(log_entry.entry_v1); } - char* msg = (char *)log_entry.buf + hdr_size; + char* msg = reinterpret_cast<char*>(log_entry.buf) + hdr_size; + + char timeBuf[32]; + time_t sec = static_cast<time_t>(entry->sec); + struct tm tmBuf; + struct tm* ptm; + ptm = localtime_r(&sec, &tmBuf); + strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", ptm); + + if (log_entry.id() == LOG_ID_EVENTS) { + if (!g_eventTagMap) { + g_eventTagMap = android_openEventTagMap(EVENT_TAG_MAP_FILE); + } + AndroidLogEntry e; + char buf[512]; + android_log_processBinaryLogBuffer(entry, &e, g_eventTagMap, buf, sizeof(buf)); + _LOG(log, 0, "%s.%03d %5d %5d %c %-8s: %s\n", + timeBuf, entry->nsec / 1000000, entry->pid, entry->tid, + 'I', e.tag, e.message); + continue; + } + unsigned char prio = msg[0]; char* tag = msg + 1; msg = tag + strlen(tag) + 1; @@ -534,13 +559,6 @@ static void dump_log_file(log_t* log, pid_t pid, const char* filename, char prioChar = (prio < strlen(kPrioChars) ? kPrioChars[prio] : '?'); - char timeBuf[32]; - time_t sec = static_cast<time_t>(entry->sec); - struct tm tmBuf; - struct tm* ptm; - ptm = localtime_r(&sec, &tmBuf); - strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", ptm); - // Look for line breaks ('\n') and display each text line // on a separate line, prefixed with the header, like logcat does. do { diff --git a/fastboot/fastboot.c b/fastboot/fastboot.c index 3a140ab..9c04c21 100644 --- a/fastboot/fastboot.c +++ b/fastboot/fastboot.c @@ -32,6 +32,7 @@ #include <errno.h> #include <fcntl.h> #include <getopt.h> +#include <inttypes.h> #include <limits.h> #include <stdbool.h> #include <stdint.h> @@ -576,7 +577,7 @@ static int64_t get_target_sparse_limit(struct usb_handle *usb) if (!status) { limit = strtoul(response, NULL, 0); if (limit > 0) { - fprintf(stderr, "target reported max download size of %lld bytes\n", + fprintf(stderr, "target reported max download size of %" PRId64 " bytes\n", limit); } } diff --git a/fastbootd/transport.c b/fastbootd/transport.c index ce8f9d0..9a16fd7 100644 --- a/fastbootd/transport.c +++ b/fastbootd/transport.c @@ -55,7 +55,7 @@ int transport_handle_download(struct transport_handle *thandle, size_t len) ftruncate(fd, len); buffer = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (buffer == NULL) { + if (buffer == MAP_FAILED) { D(ERR, "mmap(%zu) failed: %d %s", len, errno, strerror(errno)); goto err; } diff --git a/include/backtrace/BacktraceMap.h b/include/backtrace/BacktraceMap.h index 13083bd..c717f09 100644 --- a/include/backtrace/BacktraceMap.h +++ b/include/backtrace/BacktraceMap.h @@ -18,6 +18,7 @@ #define _BACKTRACE_BACKTRACE_MAP_H #include <stdint.h> +#include <sys/types.h> #ifdef USE_MINGW // MINGW does not define these constants. #define PROT_NONE 0 diff --git a/include/cutils/bitops.h b/include/cutils/bitops.h index c26dc54..045830d 100644 --- a/include/cutils/bitops.h +++ b/include/cutils/bitops.h @@ -59,7 +59,7 @@ static inline void bitmask_init(unsigned int *bitmask, int num_bits) static inline int bitmask_ffz(unsigned int *bitmask, int num_bits) { int bit, result; - unsigned int i; + size_t i; for (i = 0; i < BITS_TO_WORDS(num_bits); i++) { bit = ffs(~bitmask[i]); @@ -77,7 +77,7 @@ static inline int bitmask_ffz(unsigned int *bitmask, int num_bits) static inline int bitmask_weight(unsigned int *bitmask, int num_bits) { - int i; + size_t i; int weight = 0; for (i = 0; i < BITS_TO_WORDS(num_bits); i++) diff --git a/include/cutils/fs.h b/include/cutils/fs.h index d1d4cf2..70f0b92 100644 --- a/include/cutils/fs.h +++ b/include/cutils/fs.h @@ -18,6 +18,7 @@ #define __CUTILS_FS_H #include <sys/types.h> +#include <unistd.h> /* * TEMP_FAILURE_RETRY is defined by some, but not all, versions of diff --git a/include/cutils/list.h b/include/cutils/list.h index 945729a..4ba2cfd 100644 --- a/include/cutils/list.h +++ b/include/cutils/list.h @@ -44,10 +44,10 @@ struct listnode #define list_for_each_reverse(node, list) \ for (node = (list)->prev; node != (list); node = node->prev) -#define list_for_each_safe(node, next, list) \ - for (node = (list)->next, next = node->next; \ +#define list_for_each_safe(node, n, list) \ + for (node = (list)->next, n = node->next; \ node != (list); \ - node = next, next = node->next) + node = n, n = node->next) static inline void list_init(struct listnode *node) { @@ -63,6 +63,14 @@ static inline void list_add_tail(struct listnode *head, struct listnode *item) head->prev = item; } +static inline void list_add_head(struct listnode *head, struct listnode *item) +{ + item->next = head->next; + item->prev = head; + head->next->prev = item; + head->next = item; +} + static inline void list_remove(struct listnode *item) { item->next->prev = item->prev; diff --git a/include/cutils/sockets.h b/include/cutils/sockets.h index 19cae0c..daf43ec 100644 --- a/include/cutils/sockets.h +++ b/include/cutils/sockets.h @@ -86,6 +86,8 @@ static inline int android_get_control_socket(const char *name) extern int socket_loopback_client(int port, int type); extern int socket_network_client(const char *host, int port, int type); +extern int socket_network_client_timeout(const char *host, int port, int type, + int timeout); extern int socket_loopback_server(int port, int type); extern int socket_local_server(const char *name, int namespaceId, int type); extern int socket_local_server_bind(int s, const char *name, int namespaceId); diff --git a/include/cutils/trace.h b/include/cutils/trace.h index dbd5e25..fd9bc6a 100644 --- a/include/cutils/trace.h +++ b/include/cutils/trace.h @@ -20,6 +20,7 @@ #include <inttypes.h> #include <stdbool.h> #include <stdint.h> +#include <stdio.h> #include <sys/cdefs.h> #include <sys/types.h> #include <unistd.h> @@ -68,7 +69,8 @@ __BEGIN_DECLS #define ATRACE_TAG_RESOURCES (1<<13) #define ATRACE_TAG_DALVIK (1<<14) #define ATRACE_TAG_RS (1<<15) -#define ATRACE_TAG_LAST ATRACE_TAG_RS +#define ATRACE_TAG_BIONIC (1<<16) +#define ATRACE_TAG_LAST ATRACE_TAG_BIONIC // Reserved for initialization. #define ATRACE_TAG_NOT_READY (1LL<<63) diff --git a/include/log/log_read.h b/include/log/log_read.h index 54d71a4..946711a 100644 --- a/include/log/log_read.h +++ b/include/log/log_read.h @@ -67,7 +67,8 @@ public: // timespec bool operator== (const timespec &T) const { - return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec); + return (tv_sec == static_cast<uint32_t>(T.tv_sec)) + && (tv_nsec == static_cast<uint32_t>(T.tv_nsec)); } bool operator!= (const timespec &T) const { @@ -75,8 +76,9 @@ public: } bool operator< (const timespec &T) const { - return (tv_sec < T.tv_sec) - || ((tv_sec == T.tv_sec) && (tv_nsec < T.tv_nsec)); + return (tv_sec < static_cast<uint32_t>(T.tv_sec)) + || ((tv_sec == static_cast<uint32_t>(T.tv_sec)) + && (tv_nsec < static_cast<uint32_t>(T.tv_nsec))); } bool operator>= (const timespec &T) const { @@ -84,8 +86,9 @@ public: } bool operator> (const timespec &T) const { - return (tv_sec > T.tv_sec) - || ((tv_sec == T.tv_sec) && (tv_nsec > T.tv_nsec)); + return (tv_sec > static_cast<uint32_t>(T.tv_sec)) + || ((tv_sec == static_cast<uint32_t>(T.tv_sec)) + && (tv_nsec > static_cast<uint32_t>(T.tv_nsec))); } bool operator<= (const timespec &T) const { diff --git a/include/log/logger.h b/include/log/logger.h index ed39c4f..53be1d3 100644 --- a/include/log/logger.h +++ b/include/log/logger.h @@ -62,9 +62,8 @@ struct logger_entry_v3 { /* * The maximum size of the log entry payload that can be - * written to the kernel logger driver. An attempt to write - * more than this amount to /dev/log/* will result in a - * truncated log entry. + * written to the logger. An attempt to write more than + * this amount will result in a truncated log entry. */ #define LOGGER_ENTRY_MAX_PAYLOAD 4076 diff --git a/include/netd_client/FwmarkCommands.h b/include/netd_client/FwmarkCommands.h deleted file mode 100644 index 0d22f02..0000000 --- a/include/netd_client/FwmarkCommands.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef NETD_CLIENT_FWMARK_COMMANDS_H -#define NETD_CLIENT_FWMARK_COMMANDS_H - -#include <stdint.h> - -// Commands sent from clients to the fwmark server to mark sockets (i.e., set their SO_MARK). -const uint8_t FWMARK_COMMAND_ON_CREATE = 0; -const uint8_t FWMARK_COMMAND_ON_CONNECT = 1; -const uint8_t FWMARK_COMMAND_ON_ACCEPT = 2; -const uint8_t FWMARK_COMMAND_SELECT_NETWORK = 3; -const uint8_t FWMARK_COMMAND_PROTECT_FROM_VPN = 4; - -#endif // NETD_CLIENT_FWMARK_COMMANDS_H diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index d662107..f5289c1 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -77,6 +77,7 @@ #define AID_SDCARD_AV 1034 /* external storage audio/video access */ #define AID_SDCARD_ALL 1035 /* access all users external storage */ #define AID_LOGD 1036 /* log daemon */ +#define AID_SHARED_RELRO 1037 /* creator of shared GNU RELRO files */ #define AID_SHELL 2000 /* adb and debug shell user */ #define AID_CACHE 2001 /* cache access */ @@ -153,6 +154,7 @@ static const struct android_id_info android_ids[] = { { "sdcard_av", AID_SDCARD_AV, }, { "sdcard_all", AID_SDCARD_ALL, }, { "logd", AID_LOGD, }, + { "shared_relro", AID_SHARED_RELRO, }, { "shell", AID_SHELL, }, { "cache", AID_CACHE, }, @@ -198,6 +200,7 @@ static const struct fs_path_config android_dirs[] = { { 00771, AID_SHELL, AID_SHELL, 0, "data/local" }, { 01771, AID_SYSTEM, AID_MISC, 0, "data/misc" }, { 00770, AID_DHCP, AID_DHCP, 0, "data/misc/dhcp" }, + { 00771, AID_SHARED_RELRO, AID_SHARED_RELRO, 0, "data/misc/shared_relro" }, { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media" }, { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/Music" }, { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data" }, diff --git a/include/system/audio.h b/include/system/audio.h index f36befb..8838e71 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -434,6 +434,14 @@ typedef struct { static const audio_offload_info_t AUDIO_INFO_INITIALIZER = { version: AUDIO_OFFLOAD_INFO_VERSION_CURRENT, size: sizeof(audio_offload_info_t), + sample_rate: 0, + channel_mask: 0, + format: AUDIO_FORMAT_DEFAULT, + stream_type: AUDIO_STREAM_VOICE_CALL, + bit_rate: 0, + duration_us: 0, + has_video: false, + is_streaming: false }; static inline bool audio_is_output_device(audio_devices_t device) diff --git a/include/system/window.h b/include/system/window.h index 588f9c6..16b7b67 100644 --- a/include/system/window.h +++ b/include/system/window.h @@ -26,6 +26,13 @@ #include <system/graphics.h> #include <unistd.h> +#ifndef __unused +#define __unused __attribute__((__unused__)) +#endif +#ifndef __deprecated +#define __deprecated __attribute__((__deprecated__)) +#endif + __BEGIN_DECLS /*****************************************************************************/ @@ -89,10 +96,10 @@ typedef struct ANativeWindowBuffer // Implement the methods that sp<ANativeWindowBuffer> expects so that it // can be used to automatically refcount ANativeWindowBuffer's. - void incStrong(const void* id) const { + void incStrong(const void* /*id*/) const { common.incRef(const_cast<android_native_base_t*>(&common)); } - void decStrong(const void* id) const { + void decStrong(const void* /*id*/) const { common.decRef(const_cast<android_native_base_t*>(&common)); } #endif @@ -352,10 +359,10 @@ struct ANativeWindow /* Implement the methods that sp<ANativeWindow> expects so that it can be used to automatically refcount ANativeWindow's. */ - void incStrong(const void* id) const { + void incStrong(const void* /*id*/) const { common.incRef(const_cast<android_native_base_t*>(&common)); } - void decStrong(const void* id) const { + void decStrong(const void* /*id*/) const { common.decRef(const_cast<android_native_base_t*>(&common)); } #endif @@ -582,7 +589,7 @@ struct ANativeWindow * android_native_window_t is deprecated. */ typedef struct ANativeWindow ANativeWindow; -typedef struct ANativeWindow android_native_window_t; +typedef struct ANativeWindow android_native_window_t __deprecated; /* * native_window_set_usage(..., usage) @@ -603,13 +610,19 @@ static inline int native_window_set_usage( /* deprecated. Always returns 0. Don't call. */ static inline int native_window_connect( - struct ANativeWindow* window, int api) { + struct ANativeWindow* window __unused, int api __unused) __deprecated; + +static inline int native_window_connect( + struct ANativeWindow* window __unused, int api __unused) { return 0; } /* deprecated. Always returns 0. Don't call. */ static inline int native_window_disconnect( - struct ANativeWindow* window, int api) { + struct ANativeWindow* window __unused, int api __unused) __deprecated; + +static inline int native_window_disconnect( + struct ANativeWindow* window __unused, int api __unused) { return 0; } @@ -664,6 +677,10 @@ static inline int native_window_set_post_transform_crop( */ static inline int native_window_set_active_rect( struct ANativeWindow* window, + android_native_rect_t const * active_rect) __deprecated; + +static inline int native_window_set_active_rect( + struct ANativeWindow* window, android_native_rect_t const * active_rect) { return native_window_set_post_transform_crop(window, active_rect); @@ -691,6 +708,10 @@ static inline int native_window_set_buffer_count( */ static inline int native_window_set_buffers_geometry( struct ANativeWindow* window, + int w, int h, int format) __deprecated; + +static inline int native_window_set_buffers_geometry( + struct ANativeWindow* window, int w, int h, int format) { return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY, diff --git a/include/utils/Functor.h b/include/utils/Functor.h index e24ded4..09ea614 100644 --- a/include/utils/Functor.h +++ b/include/utils/Functor.h @@ -25,7 +25,7 @@ class Functor { public: Functor() {} virtual ~Functor() {} - virtual status_t operator ()(int what, void* data) { return NO_ERROR; } + virtual status_t operator ()(int /*what*/, void* /*data*/) { return NO_ERROR; } }; }; // namespace android diff --git a/include/utils/LruCache.h b/include/utils/LruCache.h index 053bfaf..9248ac9 100644 --- a/include/utils/LruCache.h +++ b/include/utils/LruCache.h @@ -56,7 +56,7 @@ public: bool next() { mIndex = mCache.mTable->next(mIndex); - return mIndex != -1; + return (ssize_t)mIndex != -1; } size_t index() const { @@ -103,9 +103,13 @@ private: // Implementation is here, because it's fully templated template <typename TKey, typename TValue> -LruCache<TKey, TValue>::LruCache(uint32_t maxCapacity): mMaxCapacity(maxCapacity), - mNullValue(NULL), mTable(new BasicHashtable<TKey, Entry>), mYoungest(NULL), mOldest(NULL), - mListener(NULL) { +LruCache<TKey, TValue>::LruCache(uint32_t maxCapacity) + : mTable(new BasicHashtable<TKey, Entry>) + , mListener(NULL) + , mOldest(NULL) + , mYoungest(NULL) + , mMaxCapacity(maxCapacity) + , mNullValue(NULL) { }; template<typename K, typename V> diff --git a/init/devices.c b/init/devices.c index 5d7ad3b..3119e8e 100644 --- a/init/devices.c +++ b/init/devices.c @@ -298,6 +298,37 @@ static void remove_platform_device(const char *path) } } +/* Given a path that may start with a PCI device, populate the supplied buffer + * with the PCI domain/bus number and the peripheral ID and return 0. + * If it doesn't start with a PCI device, or there is some error, return -1 */ +static int find_pci_device_prefix(const char *path, char *buf, ssize_t buf_sz) +{ + const char *start, *end; + + if (strncmp(path, "/devices/pci", 12)) + return -1; + + /* Beginning of the prefix is the initial "pci" after "/devices/" */ + start = path + 9; + + /* End of the prefix is two path '/' later, capturing the domain/bus number + * and the peripheral ID. Example: pci0000:00/0000:00:1f.2 */ + end = strchr(start, '/'); + if (!end) + return -1; + end = strchr(end + 1, '/'); + if (!end) + return -1; + + /* Make sure we have enough room for the string plus null terminator */ + if (end - start + 1 > buf_sz) + return -1; + + strncpy(buf, start, end - start); + buf[end - start] = '\0'; + return 0; +} + #if LOG_UEVENTS static inline suseconds_t get_usecs(void) @@ -422,11 +453,12 @@ err: return NULL; } -static char **parse_platform_block_device(struct uevent *uevent) +static char **get_block_device_symlinks(struct uevent *uevent) { const char *device; struct platform_node *pdev; char *slash; + const char *type; int width; char buf[256]; char link_path[256]; @@ -438,18 +470,24 @@ static char **parse_platform_block_device(struct uevent *uevent) struct stat info; pdev = find_platform_device(uevent->path); - if (!pdev) + if (pdev) { + device = pdev->name; + type = "platform"; + } else if (!find_pci_device_prefix(uevent->path, buf, sizeof(buf))) { + device = buf; + type = "pci"; + } else { return NULL; - device = pdev->name; + } char **links = malloc(sizeof(char *) * 4); if (!links) return NULL; memset(links, 0, sizeof(char *) * 4); - INFO("found platform device %s\n", device); + INFO("found %s device %s\n", type, device); - snprintf(link_path, sizeof(link_path), "/dev/block/platform/%s", device); + snprintf(link_path, sizeof(link_path), "/dev/block/%s/%s", type, device); if (uevent->partition_name) { p = strdup(uevent->partition_name); @@ -556,7 +594,7 @@ static void handle_block_device_event(struct uevent *uevent) make_dir(base, 0755); if (!strncmp(uevent->path, "/devices/", 9)) - links = parse_platform_block_device(uevent); + links = get_block_device_symlinks(uevent); handle_device(uevent->action, devpath, uevent->path, 1, uevent->major, uevent->minor, links); diff --git a/init/init_parser.c b/init/init_parser.c index 02e5bdc..7800082 100644 --- a/init/init_parser.c +++ b/init/init_parser.c @@ -760,7 +760,7 @@ static void parse_line_service(struct parse_state *state, int nargs, char **args break; case K_setenv: { /* name value */ struct svcenvinfo *ei; - if (nargs < 2) { + if (nargs < 3) { parse_error(state, "setenv option requires name and value arguments\n"); break; } diff --git a/init/property_service.c b/init/property_service.c index 4bcf883..fb3bc8d 100644 --- a/init/property_service.c +++ b/init/property_service.c @@ -38,7 +38,6 @@ #include <sys/types.h> #include <netinet/in.h> #include <sys/mman.h> -#include <sys/atomics.h> #include <private/android_filesystem_config.h> #include <selinux/selinux.h> diff --git a/libbacktrace/Android.build.mk b/libbacktrace/Android.build.mk index 3c80cc2..9882e31 100644 --- a/libbacktrace/Android.build.mk +++ b/libbacktrace/Android.build.mk @@ -60,7 +60,11 @@ LOCAL_LDLIBS := \ $($(module)_ldlibs_$(build_type)) \ ifeq ($(build_type),target) - include external/stlport/libstlport.mk + ifneq ($($(module)_libc++),) + include external/libcxx/libcxx.mk + else + include external/stlport/libstlport.mk + endif include $(BUILD_$(build_target)) endif @@ -68,6 +72,9 @@ endif ifeq ($(build_type),host) # Only build if host builds are supported. ifeq ($(build_host),true) + ifneq ($($(module)_libc++),) + include external/libcxx/libcxx.mk + endif include $(BUILD_HOST_$(build_target)) endif endif diff --git a/libbacktrace/Android.mk b/libbacktrace/Android.mk index fa79221..5a0bc7f 100755 --- a/libbacktrace/Android.mk +++ b/libbacktrace/Android.mk @@ -72,6 +72,50 @@ include $(LOCAL_PATH)/Android.build.mk build_type := host include $(LOCAL_PATH)/Android.build.mk +# Don't build for unbundled branches +ifeq (,$(TARGET_BUILD_APPS)) +#------------------------------------------------------------------------- +# The libbacktrace library (libc++) +#------------------------------------------------------------------------- +libbacktrace_libc++_src_files := \ + BacktraceImpl.cpp \ + BacktraceMap.cpp \ + BacktraceThread.cpp \ + thread_utils.c \ + +libbacktrace_libc++_shared_libraries_target := \ + libcutils \ + libgccdemangle \ + +libbacktrace_libc++_src_files += \ + UnwindCurrent.cpp \ + UnwindMap.cpp \ + UnwindPtrace.cpp \ + +libbacktrace_libc++_c_includes := \ + external/libunwind/include \ + +libbacktrace_libc++_shared_libraries := \ + libunwind \ + libunwind-ptrace \ + +libbacktrace_libc++_shared_libraries_host := \ + liblog \ + +libbacktrace_libc++_static_libraries_host := \ + libcutils \ + +libbacktrace_libc++_libc++ := true + +module := libbacktrace_libc++ +module_tag := optional +build_type := target +build_target := SHARED_LIBRARY +include $(LOCAL_PATH)/Android.build.mk +build_type := host +include $(LOCAL_PATH)/Android.build.mk +endif + #------------------------------------------------------------------------- # The libbacktrace_test library needed by backtrace_test. #------------------------------------------------------------------------- diff --git a/libbacktrace/BacktraceThread.cpp b/libbacktrace/BacktraceThread.cpp index 018d51f..b47cd2a 100644 --- a/libbacktrace/BacktraceThread.cpp +++ b/libbacktrace/BacktraceThread.cpp @@ -117,6 +117,12 @@ void ThreadEntry::Wake() { futex(&futex_, FUTEX_WAKE, INT_MAX, NULL, NULL, 0); } +void ThreadEntry::CopyUcontextFromSigcontext(void* sigcontext) { + ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(sigcontext); + // The only thing the unwinder cares about is the mcontext data. + memcpy(&ucontext_.uc_mcontext, &ucontext->uc_mcontext, sizeof(ucontext->uc_mcontext)); +} + //------------------------------------------------------------------------- // BacktraceThread functions. //------------------------------------------------------------------------- @@ -129,7 +135,7 @@ static void SignalHandler(int, siginfo_t*, void* sigcontext) { return; } - entry->CopyUcontext(reinterpret_cast<ucontext_t*>(sigcontext)); + entry->CopyUcontextFromSigcontext(sigcontext); // Indicate the ucontext is now valid. entry->Wake(); diff --git a/libbacktrace/BacktraceThread.h b/libbacktrace/BacktraceThread.h index a75a807..ff3e9f3 100644 --- a/libbacktrace/BacktraceThread.h +++ b/libbacktrace/BacktraceThread.h @@ -40,14 +40,12 @@ public: static void Remove(ThreadEntry* entry); - inline void CopyUcontext(ucontext_t* ucontext) { - memcpy(&ucontext_, ucontext, sizeof(ucontext_)); - } - void Wake(); void Wait(int); + void CopyUcontextFromSigcontext(void*); + inline void Lock() { pthread_mutex_lock(&mutex_); // Reset the futex value in case of multiple unwinds of the same thread. diff --git a/libbacktrace/UnwindMap.cpp b/libbacktrace/UnwindMap.cpp index 1615518..4f9831b 100644 --- a/libbacktrace/UnwindMap.cpp +++ b/libbacktrace/UnwindMap.cpp @@ -15,6 +15,7 @@ */ #include <pthread.h> +#include <stdlib.h> #include <sys/types.h> #include <unistd.h> diff --git a/libctest/Android.mk b/libctest/Android.mk deleted file mode 100644 index 815fabb..0000000 --- a/libctest/Android.mk +++ /dev/null @@ -1,7 +0,0 @@ -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE:= libctest -LOCAL_SRC_FILES := ctest.c - -include $(BUILD_SHARED_LIBRARY) diff --git a/libctest/NOTICE b/libctest/NOTICE deleted file mode 100644 index c5b1efa..0000000 --- a/libctest/NOTICE +++ /dev/null @@ -1,190 +0,0 @@ - - Copyright (c) 2005-2008, The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - diff --git a/libctest/ctest.c b/libctest/ctest.c deleted file mode 100644 index ee6331f..0000000 --- a/libctest/ctest.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <assert.h> -#include <stdlib.h> -#include <stdio.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <unistd.h> -#include <ctest/ctest.h> - -#define MAX_TESTS 255 - -/** Semi-random number used to identify assertion errors. */ -#define ASSERTION_ERROR 42 - -typedef void TestCase(); - -/** A suite of tests. */ -typedef struct { - int size; - const char* testNames[MAX_TESTS]; - TestCase* tests[MAX_TESTS]; - int currentTest; - FILE* out; -} TestSuite; - -/** Gets the test suite. Creates it if necessary. */ -static TestSuite* getTestSuite() { - static TestSuite* suite = NULL; - - if (suite != NULL) { - return suite; - } - - suite = calloc(1, sizeof(TestSuite)); - assert(suite != NULL); - - suite->out = tmpfile(); - assert(suite->out != NULL); - - return suite; -} - -void addNamedTest(const char* name, TestCase* test) { - TestSuite* testSuite = getTestSuite(); - assert(testSuite->size <= MAX_TESTS); - - int index = testSuite->size; - testSuite->testNames[index] = name; - testSuite->tests[index] = test; - - testSuite->size++; -} - -/** Prints failures to stderr. */ -static void printFailures(int failures) { - TestSuite* suite = getTestSuite(); - - fprintf(stderr, "FAILURE! %d of %d tests failed. Failures:\n", - failures, suite->size); - - // Copy test output to stdout. - rewind(suite->out); - char buffer[512]; - size_t read; - while ((read = fread(buffer, sizeof(char), 512, suite->out)) > 0) { - // TODO: Make sure we actually wrote 'read' bytes. - fwrite(buffer, sizeof(char), read, stderr); - } -} - -/** Runs a single test case. */ -static int runCurrentTest() { - TestSuite* suite = getTestSuite(); - - pid_t pid = fork(); - if (pid == 0) { - // Child process. Runs test case. - suite->tests[suite->currentTest](); - - // Exit successfully. - exit(0); - } else if (pid < 0) { - fprintf(stderr, "Fork failed."); - exit(1); - } else { - // Parent process. Wait for child. - int status; - waitpid(pid, &status, 0); - - if (!WIFEXITED(status)) { - return -1; - } - - return WEXITSTATUS(status); - } -} - -void runTests() { - TestSuite* suite = getTestSuite(); - - int failures = 0; - for (suite->currentTest = 0; suite->currentTest < suite->size; - suite->currentTest++) { - // Flush stdout before forking. - fflush(stdout); - - int result = runCurrentTest(); - - if (result != 0) { - printf("X"); - - failures++; - - // Handle errors other than assertions. - if (result != ASSERTION_ERROR) { - // TODO: Report file name. - fprintf(suite->out, "Process failed: [%s] status: %d\n", - suite->testNames[suite->currentTest], result); - fflush(suite->out); - } - } else { - printf("."); - } - } - - printf("\n"); - - if (failures > 0) { - printFailures(failures); - } else { - printf("SUCCESS! %d tests ran successfully.\n", suite->size); - } -} - -void assertTrueWithSource(int value, const char* file, int line, char* message) { - if (!value) { - TestSuite* suite = getTestSuite(); - - fprintf(suite->out, "Assertion failed: [%s:%d] %s: %s\n", file, line, - suite->testNames[suite->currentTest], message); - fflush(suite->out); - - // Exit the process for this test case. - exit(ASSERTION_ERROR); - } -} diff --git a/libcutils/Android.mk b/libcutils/Android.mk index 945ebdd..e1d6f49 100644 --- a/libcutils/Android.mk +++ b/libcutils/Android.mk @@ -27,13 +27,6 @@ commonSources := \ hashmap.c \ atomic.c.arm \ native_handle.c \ - socket_inaddr_any_server.c \ - socket_local_client.c \ - socket_local_server.c \ - socket_loopback_client.c \ - socket_loopback_server.c \ - socket_network_client.c \ - sockets.c \ config_utils.c \ cpu_info.c \ load_file.c \ @@ -67,7 +60,15 @@ endif ifneq ($(WINDOWS_HOST_ONLY),1) commonSources += \ fs.c \ - multiuser.c + multiuser.c \ + socket_inaddr_any_server.c \ + socket_local_client.c \ + socket_local_server.c \ + socket_loopback_client.c \ + socket_loopback_server.c \ + socket_network_client.c \ + sockets.c \ + endif diff --git a/libcutils/socket_network_client.c b/libcutils/socket_network_client.c index c52013d..4826033 100644 --- a/libcutils/socket_network_client.c +++ b/libcutils/socket_network_client.c @@ -15,18 +15,17 @@ */ #include <errno.h> +#include <fcntl.h> #include <stddef.h> #include <stdlib.h> #include <string.h> #include <unistd.h> -#ifndef HAVE_WINSOCK #include <sys/socket.h> #include <sys/select.h> #include <sys/types.h> #include <netinet/in.h> #include <netdb.h> -#endif #include <cutils/sockets.h> @@ -36,27 +35,92 @@ */ int socket_network_client(const char *host, int port, int type) { + return socket_network_client_timeout(host, port, type, 0); +} + +/* Connect to port on the IP interface. type is SOCK_STREAM or SOCK_DGRAM. + * timeout in seconds return is a file descriptor or -1 on error + */ +int socket_network_client_timeout(const char *host, int port, int type, int timeout) +{ struct hostent *hp; struct sockaddr_in addr; + socklen_t alen; int s; + int flags = 0, error = 0, ret = 0; + fd_set rset, wset; + socklen_t len = sizeof(error); + struct timeval ts; + + ts.tv_sec = timeout; + ts.tv_usec = 0; hp = gethostbyname(host); - if(hp == 0) return -1; - + if (hp == 0) return -1; + memset(&addr, 0, sizeof(addr)); addr.sin_family = hp->h_addrtype; addr.sin_port = htons(port); memcpy(&addr.sin_addr, hp->h_addr, hp->h_length); s = socket(hp->h_addrtype, type, 0); - if(s < 0) return -1; + if (s < 0) return -1; - if(connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if ((flags = fcntl(s, F_GETFL, 0)) < 0) { close(s); return -1; } - return s; + if (fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0) { + close(s); + return -1; + } -} + if ((ret = connect(s, (struct sockaddr *) &addr, sizeof(addr))) < 0) { + if (errno != EINPROGRESS) { + close(s); + return -1; + } + } + + if (ret == 0) + goto done; + + FD_ZERO(&rset); + FD_SET(s, &rset); + wset = rset; + if ((ret = select(s + 1, &rset, &wset, NULL, (timeout) ? &ts : NULL)) < 0) { + close(s); + return -1; + } + if (ret == 0) { // we had a timeout + errno = ETIMEDOUT; + close(s); + return -1; + } + + if (FD_ISSET(s, &rset) || FD_ISSET(s, &wset)) { + if (getsockopt(s, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { + close(s); + return -1; + } + } else { + close(s); + return -1; + } + + if (error) { // check if we had a socket error + errno = error; + close(s); + return -1; + } + +done: + if (fcntl(s, F_SETFL, flags) < 0) { + close(s); + return -1; + } + + return s; +} diff --git a/libdiskconfig/Android.mk b/libdiskconfig/Android.mk index b5d83fa..624e385 100644 --- a/libdiskconfig/Android.mk +++ b/libdiskconfig/Android.mk @@ -12,6 +12,7 @@ LOCAL_SRC_FILES := $(commonSources) LOCAL_MODULE := libdiskconfig LOCAL_MODULE_TAGS := optional LOCAL_SYSTEM_SHARED_LIBRARIES := libcutils liblog libc +LOCAL_CFLAGS := -Werror include $(BUILD_SHARED_LIBRARY) ifeq ($(HOST_OS),linux) diff --git a/libion/Android.mk b/libion/Android.mk index e5d495b..6562cd3 100644 --- a/libion/Android.mk +++ b/libion/Android.mk @@ -1,4 +1,4 @@ -LOCAL_PATH:= $(call my-dir) +LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := ion.c @@ -7,6 +7,7 @@ LOCAL_MODULE_TAGS := optional LOCAL_SHARED_LIBRARIES := liblog LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/kernel-headers LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include $(LOCAL_PATH)/kernel-headers +LOCAL_CFLAGS := -Werror include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) @@ -15,6 +16,7 @@ LOCAL_MODULE := iontest LOCAL_MODULE_TAGS := optional tests LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/kernel-headers LOCAL_SHARED_LIBRARIES := liblog +LOCAL_CFLAGS := -Werror include $(BUILD_EXECUTABLE) include $(call first-makefiles-under,$(LOCAL_PATH)) diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp index ec35e45..393e2cd 100644 --- a/liblog/tests/liblog_test.cpp +++ b/liblog/tests/liblog_test.cpp @@ -544,7 +544,7 @@ TEST(liblog, too_big_payload) { EXPECT_LE(LOGGER_ENTRY_MAX_PAYLOAD - sizeof(big_payload_tag), static_cast<size_t>(max_len)); - EXPECT_EQ(ret, max_len + sizeof(big_payload_tag)); + EXPECT_EQ(ret, max_len + static_cast<ssize_t>(sizeof(big_payload_tag))); } TEST(liblog, dual_reader) { diff --git a/libnetd_client/Android.mk b/libnetd_client/Android.mk deleted file mode 100644 index 2b75626..0000000 --- a/libnetd_client/Android.mk +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (C) 2014 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := libnetd_client -LOCAL_SRC_FILES := FwmarkClient.cpp NetdClient.cpp - -include $(BUILD_SHARED_LIBRARY) diff --git a/libnetd_client/FwmarkClient.cpp b/libnetd_client/FwmarkClient.cpp deleted file mode 100644 index e360b4e..0000000 --- a/libnetd_client/FwmarkClient.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "FwmarkClient.h" - -#include <stdlib.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <unistd.h> - -namespace { - -const sockaddr_un FWMARK_SERVER_PATH = {AF_UNIX, "/dev/socket/fwmarkd"}; - -} // namespace - -bool FwmarkClient::shouldSetFwmark(int sockfd, const sockaddr* addr) { - return sockfd >= 0 && addr && (addr->sa_family == AF_INET || addr->sa_family == AF_INET6) && - !getenv("ANDROID_NO_USE_FWMARK_CLIENT"); -} - -FwmarkClient::FwmarkClient() : mChannel(-1) { -} - -FwmarkClient::~FwmarkClient() { - if (mChannel >= 0) { - // We don't care about errors while closing the channel, so restore any previous error. - int error = errno; - close(mChannel); - errno = error; - } -} - -bool FwmarkClient::send(void* data, size_t len, int fd) { - mChannel = socket(AF_UNIX, SOCK_STREAM, 0); - if (mChannel == -1) { - return false; - } - - if (TEMP_FAILURE_RETRY(connect(mChannel, reinterpret_cast<const sockaddr*>(&FWMARK_SERVER_PATH), - sizeof(FWMARK_SERVER_PATH))) == -1) { - // If we are unable to connect to the fwmark server, assume there's no error. This protects - // against future changes if the fwmark server goes away. - errno = 0; - return true; - } - - iovec iov; - iov.iov_base = data; - iov.iov_len = len; - - msghdr message; - memset(&message, 0, sizeof(message)); - message.msg_iov = &iov; - message.msg_iovlen = 1; - - union { - cmsghdr cmh; - char cmsg[CMSG_SPACE(sizeof(fd))]; - } cmsgu; - - memset(cmsgu.cmsg, 0, sizeof(cmsgu.cmsg)); - message.msg_control = cmsgu.cmsg; - message.msg_controllen = sizeof(cmsgu.cmsg); - - cmsghdr* const cmsgh = CMSG_FIRSTHDR(&message); - cmsgh->cmsg_len = CMSG_LEN(sizeof(fd)); - cmsgh->cmsg_level = SOL_SOCKET; - cmsgh->cmsg_type = SCM_RIGHTS; - memcpy(CMSG_DATA(cmsgh), &fd, sizeof(fd)); - - if (TEMP_FAILURE_RETRY(sendmsg(mChannel, &message, 0)) == -1) { - return false; - } - - int error = 0; - if (TEMP_FAILURE_RETRY(recv(mChannel, &error, sizeof(error), 0)) == -1) { - return false; - } - - errno = error; - return !error; -} diff --git a/libnetd_client/FwmarkClient.h b/libnetd_client/FwmarkClient.h deleted file mode 100644 index 4cf0cc0..0000000 --- a/libnetd_client/FwmarkClient.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef NETD_CLIENT_FWMARK_CLIENT_H -#define NETD_CLIENT_FWMARK_CLIENT_H - -#include <sys/socket.h> - -class FwmarkClient { -public: - // Returns true if |sockfd| should be sent to the fwmark server to have its SO_MARK set. - static bool shouldSetFwmark(int sockfd, const sockaddr* addr); - - FwmarkClient(); - ~FwmarkClient(); - - // Sends |data| to the fwmark server, along with |fd| as ancillary data using cmsg(3). - // Returns true on success. - bool send(void* data, size_t len, int fd); - -private: - int mChannel; -}; - -#endif // NETD_CLIENT_INCLUDE_FWMARK_CLIENT_H diff --git a/libnetd_client/NetdClient.cpp b/libnetd_client/NetdClient.cpp deleted file mode 100644 index 8deea1e..0000000 --- a/libnetd_client/NetdClient.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "FwmarkClient.h" -#include "netd_client/FwmarkCommands.h" - -#include <sys/socket.h> -#include <unistd.h> - -namespace { - -int closeFdAndRestoreErrno(int fd) { - int error = errno; - close(fd); - errno = error; - return -1; -} - -typedef int (*ConnectFunctionType)(int, const sockaddr*, socklen_t); -typedef int (*AcceptFunctionType)(int, sockaddr*, socklen_t*); - -ConnectFunctionType libcConnect = 0; -AcceptFunctionType libcAccept = 0; - -int netdClientConnect(int sockfd, const sockaddr* addr, socklen_t addrlen) { - if (FwmarkClient::shouldSetFwmark(sockfd, addr)) { - char data[] = {FWMARK_COMMAND_ON_CONNECT}; - if (!FwmarkClient().send(data, sizeof(data), sockfd)) { - return -1; - } - } - return libcConnect(sockfd, addr, addrlen); -} - -int netdClientAccept(int sockfd, sockaddr* addr, socklen_t* addrlen) { - int acceptedSocket = libcAccept(sockfd, addr, addrlen); - if (acceptedSocket == -1) { - return -1; - } - sockaddr socketAddress; - if (!addr) { - socklen_t socketAddressLen = sizeof(socketAddress); - if (getsockname(acceptedSocket, &socketAddress, &socketAddressLen) == -1) { - return closeFdAndRestoreErrno(acceptedSocket); - } - addr = &socketAddress; - } - if (FwmarkClient::shouldSetFwmark(acceptedSocket, addr)) { - char data[] = {FWMARK_COMMAND_ON_ACCEPT}; - if (!FwmarkClient().send(data, sizeof(data), acceptedSocket)) { - return closeFdAndRestoreErrno(acceptedSocket); - } - } - return acceptedSocket; -} - -} // namespace - -extern "C" void netdClientInitConnect(ConnectFunctionType* function) { - if (function && *function) { - libcConnect = *function; - *function = netdClientConnect; - } -} - -extern "C" void netdClientInitAccept(AcceptFunctionType* function) { - if (function && *function) { - libcAccept = *function; - *function = netdClientAccept; - } -} diff --git a/libnetutils/Android.mk b/libnetutils/Android.mk index aba4621..1f61511 100644 --- a/libnetutils/Android.mk +++ b/libnetutils/Android.mk @@ -1,7 +1,7 @@ -LOCAL_PATH:= $(call my-dir) +LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_SRC_FILES:= \ +LOCAL_SRC_FILES := \ dhcpclient.c \ dhcpmsg.c \ dhcp_utils.c \ @@ -12,6 +12,8 @@ LOCAL_SHARED_LIBRARIES := \ libcutils \ liblog -LOCAL_MODULE:= libnetutils +LOCAL_MODULE := libnetutils + +LOCAL_CFLAGS := -Werror include $(BUILD_SHARED_LIBRARY) diff --git a/libnetutils/dhcpclient.c b/libnetutils/dhcpclient.c index 34500e7..b58120e 100644 --- a/libnetutils/dhcpclient.c +++ b/libnetutils/dhcpclient.c @@ -282,16 +282,18 @@ void dump_dhcp_msg(dhcp_msg *msg, int len) ALOGD("chaddr = {%s}", buf); for (n = 0; n < 64; n++) { - if ((msg->sname[n] < ' ') || (msg->sname[n] > 127)) { - if (msg->sname[n] == 0) break; + unsigned char x = msg->sname[n]; + if ((x < ' ') || (x > 127)) { + if (x == 0) break; msg->sname[n] = '.'; } } msg->sname[63] = 0; for (n = 0; n < 128; n++) { - if ((msg->file[n] < ' ') || (msg->file[n] > 127)) { - if (msg->file[n] == 0) break; + unsigned char x = msg->file[n]; + if ((x < ' ') || (x > 127)) { + if (x == 0) break; msg->file[n] = '.'; } } diff --git a/libpixelflinger/codeflinger/CodeCache.cpp b/libpixelflinger/codeflinger/CodeCache.cpp index 7446da2..8afe0a9 100644 --- a/libpixelflinger/codeflinger/CodeCache.cpp +++ b/libpixelflinger/codeflinger/CodeCache.cpp @@ -89,7 +89,7 @@ static mspace getMspace() gExecutableStore = mmap(NULL, kMaxCodeCacheCapacity, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0); - LOG_ALWAYS_FATAL_IF(gExecutableStore == NULL, + LOG_ALWAYS_FATAL_IF(gExecutableStore == MAP_FAILED, "Creating code cache, mmap failed with error " "'%s'", strerror(errno)); close(fd); diff --git a/libsuspend/Android.mk b/libsuspend/Android.mk index a2fa3e0..1ba2f59 100644 --- a/libsuspend/Android.mk +++ b/libsuspend/Android.mk @@ -18,6 +18,7 @@ LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include LOCAL_C_INCLUDES += $(LOCAL_PATH)/include LOCAL_SHARED_LIBRARIES := $(libsuspend_libraries) +LOCAL_CFLAGS := -Werror #LOCAL_CFLAGS += -DLOG_NDEBUG=0 include $(BUILD_SHARED_LIBRARY) @@ -27,5 +28,6 @@ LOCAL_MODULE := libsuspend LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include LOCAL_C_INCLUDES += $(LOCAL_PATH)/include +LOCAL_CFLAGS := -Werror #LOCAL_CFLAGS += -DLOG_NDEBUG=0 include $(BUILD_STATIC_LIBRARY) diff --git a/libsync/Android.mk b/libsync/Android.mk index 626b762..fd1c88c 100644 --- a/libsync/Android.mk +++ b/libsync/Android.mk @@ -7,6 +7,7 @@ LOCAL_MODULE_TAGS := optional LOCAL_SHARED_LIBRARIES := liblog LOCAL_C_INCLUDES := $(LOCAL_PATH)/include LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include +LOCAL_CFLAGS := -Werror include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) @@ -15,4 +16,5 @@ LOCAL_MODULE := sync_test LOCAL_MODULE_TAGS := optional tests LOCAL_SHARED_LIBRARIES := liblog LOCAL_C_INCLUDES := $(LOCAL_PATH)/include +LOCAL_CFLAGS := -Werror include $(BUILD_EXECUTABLE) diff --git a/libusbhost/Android.mk b/libusbhost/Android.mk index acfc020..5c12f2c 100644 --- a/libusbhost/Android.mk +++ b/libusbhost/Android.mk @@ -25,6 +25,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := libusbhost LOCAL_SRC_FILES := usbhost.c +LOCAL_CFLAGS := -Werror include $(BUILD_HOST_STATIC_LIBRARY) @@ -38,7 +39,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := libusbhost LOCAL_SRC_FILES := usbhost.c -LOCAL_CFLAGS := -g -DUSE_LIBLOG +LOCAL_CFLAGS := -g -DUSE_LIBLOG -Werror # needed for logcat LOCAL_SHARED_LIBRARIES := libcutils @@ -52,5 +53,6 @@ include $(CLEAR_VARS) LOCAL_MODULE := libusbhost LOCAL_SRC_FILES := usbhost.c +LOCAL_CFLAGS := -Werror include $(BUILD_STATIC_LIBRARY) diff --git a/libutils/Printer.cpp b/libutils/Printer.cpp index 263e740..1dc8632 100644 --- a/libutils/Printer.cpp +++ b/libutils/Printer.cpp @@ -25,10 +25,6 @@ #include <stdio.h> #include <stdlib.h> -#ifndef __BIONIC__ -#define fdprintf dprintf -#endif - namespace android { /* @@ -120,7 +116,7 @@ void FdPrinter::printLine(const char* string) { } #ifndef USE_MINGW - fdprintf(mFd, mFormatString, mPrefix, string); + dprintf(mFd, mFormatString, mPrefix, string); #endif } diff --git a/libziparchive/zip_archive_test.cc b/libziparchive/zip_archive_test.cc index 3082216..2eb9318 100644 --- a/libziparchive/zip_archive_test.cc +++ b/libziparchive/zip_archive_test.cc @@ -209,7 +209,8 @@ TEST(ziparchive, ExtractToFile) { sizeof(kATxtContents))); // Assert that the total length of the file is sane - ASSERT_EQ(data_size + sizeof(kATxtContents), lseek64(fd, 0, SEEK_END)); + ASSERT_EQ(data_size + static_cast<ssize_t>(sizeof(kATxtContents)), + lseek64(fd, 0, SEEK_END)); close(fd); } @@ -247,4 +248,3 @@ int main(int argc, char** argv) { return RUN_ALL_TESTS(); } - diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp index db4fddd..16fe7ee 100644 --- a/logcat/logcat.cpp +++ b/logcat/logcat.cpp @@ -623,18 +623,14 @@ int main(int argc, char **argv) } if (!devices) { - devices = new log_device_t("main", false, 'm'); + dev = devices = new log_device_t("main", false, 'm'); android::g_devCount = 1; if (android_name_to_log_id("system") == LOG_ID_SYSTEM) { - devices->next = new log_device_t("system", false, 's'); + dev = dev->next = new log_device_t("system", false, 's'); android::g_devCount++; } if (android_name_to_log_id("crash") == LOG_ID_CRASH) { - if (devices->next) { - devices->next->next = new log_device_t("crash", false, 'c'); - } else { - devices->next = new log_device_t("crash", false, 'c'); - } + dev = dev->next = new log_device_t("crash", false, 'c'); android::g_devCount++; } } diff --git a/logd/Android.mk b/logd/Android.mk index 9f4c64f..188511f 100644 --- a/logd/Android.mk +++ b/logd/Android.mk @@ -17,7 +17,8 @@ LOCAL_SRC_FILES := \ LogStatistics.cpp \ LogWhiteBlackList.cpp \ libaudit.c \ - LogAudit.cpp + LogAudit.cpp \ + event.logtags LOCAL_SHARED_LIBRARIES := \ libsysutils \ @@ -25,7 +26,7 @@ LOCAL_SHARED_LIBRARIES := \ libcutils \ libutils -LOCAL_CFLAGS := -Werror +LOCAL_CFLAGS := -Werror $(shell sed -n 's/^\([0-9]*\)[ \t]*auditd[ \t].*/-DAUDITD_LOG_TAG=\1/p' $(LOCAL_PATH)/event.logtags) include $(BUILD_EXECUTABLE) diff --git a/logd/LogAudit.cpp b/logd/LogAudit.cpp index add0f0e..f8d6162 100644 --- a/logd/LogAudit.cpp +++ b/logd/LogAudit.cpp @@ -54,9 +54,6 @@ bool LogAudit::onDataAvailable(SocketClient *cli) { return true; } -#define AUDIT_LOG_ID LOG_ID_MAIN -#define AUDIT_LOG_PRIO ANDROID_LOG_WARN - int LogAudit::logPrint(const char *fmt, ...) { if (fmt == NULL) { return -EINVAL; @@ -73,6 +70,11 @@ int LogAudit::logPrint(const char *fmt, ...) { return rc; } + char *cp; + while ((cp = strstr(str, " "))) { + memmove(cp, cp + 1, strlen(cp + 1) + 1); + } + if (fdDmesg >= 0) { struct iovec iov[2]; @@ -91,12 +93,11 @@ int LogAudit::logPrint(const char *fmt, ...) { static const char audit_str[] = " audit("; char *timeptr = strstr(str, audit_str); - char *cp; if (timeptr && ((cp = now.strptime(timeptr + sizeof(audit_str) - 1, "%s.%q"))) && (*cp == ':')) { memcpy(timeptr + sizeof(audit_str) - 1, "0.0", 3); - strcpy(timeptr + sizeof(audit_str) - 1 + 3, cp); + memmove(timeptr + sizeof(audit_str) - 1 + 3, cp, strlen(cp) + 1); } else { now.strptime("", ""); // side effect of setting CLOCK_REALTIME } @@ -112,50 +113,88 @@ int LogAudit::logPrint(const char *fmt, ...) { } tid = pid; uid = logbuf->pidToUid(pid); - strcpy(pidptr, cp); + memmove(pidptr, cp, strlen(cp) + 1); + } + + // log to events + + size_t l = strlen(str); + size_t n = l + sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint32_t); + + bool notify = false; + + char *newstr = reinterpret_cast<char *>(malloc(n)); + if (!newstr) { + rc = -ENOMEM; + } else { + cp = newstr; + *cp++ = AUDITD_LOG_TAG & 0xFF; + *cp++ = (AUDITD_LOG_TAG >> 8) & 0xFF; + *cp++ = (AUDITD_LOG_TAG >> 16) & 0xFF; + *cp++ = (AUDITD_LOG_TAG >> 24) & 0xFF; + *cp++ = EVENT_TYPE_STRING; + *cp++ = l & 0xFF; + *cp++ = (l >> 8) & 0xFF; + *cp++ = (l >> 16) & 0xFF; + *cp++ = (l >> 24) & 0xFF; + memcpy(cp, str, l); + + logbuf->log(LOG_ID_EVENTS, now, uid, pid, tid, newstr, + (n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX); + free(newstr); + + notify = true; } + // log to main + static const char comm_str[] = " comm=\""; - char *comm = strstr(str, comm_str); + const char *comm = strstr(str, comm_str); + const char *estr = str + strlen(str); if (comm) { - cp = comm; + estr = comm; comm += sizeof(comm_str) - 1; - char *ecomm = strchr(comm, '"'); - if (ecomm) { - *ecomm = '\0'; - } - comm = strdup(comm); - if (ecomm) { - strcpy(cp, ecomm + 1); - } } else if (pid == getpid()) { pid = tid; - comm = strdup("auditd"); + comm = "auditd"; } else if (!(comm = logbuf->pidToName(pid))) { - comm = strdup("unknown"); + comm = "unknown"; } - size_t l = strlen(comm) + 1; - size_t n = l + strlen(str) + 2; + const char *ecomm = strchr(comm, '"'); + if (ecomm) { + ++ecomm; + l = ecomm - comm; + } else { + l = strlen(comm) + 1; + ecomm = ""; + } + n = (estr - str) + strlen(ecomm) + l + 2; - char *newstr = reinterpret_cast<char *>(malloc(n)); + newstr = reinterpret_cast<char *>(malloc(n)); if (!newstr) { - free(comm); - free(str); - return -ENOMEM; + rc = -ENOMEM; + } else { + *newstr = (strstr(str, " permissive=1") + || strstr(str, " policy loaded ")) + ? ANDROID_LOG_INFO + : ANDROID_LOG_WARN; + strlcpy(newstr + 1, comm, l); + strncpy(newstr + 1 + l, str, estr - str); + strcpy(newstr + 1 + l + (estr - str), ecomm); + + logbuf->log(LOG_ID_MAIN, now, uid, pid, tid, newstr, + (n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX); + free(newstr); + + notify = true; } - *newstr = AUDIT_LOG_PRIO; - strcpy(newstr + 1, comm); - free(comm); - strcpy(newstr + 1 + l, str); free(str); - logbuf->log(AUDIT_LOG_ID, now, uid, pid, tid, newstr, - (n <= USHRT_MAX) ? (unsigned short) n : USHRT_MAX); - reader->notifyNewLog(); - - free(newstr); + if (notify) { + reader->notifyNewLog(); + } return rc; } diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index ae167aa..0448afa 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -174,7 +174,7 @@ void LogBuffer::log(log_id_t log_id, log_time realtime, if (last == mLogElements.end()) { mLogElements.push_back(elem); } else { - log_time end; + log_time end = log_time::EPOCH; bool end_set = false; bool end_always = false; diff --git a/logd/event.logtags b/logd/event.logtags new file mode 100644 index 0000000..a63f034 --- /dev/null +++ b/logd/event.logtags @@ -0,0 +1,36 @@ +# The entries in this file map a sparse set of log tag numbers to tag names. +# This is installed on the device, in /system/etc, and parsed by logcat. +# +# Tag numbers are decimal integers, from 0 to 2^31. (Let's leave the +# negative values alone for now.) +# +# Tag names are one or more ASCII letters and numbers or underscores, i.e. +# "[A-Z][a-z][0-9]_". Do not include spaces or punctuation (the former +# impacts log readability, the latter makes regex searches more annoying). +# +# Tag numbers and names are separated by whitespace. Blank lines and lines +# starting with '#' are ignored. +# +# Optionally, after the tag names can be put a description for the value(s) +# of the tag. Description are in the format +# (<name>|data type[|data unit]) +# Multiple values are separated by commas. +# +# The data type is a number from the following values: +# 1: int +# 2: long +# 3: string +# 4: list +# +# The data unit is a number taken from the following list: +# 1: Number of objects +# 2: Number of bytes +# 3: Number of milliseconds +# 4: Number of allocations +# 5: Id +# 6: Percent +# Default value for data of type int/long is 2 (bytes). +# +# TODO: generate ".java" and ".h" files with integer constants from this file. + +1003 auditd (avc|3) diff --git a/reboot/Android.mk b/reboot/Android.mk index 4db0c1e..7a24f99 100644 --- a/reboot/Android.mk +++ b/reboot/Android.mk @@ -1,12 +1,14 @@ # Copyright 2013 The Android Open Source Project -LOCAL_PATH:= $(call my-dir) +LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_SRC_FILES:= reboot.c +LOCAL_SRC_FILES := reboot.c -LOCAL_SHARED_LIBRARIES:= libcutils +LOCAL_SHARED_LIBRARIES := libcutils -LOCAL_MODULE:= reboot +LOCAL_MODULE := reboot + +LOCAL_CFLAGS := -Werror include $(BUILD_EXECUTABLE) diff --git a/rootdir/init.rc b/rootdir/init.rc index ed756e0..9f60081 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -98,7 +98,6 @@ loglevel 3 write /proc/sys/kernel/sched_child_runs_first 0 write /proc/sys/kernel/randomize_va_space 2 write /proc/sys/kernel/kptr_restrict 2 - write /proc/sys/kernel/dmesg_restrict 1 write /proc/sys/vm/mmap_min_addr 32768 write /proc/sys/net/ipv4/ping_group_range "0 2147483647" write /proc/sys/net/unix/max_dgram_qlen 300 @@ -227,6 +226,7 @@ on post-fs-data mkdir /data/misc/sms 0770 system radio mkdir /data/misc/zoneinfo 0775 system system mkdir /data/misc/vpn 0770 system vpn + mkdir /data/misc/shared_relro 0771 shared_relro shared_relro mkdir /data/misc/systemkeys 0700 system system mkdir /data/misc/wifi 0770 wifi wifi mkdir /data/misc/wifi/sockets 0770 wifi wifi diff --git a/rootdir/init.zygote64_32.rc b/rootdir/init.zygote64_32.rc new file mode 100644 index 0000000..979ab3b --- /dev/null +++ b/rootdir/init.zygote64_32.rc @@ -0,0 +1,12 @@ +service zygote /system/bin/app_process64 -Xzygote /system/bin --zygote --start-system-server --socket-name=zygote + class main + socket zygote stream 660 root system + onrestart write /sys/android_power/request_state wake + onrestart write /sys/power/state on + onrestart restart media + onrestart restart netd + +service zygote_secondary /system/bin/app_process32 -Xzygote /system/bin --zygote --socket-name=zygote_secondary + class main + socket zygote_secondary stream 660 root system + onrestart restart zygote diff --git a/sdcard/Android.mk b/sdcard/Android.mk index 4630db9..63b0f41 100644 --- a/sdcard/Android.mk +++ b/sdcard/Android.mk @@ -1,10 +1,10 @@ -LOCAL_PATH:= $(call my-dir) +LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_SRC_FILES:= sdcard.c -LOCAL_MODULE:= sdcard -LOCAL_CFLAGS := -Wall -Wno-unused-parameter +LOCAL_SRC_FILES := sdcard.c +LOCAL_MODULE := sdcard +LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror LOCAL_SHARED_LIBRARIES := libc libcutils diff --git a/toolbox/Android.mk b/toolbox/Android.mk index 5383b83..fddf0a9 100644 --- a/toolbox/Android.mk +++ b/toolbox/Android.mk @@ -96,7 +96,7 @@ LOCAL_C_INCLUDES := bionic/libc/bionic LOCAL_CFLAGS += \ -std=gnu99 \ - -Wno-unused-parameter \ + -Werror -Wno-unused-parameter \ -include bsd-compatibility.h \ LOCAL_SHARED_LIBRARIES := \ diff --git a/toolbox/cp/cp.c b/toolbox/cp/cp.c index bd3c70e..e666453 100644 --- a/toolbox/cp/cp.c +++ b/toolbox/cp/cp.c @@ -95,12 +95,14 @@ enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE }; static int copy(char *[], enum op, int); +#ifndef ANDROID static void progress(int sig __unused) { pinfo++; } +#endif int cp_main(int argc, char *argv[]) diff --git a/toolbox/cp/utils.c b/toolbox/cp/utils.c index b682bbe..9d0390f 100644 --- a/toolbox/cp/utils.c +++ b/toolbox/cp/utils.c @@ -380,10 +380,11 @@ copy_special(struct stat *from_stat, int exists) int setfile(struct stat *fs, int fd) { - int rval, islink; + int rval = 0; +#ifndef ANDROID + int islink = S_ISLNK(fs->st_mode); +#endif - rval = 0; - islink = S_ISLNK(fs->st_mode); fs->st_mode &= S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO; /* @@ -401,13 +402,13 @@ setfile(struct stat *fs, int fd) fs->st_mode &= ~(S_ISUID | S_ISGID); } #ifdef ANDROID - if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode)) { + if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode)) { #else - if (fd ? fchmod(fd, fs->st_mode) : lchmod(to.p_path, fs->st_mode)) { + if (fd ? fchmod(fd, fs->st_mode) : lchmod(to.p_path, fs->st_mode)) { #endif - warn("chmod: %s", to.p_path); - rval = 1; - } + warn("chmod: %s", to.p_path); + rval = 1; + } #ifndef ANDROID if (!islink && !Nflag) { diff --git a/toolbox/date.c b/toolbox/date.c index aa3b72e..70ce1d5 100644 --- a/toolbox/date.c +++ b/toolbox/date.c @@ -140,14 +140,12 @@ static char *parse_time(const char *str, struct timeval *ts) { int date_main(int argc, char *argv[]) { - int c; + int c; int res; - struct tm tm; - time_t t; - struct timeval tv; - struct timespec ts; - char strbuf[260]; - int fd; + struct tm tm; + time_t t; + struct timeval tv; + char strbuf[260]; int useutc = 0; @@ -177,7 +175,6 @@ int date_main(int argc, char *argv[]) int hasfmt = argc == optind + 1 && argv[optind][0] == '+'; if(optind == argc || hasfmt) { - char buf[2000]; time(&t); if (useutc) { gmtime_r(&t, &tm); diff --git a/toolbox/dd.c b/toolbox/dd.c index 6b61ffb..408a496 100644 --- a/toolbox/dd.c +++ b/toolbox/dd.c @@ -356,7 +356,7 @@ dd_in(void) ++st.in_full; /* Handle full input blocks. */ - } else if (n == in.dbsz) { + } else if (n == (int64_t)in.dbsz) { in.dbcnt += in.dbrcnt = n; ++st.in_full; @@ -521,7 +521,7 @@ dd_out(int force) outp += nw; st.bytes += nw; if (nw == n) { - if (n != out.dbsz) + if (n != (int64_t)out.dbsz) ++st.out_part; else ++st.out_full; @@ -649,8 +649,8 @@ pos_in(void) void pos_out(void) { -// struct mtop t_op; - int cnt, n; +/* struct mtop t_op; */ + int64_t cnt, n; /* * If not a tape, try seeking on the file. Seeking on a pipe is @@ -681,7 +681,7 @@ pos_out(void) } /* Read it. */ - for (cnt = 0; cnt < out.offset; ++cnt) { + for (cnt = 0; cnt < (int64_t)out.offset; ++cnt) { if ((n = read(out.fd, out.db, out.dbsz)) > 0) continue; @@ -705,8 +705,8 @@ pos_out(void) /* NOTREACHED */ } - while (cnt++ < out.offset) - if ((n = bwrite(out.fd, out.db, out.dbsz)) != out.dbsz) { + while (cnt++ < (int64_t)out.offset) + if ((n = bwrite(out.fd, out.db, out.dbsz)) != (int64_t)out.dbsz) { fprintf(stderr, "%s: cannot position " "by writing: %s\n", out.name, strerror(errno)); @@ -1153,7 +1153,7 @@ c_arg(const void *a, const void *b) ((const struct arg *)b)->name)); } -static long long strsuftoll(const char* name, const char* arg, int def, unsigned int max) +static long long strsuftoll(const char* name, const char* arg, int def, unsigned long long max) { long long result; @@ -1180,7 +1180,7 @@ static void f_count(char *arg) { - cpy_cnt = strsuftoll("block count", arg, 0, LLONG_MAX); + cpy_cnt = (uint64_t)strsuftoll("block count", arg, 0, 0xFFFFFFFFFFFFFFFFULL); if (!cpy_cnt) terminate(0); } @@ -1228,14 +1228,14 @@ static void f_seek(char *arg) { - out.offset = strsuftoll("seek blocks", arg, 0, LLONG_MAX); + out.offset = (uint64_t)strsuftoll("seek blocks", arg, 0, 0xFFFFFFFFFFFFFFFFULL); } static void f_skip(char *arg) { - in.offset = strsuftoll("skip blocks", arg, 0, LLONG_MAX); + in.offset = (uint64_t)strsuftoll("skip blocks", arg, 0, 0xFFFFFFFFFFFFFFFFULL); } static void diff --git a/toolbox/du.c b/toolbox/du.c index fc7c943..c8beba5 100644 --- a/toolbox/du.c +++ b/toolbox/du.c @@ -76,7 +76,7 @@ du_main(int argc, char *argv[]) int64_t totalblocks; int ftsoptions, listfiles; int depth; - int Hflag, Lflag, aflag, ch, cflag, dflag, gkmflag, nflag, rval, sflag; + int Hflag, Lflag, aflag, ch, cflag, dflag, gkmflag, rval, sflag; const char *noargv[2]; Hflag = Lflag = aflag = cflag = dflag = gkmflag = sflag = 0; diff --git a/toolbox/getevent.c b/toolbox/getevent.c index ed381f5..c2256ff 100644 --- a/toolbox/getevent.c +++ b/toolbox/getevent.c @@ -492,13 +492,11 @@ int getevent_main(int argc, char *argv[]) int c; int i; int res; - int pollres; int get_time = 0; int print_device = 0; char *newline = "\n"; uint16_t get_switch = 0; struct input_event event; - int version; int print_flags = 0; int print_flags_set = 0; int dont_block = -1; @@ -629,7 +627,8 @@ int getevent_main(int argc, char *argv[]) return 0; while(1) { - pollres = poll(ufds, nfds, -1); + //int pollres = + poll(ufds, nfds, -1); //printf("poll %d, returned %d\n", nfds, pollres); if(ufds[0].revents & POLLIN) { read_notify(device_path, ufds[0].fd, print_flags); diff --git a/toolbox/getevent.h b/toolbox/getevent.h index 2b76209..0482d04 100644 --- a/toolbox/getevent.h +++ b/toolbox/getevent.h @@ -652,6 +652,7 @@ static struct label snd_labels[] = { LABEL_END, }; +#if 0 static struct label id_labels[] = { LABEL(ID_BUS), LABEL(ID_VENDOR), @@ -682,6 +683,7 @@ static struct label bus_labels[] = { LABEL(BUS_SPI), LABEL_END, }; +#endif static struct label mt_tool_labels[] = { LABEL(MT_TOOL_FINGER), diff --git a/toolbox/getprop.c b/toolbox/getprop.c index 7fd694d..dcc0ea0 100644 --- a/toolbox/getprop.c +++ b/toolbox/getprop.c @@ -32,8 +32,6 @@ static void list_properties(void) int getprop_main(int argc, char *argv[]) { - int n = 0; - if (argc == 1) { list_properties(); } else { diff --git a/toolbox/grep/file.c b/toolbox/grep/file.c index 86b7658..d28dff5 100644 --- a/toolbox/grep/file.c +++ b/toolbox/grep/file.c @@ -78,7 +78,9 @@ static inline int grep_refill(struct file *f) { ssize_t nr; +#ifndef ANDROID int bzerr; +#endif bufpos = buffer; bufrem = 0; diff --git a/toolbox/grep/grep.c b/toolbox/grep/grep.c index 5a4fa0c..7b2c487 100644 --- a/toolbox/grep/grep.c +++ b/toolbox/grep/grep.c @@ -403,7 +403,7 @@ grep_main(int argc, char *argv[]) Aflag = 0; else if (Aflag > LLONG_MAX / 10) { errno = ERANGE; - err(2, NULL); + err(2, "%llu", Aflag); } Aflag = Bflag = (Aflag * 10) + (c - '0'); break; @@ -420,10 +420,10 @@ grep_main(int argc, char *argv[]) l = strtoull(optarg, &ep, 10); if (((errno == ERANGE) && (l == ULLONG_MAX)) || ((errno == EINVAL) && (l == 0))) - err(2, NULL); + err(2, "strtoull"); else if (ep[0] != '\0') { errno = EINVAL; - err(2, NULL); + err(2, "empty"); } if (c == 'A') Aflag = l; @@ -509,10 +509,10 @@ grep_main(int argc, char *argv[]) mcount = strtoull(optarg, &ep, 10); if (((errno == ERANGE) && (mcount == ULLONG_MAX)) || ((errno == EINVAL) && (mcount == 0))) - err(2, NULL); + err(2, "strtoull"); else if (ep[0] != '\0') { errno = EINVAL; - err(2, NULL); + err(2, "empty"); } break; case 'n': diff --git a/toolbox/grep/util.c b/toolbox/grep/util.c index 497db06..5712fee 100644 --- a/toolbox/grep/util.c +++ b/toolbox/grep/util.c @@ -273,7 +273,7 @@ procfile(const char *fn) return (c); } -#define iswword(x) (iswalnum((x)) || (x) == L'_') +#define iswword(x) (iswalnum((wint_t)(x)) || (x) == L'_') /* * Processes a line comparing it with the specified patterns. Each pattern @@ -323,7 +323,7 @@ procline(struct str *l, int nottext) continue; /* Check for whole word match */ if (fg_pattern[i].word && pmatch.rm_so != 0) { - wint_t wbegin, wend; + wchar_t wbegin, wend; wbegin = wend = L' '; if (pmatch.rm_so != 0 && diff --git a/toolbox/hd.c b/toolbox/hd.c index 0d2f96a..7c9998e 100644 --- a/toolbox/hd.c +++ b/toolbox/hd.c @@ -14,7 +14,6 @@ int hd_main(int argc, char *argv[]) unsigned char buf[4096]; int res; int read_len; - int rv = 0; int i; int filepos = 0; int sum; diff --git a/toolbox/insmod.c b/toolbox/insmod.c index fb1448b..d252433 100644 --- a/toolbox/insmod.c +++ b/toolbox/insmod.c @@ -73,7 +73,7 @@ int insmod_main(int argc, char **argv) char *ptr = opts; for (i = 2; (i < argc) && (ptr < end); i++) { - len = MIN(strlen(argv[i]), end - ptr); + len = MIN(strlen(argv[i]), (size_t)(end - ptr)); memcpy(ptr, argv[i], len); ptr += len; *ptr++ = ' '; diff --git a/toolbox/ioctl.c b/toolbox/ioctl.c index fb555d2..17fabff 100644 --- a/toolbox/ioctl.c +++ b/toolbox/ioctl.c @@ -21,9 +21,9 @@ int ioctl_main(int argc, char *argv[]) int arg_size = 4; int direct_arg = 0; uint32_t ioctl_nr; - void *ioctl_args; + void *ioctl_args = NULL; uint8_t *ioctl_argp; - uint8_t *ioctl_argp_save; + uint8_t *ioctl_argp_save = NULL; int rem; do { @@ -112,6 +112,7 @@ int ioctl_main(int argc, char *argv[]) else res = ioctl(fd, ioctl_nr, 0); if (res < 0) { + free(ioctl_args); fprintf(stderr, "ioctl 0x%x failed, %d\n", ioctl_nr, res); return 1; } @@ -124,5 +125,6 @@ int ioctl_main(int argc, char *argv[]) } printf("\n"); } + free(ioctl_args); return 0; } diff --git a/toolbox/load_policy.c b/toolbox/load_policy.c index eb5aba6..90d48c4 100644 --- a/toolbox/load_policy.c +++ b/toolbox/load_policy.c @@ -10,7 +10,7 @@ int load_policy_main(int argc, char **argv) { - int fd, rc, vers; + int fd, rc; struct stat sb; void *map; const char *path; diff --git a/toolbox/ls.c b/toolbox/ls.c index 06910ee..011f7b5 100644 --- a/toolbox/ls.c +++ b/toolbox/ls.c @@ -443,7 +443,6 @@ static int listpath(const char *name, int flags) int ls_main(int argc, char **argv) { int flags = 0; - int listed = 0; if(argc > 1) { int i; diff --git a/toolbox/lsof.c b/toolbox/lsof.c index af321af..bee981d 100644 --- a/toolbox/lsof.c +++ b/toolbox/lsof.c @@ -99,10 +99,7 @@ out: static void print_maps(struct pid_info_t* info) { FILE *maps; - char buffer[PATH_MAX + 100]; - size_t offset; - int major, minor; char device[10]; long int inode; char file[PATH_MAX]; diff --git a/toolbox/mkdir.c b/toolbox/mkdir.c index 656970a..398d350 100644 --- a/toolbox/mkdir.c +++ b/toolbox/mkdir.c @@ -15,7 +15,6 @@ static int usage() int mkdir_main(int argc, char *argv[]) { - int symbolic = 0; int ret; if(argc < 2 || strcmp(argv[1], "--help") == 0) { return usage(); diff --git a/toolbox/newfs_msdos.c b/toolbox/newfs_msdos.c index 27dca42..30b9f77 100644 --- a/toolbox/newfs_msdos.c +++ b/toolbox/newfs_msdos.c @@ -360,7 +360,7 @@ newfs_msdos_main(int argc, char *argv[]) if (!opt_create && !strchr(fname, '/')) { snprintf(buf, sizeof(buf), "%s%s", _PATH_DEV, fname); if (!(fname = strdup(buf))) - err(1, NULL); + err(1, "%s", buf); } dtype = *argv; if (opt_create) { @@ -493,7 +493,7 @@ newfs_msdos_main(int argc, char *argv[]) if (!strchr(bname, '/')) { snprintf(buf, sizeof(buf), "/boot/%s", bname); if (!(bname = strdup(buf))) - err(1, NULL); + err(1, "%s", buf); } if ((fd1 = open(bname, O_RDONLY)) == -1 || fstat(fd1, &sb)) err(1, "%s", bname); @@ -611,7 +611,7 @@ newfs_msdos_main(int argc, char *argv[]) now = tv.tv_sec; tm = localtime(&now); if (!(img = malloc(bpb.bps))) - err(1, NULL); + err(1, "%u", bpb.bps); dir = bpb.res + (bpb.spf ? bpb.spf : bpb.bspf) * bpb.nft; for (lsn = 0; lsn < dir + (fat == 32 ? bpb.spc : rds); lsn++) { x = lsn; @@ -728,14 +728,14 @@ newfs_msdos_main(int argc, char *argv[]) static void check_mounted(const char *fname, mode_t mode) { +#ifdef ANDROID + warnx("Skipping mount checks"); +#else struct statfs *mp; const char *s1, *s2; size_t len; int n, r; -#ifdef ANDROID - warnx("Skipping mount checks"); -#else if (!(n = getmntinfo(&mp, MNT_NOWAIT))) err(1, "getmntinfo"); len = strlen(_PATH_DEV); diff --git a/toolbox/ps.c b/toolbox/ps.c index e9fba0b..57b4280 100644 --- a/toolbox/ps.c +++ b/toolbox/ps.c @@ -43,7 +43,7 @@ static int ps_line(int pid, int tid, char *namefilter) struct stat stats; int fd, r; char *ptr, *name, *state; - int ppid, tty; + int ppid; unsigned wchan, rss, vss, eip; unsigned utime, stime; int prio, nice, rtprio, sched, psr; @@ -91,7 +91,7 @@ static int ps_line(int pid, int tid, char *namefilter) ppid = atoi(nexttok(&ptr)); nexttok(&ptr); // pgrp nexttok(&ptr); // sid - tty = atoi(nexttok(&ptr)); + nexttok(&ptr); // tty nexttok(&ptr); // tpgid nexttok(&ptr); // flags @@ -133,7 +133,7 @@ static int ps_line(int pid, int tid, char *namefilter) rtprio = atoi(nexttok(&ptr)); // rt_priority sched = atoi(nexttok(&ptr)); // scheduling policy - tty = atoi(nexttok(&ptr)); + nexttok(&ptr); // tty if(tid != 0) { ppid = pid; diff --git a/toolbox/rmdir.c b/toolbox/rmdir.c index 06f3df2..749fec8 100644 --- a/toolbox/rmdir.c +++ b/toolbox/rmdir.c @@ -11,7 +11,6 @@ static int usage() int rmdir_main(int argc, char *argv[]) { - int symbolic = 0; int ret; if(argc < 2) return usage(); diff --git a/toolbox/schedtop.c b/toolbox/schedtop.c index 0c85e76..2fccd2e 100644 --- a/toolbox/schedtop.c +++ b/toolbox/schedtop.c @@ -227,7 +227,6 @@ static void update_table(DIR *d, uint32_t flags) } for (i = 0; i < last_processes.active; i++) { int pid = last_processes.data[i].pid; - int tid = last_processes.data[i].tid; for (j = 0; j < processes.active; j++) if (pid == processes.data[j].pid) break; @@ -270,9 +269,6 @@ int schedtop_main(int argc, char **argv) { int c; DIR *d; - struct dirent *de; - char *namefilter = 0; - int pidfilter = 0; uint32_t flags = 0; int delay = 3000000; float delay_f; diff --git a/toolbox/sendevent.c b/toolbox/sendevent.c index 1608e6c..9b813f6 100644 --- a/toolbox/sendevent.c +++ b/toolbox/sendevent.c @@ -47,9 +47,8 @@ struct input_event { int sendevent_main(int argc, char *argv[]) { - int i; int fd; - int ret; + ssize_t ret; int version; struct input_event event; @@ -72,7 +71,7 @@ int sendevent_main(int argc, char *argv[]) event.code = atoi(argv[3]); event.value = atoi(argv[4]); ret = write(fd, &event, sizeof(event)); - if(ret < sizeof(event)) { + if(ret < (ssize_t) sizeof(event)) { fprintf(stderr, "write event failed, %s\n", strerror(errno)); return -1; } diff --git a/toolbox/start.c b/toolbox/start.c index 26344da..0941e64 100644 --- a/toolbox/start.c +++ b/toolbox/start.c @@ -7,8 +7,6 @@ int start_main(int argc, char *argv[]) { - char buf[1024]; - if(argc > 1) { property_set("ctl.start", argv[1]); } else { diff --git a/toolbox/stop.c b/toolbox/stop.c index 6552c7c..ed9a293 100644 --- a/toolbox/stop.c +++ b/toolbox/stop.c @@ -5,8 +5,6 @@ int stop_main(int argc, char *argv[]) { - char buf[1024]; - if(argc > 1) { property_set("ctl.stop", argv[1]); } else{ diff --git a/toolbox/top.c b/toolbox/top.c index 7382f1f..280a032 100644 --- a/toolbox/top.c +++ b/toolbox/top.c @@ -328,7 +328,6 @@ static void read_procs(void) { static int read_stat(char *filename, struct proc_info *proc) { FILE *file; char buf[MAX_LINE], *open_paren, *close_paren; - int res, idx; file = fopen(filename, "r"); if (!file) return 1; @@ -414,9 +413,7 @@ static void print_procs(void) { struct proc_info *old_proc, *proc; long unsigned total_delta_time; struct passwd *user; - struct group *group; char *user_str, user_buf[20]; - char *group_str, group_buf[20]; for (i = 0; i < num_new_procs; i++) { if (new_procs[i]) { @@ -467,19 +464,12 @@ static void print_procs(void) { if (!proc || (max_procs && (i >= max_procs))) break; user = getpwuid(proc->uid); - group = getgrgid(proc->gid); if (user && user->pw_name) { user_str = user->pw_name; } else { snprintf(user_buf, 20, "%d", proc->uid); user_str = user_buf; } - if (group && group->gr_name) { - group_str = group->gr_name; - } else { - snprintf(group_buf, 20, "%d", proc->gid); - group_str = group_buf; - } if (!threads) printf("%5d %2d %3ld%% %c %5d %6ldK %6ldK %3s %-8.8s %s\n", proc->pid, proc->prs, proc->delta_time * 100 / total_delta_time, proc->state, proc->num_threads, proc->vss / 1024, proc->rss * getpagesize() / 1024, proc->policy, user_str, proc->name[0] != 0 ? proc->name : proc->tname); diff --git a/toolbox/umount.c b/toolbox/umount.c index 890e870..3e17396 100644 --- a/toolbox/umount.c +++ b/toolbox/umount.c @@ -33,7 +33,6 @@ static int is_loop_mount(const char* path, char *loopdev) char mount_path[256]; char rest[256]; int result = 0; - int path_length = strlen(path); f = fopen("/proc/mounts", "r"); if (!f) { diff --git a/toolbox/watchprops.c b/toolbox/watchprops.c index bf82882..0d05aba 100644 --- a/toolbox/watchprops.c +++ b/toolbox/watchprops.c @@ -6,8 +6,6 @@ #include <cutils/properties.h> #include <cutils/hashmap.h> -#include <sys/atomics.h> - #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include <sys/_system_properties.h> @@ -23,9 +21,9 @@ static bool str_equals(void *keyA, void *keyB) static void announce(char *name, char *value) { - char *x; + unsigned char *x; - for(x = value; *x; x++) { + for(x = (unsigned char *)value; *x; x++) { if((*x < 32) || (*x > 127)) *x = '.'; } @@ -77,9 +75,7 @@ static void update_watchlist(const prop_info *pi, void *cookie) int watchprops_main(int argc, char *argv[]) { - unsigned serial = 0; - unsigned count = 0; - unsigned n; + unsigned serial; Hashmap *watchlist = hashmapCreate(1024, str_hash, str_equals); if (!watchlist) @@ -87,7 +83,7 @@ int watchprops_main(int argc, char *argv[]) __system_property_foreach(populate_watchlist, watchlist); - for(;;) { + for(serial = 0;;) { serial = __system_property_wait_any(serial); __system_property_foreach(update_watchlist, watchlist); } |