Merge "Export AIDL files as a filegroup for framework.jar"
diff --git a/adb/OVERVIEW.TXT b/adb/OVERVIEW.TXT
index c40695a..29a6992 100644
--- a/adb/OVERVIEW.TXT
+++ b/adb/OVERVIEW.TXT
@@ -7,16 +7,16 @@
- keep track of all Android devices and emulators instances
connected to or running on a given host developer machine
-- implement various control commands (e.g. "adb shell", "adb pull", etc..)
+- implement various control commands (e.g. "adb shell", "adb pull", etc.)
for the benefit of clients (command-line users, or helper programs like
- DDMS). These commands are what is called a 'service' in ADB.
+ DDMS). These commands are called 'services' in ADB.
As a whole, everything works through the following components:
1. The ADB server
This is a background process that runs on the host machine. Its purpose
- if to sense the USB ports to know when devices are attached/removed,
+ is to sense the USB ports to know when devices are attached/removed,
as well as when emulator instances start/stop.
It thus maintains a list of "connected devices" and assigns a 'state'
@@ -40,7 +40,7 @@
meaning that the ADB server detected a new device/emulator, but could not
connect to the adbd daemon.
- the BOOTLOADER and RECOVERY states correspond to alternate states of
+ The BOOTLOADER and RECOVERY states correspond to alternate states of
devices when they are in the bootloader or recovery mode.
3. The ADB command-line client
@@ -49,8 +49,7 @@
or a script. It first tries to locate the ADB server on the host machine,
and will start one automatically if none is found.
- then, the client sends its service requests to the ADB server. It doesn't
- need to know.
+ Then, the client sends its service requests to the ADB server.
Currently, a single 'adb' binary is used for both the server and client.
this makes distribution and starting the server easier.
@@ -61,13 +60,13 @@
There are essentially two kinds of services that a client can talk to.
Host Services:
- these services run within the ADB Server and thus do not need to
+ These services run within the ADB Server and thus do not need to
communicate with a device at all. A typical example is "adb devices"
which is used to return the list of currently known devices and their
- state. They are a few couple other services though.
+ states. They are a few other services though.
Local Services:
- these services either run within the adbd daemon, or are started by
+ These services either run within the adbd daemon, or are started by
it on the device. The ADB server is used to multiplex streams
between the client and the service running in adbd. In this case
its role is to initiate the connection, then of being a pass-through
@@ -109,7 +108,7 @@
Note that the connection is still alive after an OKAY, which allows the
client to make other requests. But in certain cases, an OKAY will even
- change the state of the connection.
+ change the state of the connection.
For example, the case of the 'host:transport:<serialnumber>' request,
where '<serialnumber>' is used to identify a given device/emulator; after
diff --git a/adb/SYNC.TXT b/adb/SYNC.TXT
index 06d7804..4445a76 100644
--- a/adb/SYNC.TXT
+++ b/adb/SYNC.TXT
@@ -1,4 +1,4 @@
-This file tries to document file related requests a client can make
+This file tries to document file-related requests a client can make
to the ADB server of an adbd daemon. See the OVERVIEW.TXT document
to understand what's going on here. See the SERVICES.TXT to learn more
about the other requests that are possible.
@@ -8,16 +8,16 @@
Requesting the sync service ("sync:") using the protocol as described in
SERVICES.TXT sets the connection in sync mode. This mode is a binary mode that
-differ from the regular adb protocol. The connection stays in sync mode until
+differs from the regular adb protocol. The connection stays in sync mode until
explicitly terminated (see below).
After the initial "sync:" command is sent the server must respond with either
-"OKAY" or "FAIL" as per usual.
+"OKAY" or "FAIL" as per usual.
In sync mode both the server and the client will frequently use eight-byte
-packets to communicate in this document called sync request and sync
-responses. The first four bytes is an id and specifies sync request is
-represented by four utf-8 characters. The last four bytes is a Little-Endian
+packets to communicate. In this document these are called sync requests and sync
+responses. The first four bytes are an id that specifies the sync request. It is
+represented by four utf-8 characters. The last four bytes are a Little-Endian
integer, with various uses. This number will be called "length" below. In fact
all binary integers are Little-Endian in the sync mode. Sync mode is
implicitly exited after each sync request, and normal adb communication
@@ -29,8 +29,8 @@
SEND - Send a file to device
STAT - Stat a file
-For all of the sync request above the must be followed by length number of
-bytes containing an utf-8 string with a remote filename.
+All of the sync requests above must be followed by "length": the number of
+bytes containing a utf-8 string with a remote filename.
LIST:
Lists files in the directory specified by the remote filename. The server will
@@ -45,7 +45,7 @@
6. length number of bytes containing an utf-8 string representing the file
name.
-When an sync response "DONE" is received the listing is done.
+When a sync response "DONE" is received the listing is done.
SEND:
The remote file name is split into two parts separated by the last
@@ -65,7 +65,7 @@
When the file is transferred a sync request "DONE" is sent, where length is set
to the last modified time for the file. The server responds to this last
-request (but not to chuck requests) with an "OKAY" sync response (length can
+request (but not to chunk requests) with an "OKAY" sync response (length can
be ignored).
@@ -73,9 +73,8 @@
Retrieves a file from device to a local file. The remote path is the path to
the file that will be returned. Just as for the SEND sync request the file
received is split up into chunks. The sync response id is "DATA" and length is
-the chuck size. After follows chunk size number of bytes. This is repeated
-until the file is transferred. Each chuck will not be larger than 64k.
+the chunk size. After follows chunk size number of bytes. This is repeated
+until the file is transferred. Each chunk will not be larger than 64k.
When the file is transferred a sync response "DONE" is retrieved where the
length can be ignored.
-
diff --git a/base/Android.bp b/base/Android.bp
index 7ff02a0..ad0edf4 100644
--- a/base/Android.bp
+++ b/base/Android.bp
@@ -129,6 +129,7 @@
},
windows: {
srcs: ["utf8_test.cpp"],
+ cflags: ["-Wno-unused-parameter"],
enabled: true,
},
},
diff --git a/base/logging_test.cpp b/base/logging_test.cpp
index adb041b..6f05d9b 100644
--- a/base/logging_test.cpp
+++ b/base/logging_test.cpp
@@ -192,6 +192,7 @@
#undef CHECK_WOULD_LOG_ENABLED
+#if !defined(_WIN32)
static std::string make_log_pattern(android::base::LogSeverity severity,
const char* message) {
static const char log_characters[] = "VDIWEFF";
@@ -203,6 +204,7 @@
"%c \\d+-\\d+ \\d+:\\d+:\\d+ \\s*\\d+ \\s*\\d+ %s:\\d+] %s",
log_char, basename(&holder[0]), message);
}
+#endif
static void CheckMessage(const CapturedStderr& cap,
android::base::LogSeverity severity, const char* expected) {
diff --git a/base/utf8.cpp b/base/utf8.cpp
index 5984fb0..adb46d0 100644
--- a/base/utf8.cpp
+++ b/base/utf8.cpp
@@ -195,7 +195,7 @@
return _wfopen(name_utf16.c_str(), mode_utf16.c_str());
}
-int mkdir(const char* name, mode_t mode) {
+int mkdir(const char* name, mode_t) {
std::wstring name_utf16;
if (!UTF8PathToWindowsLongPath(name, &name_utf16)) {
return -1;
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index d9db1bd..f1c6793 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -238,6 +238,10 @@
{"watchdog_apps_bite", 98},
{"xpu_err", 99},
{"power_on_usb", 100},
+ {"watchdog_rpm", 101},
+ {"watchdog_nonsec", 102},
+ {"watchdog_apps_bark", 103},
+ {"reboot_dmverity_corrupted", 104},
};
// Converts a string value representing the reason the system booted to an
diff --git a/fastboot/fs.cpp b/fastboot/fs.cpp
index 4141a3b..4bf7af8 100644
--- a/fastboot/fs.cpp
+++ b/fastboot/fs.cpp
@@ -27,7 +27,7 @@
using android::base::unique_fd;
#ifdef WIN32
-static int exec_e2fs_cmd(const char* path, char* const argv[]) {
+static int exec_e2fs_cmd(const char* /*path*/, char* const argv[]) {
std::string cmd;
int i = 0;
while (argv[i] != nullptr) {
@@ -185,6 +185,7 @@
}
return 0;
#else
+ UNUSED(fileName, partSize, initial_dir);
fprintf(stderr, "make_f2fs not supported on Windows\n");
return -1;
#endif
diff --git a/healthd/Android.bp b/healthd/Android.bp
index ed1413e..95bb5f5 100644
--- a/healthd/Android.bp
+++ b/healthd/Android.bp
@@ -27,8 +27,6 @@
"healthd_common.cpp",
],
- cflags: ["-DHEALTHD_USE_HEALTH_2_0"],
-
export_include_dirs: ["include"],
shared_libs: [
diff --git a/healthd/Android.mk b/healthd/Android.mk
index 5f10f1e..63c9d27 100644
--- a/healthd/Android.mk
+++ b/healthd/Android.mk
@@ -89,12 +89,6 @@
ifeq ($(strip $(LOCAL_CHARGER_NO_UI)),true)
LOCAL_CFLAGS += -DCHARGER_NO_UI
endif
-ifneq ($(BOARD_PERIODIC_CHORES_INTERVAL_FAST),)
-LOCAL_CFLAGS += -DBOARD_PERIODIC_CHORES_INTERVAL_FAST=$(BOARD_PERIODIC_CHORES_INTERVAL_FAST)
-endif
-ifneq ($(BOARD_PERIODIC_CHORES_INTERVAL_SLOW),)
-LOCAL_CFLAGS += -DBOARD_PERIODIC_CHORES_INTERVAL_SLOW=$(BOARD_PERIODIC_CHORES_INTERVAL_SLOW)
-endif
CHARGER_STATIC_LIBRARIES := \
android.hardware.health@2.0-impl \
diff --git a/healthd/charger_test.cpp b/healthd/charger_test.cpp
index acc0f5b..a7e2161 100644
--- a/healthd/charger_test.cpp
+++ b/healthd/charger_test.cpp
@@ -27,7 +27,7 @@
#include <thread>
#include <vector>
-#include <healthd/healthd.h>
+#include <health2/Health.h>
#define LOG_THIS(fmt, ...) \
ALOGE(fmt, ##__VA_ARGS__); \
@@ -97,6 +97,16 @@
return status;
}
+::android::hardware::hidl_handle createHidlHandle(const char* filepath) {
+ int fd = creat(filepath, S_IRUSR | S_IWUSR);
+ if (fd < 0) return {};
+ native_handle_t* nativeHandle = native_handle_create(1, 0);
+ nativeHandle->data[0] = fd;
+ ::android::hardware::hidl_handle handle;
+ handle.setTo(nativeHandle, true /* shouldOwn */);
+ return handle;
+}
+
void healthd_board_init(struct healthd_config* config) {
config->periodic_chores_interval_fast = 60;
config->periodic_chores_interval_slow = 600;
@@ -129,6 +139,8 @@
extern int healthd_charger_main(int argc, char** argv);
int main(int argc, char** argv) {
+ using android::hardware::health::V2_0::implementation::Health;
+
const char* dumpFile = "/data/local/tmp/dump.txt";
std::thread bgThread([=] {
@@ -141,12 +153,7 @@
exit(1);
}
- int fd = creat(dumpFile, S_IRUSR | S_IWUSR);
- if (fd < 0) {
- exit(errno);
- }
- healthd_dump_battery_state(fd);
- close(fd);
+ Health::getImplementation()->debug(createHidlHandle(dumpFile), {} /* options */);
std::string content = openToString(dumpFile);
int status = expectContains(content, {
diff --git a/healthd/healthd_common.cpp b/healthd/healthd_common.cpp
index 140c49d..3006644 100644
--- a/healthd/healthd_common.cpp
+++ b/healthd/healthd_common.cpp
@@ -33,25 +33,14 @@
#include <sys/timerfd.h>
#include <utils/Errors.h>
-#ifdef HEALTHD_USE_HEALTH_2_0
#include <health2/Health.h>
-#endif
using namespace android;
-#ifndef BOARD_PERIODIC_CHORES_INTERVAL_FAST
- // Periodic chores fast interval in seconds
- #define DEFAULT_PERIODIC_CHORES_INTERVAL_FAST (60 * 1)
-#else
- #define DEFAULT_PERIODIC_CHORES_INTERVAL_FAST (BOARD_PERIODIC_CHORES_INTERVAL_FAST)
-#endif
-
-#ifndef BOARD_PERIODIC_CHORES_INTERVAL_SLOW
- // Periodic chores fast interval in seconds
- #define DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW (60 * 10)
-#else
- #define DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW (BOARD_PERIODIC_CHORES_INTERVAL_SLOW)
-#endif
+// Periodic chores fast interval in seconds
+#define DEFAULT_PERIODIC_CHORES_INTERVAL_FAST (60 * 1)
+// Periodic chores fast interval in seconds
+#define DEFAULT_PERIODIC_CHORES_INTERVAL_SLOW (60 * 10)
static struct healthd_config healthd_config = {
.periodic_chores_interval_fast = DEFAULT_PERIODIC_CHORES_INTERVAL_FAST,
@@ -88,11 +77,7 @@
static int wakealarm_wake_interval = DEFAULT_PERIODIC_CHORES_INTERVAL_FAST;
-#ifndef HEALTHD_USE_HEALTH_2_0
-static BatteryMonitor* gBatteryMonitor = nullptr;
-#else
using ::android::hardware::health::V2_0::implementation::Health;
-#endif
struct healthd_mode_ops *healthd_mode_ops = nullptr;
@@ -135,81 +120,6 @@
KLOG_ERROR(LOG_TAG, "wakealarm_set_interval: timerfd_settime failed\n");
}
-#ifdef HEALTHD_USE_HEALTH_2_0
-status_t convertStatus(android::hardware::health::V2_0::Result r) {
- using android::hardware::health::V2_0::Result;
- switch(r) {
- case Result::SUCCESS: return OK;
- case Result::NOT_SUPPORTED: return BAD_VALUE;
- case Result::NOT_FOUND: return NAME_NOT_FOUND;
- case Result::CALLBACK_DIED: return DEAD_OBJECT;
- case Result::UNKNOWN: // fallthrough
- default:
- return UNKNOWN_ERROR;
- }
-}
-#endif
-
-status_t healthd_get_property(int id, struct BatteryProperty *val) {
-#ifndef HEALTHD_USE_HEALTH_2_0
- return gBatteryMonitor->getProperty(id, val);
-#else
- using android::hardware::health::V1_0::BatteryStatus;
- using android::hardware::health::V2_0::Result;
- val->valueInt64 = INT64_MIN;
- status_t err = UNKNOWN_ERROR;
- switch (id) {
- case BATTERY_PROP_CHARGE_COUNTER: {
- Health::getImplementation()->getChargeCounter([&](Result r, int32_t v) {
- err = convertStatus(r);
- val->valueInt64 = v;
- });
- break;
- }
- case BATTERY_PROP_CURRENT_NOW: {
- Health::getImplementation()->getCurrentNow([&](Result r, int32_t v) {
- err = convertStatus(r);
- val->valueInt64 = v;
- });
- break;
- }
- case BATTERY_PROP_CURRENT_AVG: {
- Health::getImplementation()->getCurrentAverage([&](Result r, int32_t v) {
- err = convertStatus(r);
- val->valueInt64 = v;
- });
- break;
- }
- case BATTERY_PROP_CAPACITY: {
- Health::getImplementation()->getCapacity([&](Result r, int32_t v) {
- err = convertStatus(r);
- val->valueInt64 = v;
- });
- break;
- }
- case BATTERY_PROP_ENERGY_COUNTER: {
- Health::getImplementation()->getEnergyCounter([&](Result r, int64_t v) {
- err = convertStatus(r);
- val->valueInt64 = v;
- });
- break;
- }
- case BATTERY_PROP_BATTERY_STATUS: {
- Health::getImplementation()->getChargeStatus([&](Result r, BatteryStatus v) {
- err = convertStatus(r);
- val->valueInt64 = static_cast<int64_t>(v);
- });
- break;
- }
- default: {
- err = BAD_VALUE;
- break;
- }
- }
- return err;
-#endif
-}
-
void healthd_battery_update_internal(bool charger_online) {
// Fast wake interval when on charger (watch for overheat);
// slow wake interval when on battery (watch for drained battery).
@@ -233,26 +143,8 @@
-1 : healthd_config.periodic_chores_interval_fast * 1000;
}
-void healthd_battery_update(void) {
-#ifndef HEALTHD_USE_HEALTH_2_0
- healthd_battery_update_internal(gBatteryMonitor->update());
-#else
+static void healthd_battery_update(void) {
Health::getImplementation()->update();
-#endif
-}
-
-void healthd_dump_battery_state(int fd) {
-#ifndef HEALTHD_USE_HEALTH_2_0
- gBatteryMonitor->dumpState(fd);
-#else
- native_handle_t* nativeHandle = native_handle_create(1, 0);
- nativeHandle->data[0] = fd;
- ::android::hardware::hidl_handle handle;
- handle.setTo(nativeHandle, true /* shouldOwn */);
- Health::getImplementation()->debug(handle, {} /* options */);
-#endif
-
- fsync(fd);
}
static void periodic_chores() {
@@ -368,21 +260,10 @@
return -1;
}
-#ifndef HEALTHD_USE_HEALTH_2_0
- healthd_board_init(&healthd_config);
-#else
- // healthd_board_* functions are removed in health@2.0
-#endif
-
healthd_mode_ops->init(&healthd_config);
wakealarm_init();
uevent_init();
-#ifndef HEALTHD_USE_HEALTH_2_0
- gBatteryMonitor = new BatteryMonitor();
- gBatteryMonitor->init(&healthd_config);
-#endif
-
return 0;
}
diff --git a/healthd/include/healthd/healthd.h b/healthd/include/healthd/healthd.h
index 97c7a8c..c01e8d7 100644
--- a/healthd/include/healthd/healthd.h
+++ b/healthd/include/healthd/healthd.h
@@ -81,15 +81,6 @@
// Global helper functions
int healthd_register_event(int fd, void (*handler)(uint32_t), EventWakeup wakeup = EVENT_NO_WAKEUP_FD);
-void healthd_battery_update();
-
-// deprecated.
-// TODO(b/62229583): This function should be removed since it is only used by
-// BatteryPropertiesRegistrar.
-android::status_t healthd_get_property(int id,
- struct android::BatteryProperty *val);
-
-void healthd_dump_battery_state(int fd);
struct healthd_mode_ops {
void (*init)(struct healthd_config *config);
diff --git a/init/selinux.cpp b/init/selinux.cpp
index 3f9f7f4..21010b0 100644
--- a/init/selinux.cpp
+++ b/init/selinux.cpp
@@ -302,18 +302,18 @@
}
std::string mapping_file("/system/etc/selinux/mapping/" + vend_plat_vers + ".cil");
- // vendor_sepolicy.cil and nonplat_declaration.cil are the new design to replace
+ // vendor_sepolicy.cil and plat_pub_versioned.cil are the new design to replace
// nonplat_sepolicy.cil.
- std::string nonplat_declaration_cil_file("/vendor/etc/selinux/nonplat_declaration.cil");
+ std::string plat_pub_versioned_cil_file("/vendor/etc/selinux/plat_pub_versioned.cil");
std::string vendor_policy_cil_file("/vendor/etc/selinux/vendor_sepolicy.cil");
if (access(vendor_policy_cil_file.c_str(), F_OK) == -1) {
// For backward compatibility.
// TODO: remove this after no device is using nonplat_sepolicy.cil.
vendor_policy_cil_file = "/vendor/etc/selinux/nonplat_sepolicy.cil";
- nonplat_declaration_cil_file.clear();
- } else if (access(nonplat_declaration_cil_file.c_str(), F_OK) == -1) {
- LOG(ERROR) << "Missing " << nonplat_declaration_cil_file;
+ plat_pub_versioned_cil_file.clear();
+ } else if (access(plat_pub_versioned_cil_file.c_str(), F_OK) == -1) {
+ LOG(ERROR) << "Missing " << plat_pub_versioned_cil_file;
return false;
}
@@ -338,8 +338,8 @@
};
// clang-format on
- if (!nonplat_declaration_cil_file.empty()) {
- compile_args.push_back(nonplat_declaration_cil_file.c_str());
+ if (!plat_pub_versioned_cil_file.empty()) {
+ compile_args.push_back(plat_pub_versioned_cil_file.c_str());
}
if (!vendor_policy_cil_file.empty()) {
compile_args.push_back(vendor_policy_cil_file.c_str());
diff --git a/libcutils/android_reboot.cpp b/libcutils/android_reboot.cpp
index 5e864d4..ce41cd3 100644
--- a/libcutils/android_reboot.cpp
+++ b/libcutils/android_reboot.cpp
@@ -23,7 +23,7 @@
#define TAG "android_reboot"
-int android_reboot(int cmd, int flags __unused, const char* arg) {
+int android_reboot(int cmd, int /*flags*/, const char* arg) {
int ret;
const char* restart_cmd = NULL;
char* prop_value;
diff --git a/libcutils/ashmem-host.cpp b/libcutils/ashmem-host.cpp
index d2c28f3..b2bec99 100644
--- a/libcutils/ashmem-host.cpp
+++ b/libcutils/ashmem-host.cpp
@@ -35,12 +35,7 @@
#include <utils/Compat.h>
-#ifndef __unused
-#define __unused __attribute__((__unused__))
-#endif
-
-int ashmem_create_region(const char *ignored __unused, size_t size)
-{
+int ashmem_create_region(const char* /*ignored*/, size_t size) {
char pattern[PATH_MAX];
snprintf(pattern, sizeof(pattern), "/tmp/android-ashmem-%d-XXXXXXXXX", getpid());
int fd = mkstemp(pattern);
@@ -56,18 +51,15 @@
return fd;
}
-int ashmem_set_prot_region(int fd __unused, int prot __unused)
-{
+int ashmem_set_prot_region(int /*fd*/, int /*prot*/) {
return 0;
}
-int ashmem_pin_region(int fd __unused, size_t offset __unused, size_t len __unused)
-{
+int ashmem_pin_region(int /*fd*/, size_t /*offset*/, size_t /*len*/) {
return 0 /*ASHMEM_NOT_PURGED*/;
}
-int ashmem_unpin_region(int fd __unused, size_t offset __unused, size_t len __unused)
-{
+int ashmem_unpin_region(int /*fd*/, size_t /*offset*/, size_t /*len*/) {
return 0 /*ASHMEM_IS_UNPINNED*/;
}
diff --git a/libcutils/sched_policy.cpp b/libcutils/sched_policy.cpp
index 0e6d333..f5ce82f 100644
--- a/libcutils/sched_policy.cpp
+++ b/libcutils/sched_policy.cpp
@@ -27,8 +27,6 @@
#include <log/log.h>
-#define UNUSED __attribute__((__unused__))
-
/* Re-map SP_DEFAULT to the system default policy, and leave other values unchanged.
* Call this any place a SchedPolicy is used as an input parameter.
* Returns the possibly re-mapped policy.
@@ -445,13 +443,11 @@
/* Stubs for non-Android targets. */
-int set_sched_policy(int tid UNUSED, SchedPolicy policy UNUSED)
-{
+int set_sched_policy(int /*tid*/, SchedPolicy /*policy*/) {
return 0;
}
-int get_sched_policy(int tid UNUSED, SchedPolicy *policy)
-{
+int get_sched_policy(int /*tid*/, SchedPolicy* policy) {
*policy = SP_SYSTEM_DEFAULT;
return 0;
}
diff --git a/libcutils/socket_local_client_unix.cpp b/libcutils/socket_local_client_unix.cpp
index 68b2b0c..d2b4909 100644
--- a/libcutils/socket_local_client_unix.cpp
+++ b/libcutils/socket_local_client_unix.cpp
@@ -39,8 +39,6 @@
#include "socket_local_unix.h"
-#define UNUSED __attribute__((unused))
-
#define LISTEN_BACKLOG 4
/* Documented in header file. */
@@ -123,9 +121,7 @@
*
* Used by AndroidSocketImpl
*/
-int socket_local_client_connect(int fd, const char *name, int namespaceId,
- int type UNUSED)
-{
+int socket_local_client_connect(int fd, const char* name, int namespaceId, int /*type*/) {
struct sockaddr_un addr;
socklen_t alen;
int err;
diff --git a/libcutils/sockets_windows.cpp b/libcutils/sockets_windows.cpp
index 3e49b85..df14712 100644
--- a/libcutils/sockets_windows.cpp
+++ b/libcutils/sockets_windows.cpp
@@ -85,6 +85,6 @@
return -1;
}
-int android_get_control_socket(const char* name) {
+int android_get_control_socket(const char*) {
return -1;
}
diff --git a/libcutils/str_parms.cpp b/libcutils/str_parms.cpp
index 139d62f..f5a52a7 100644
--- a/libcutils/str_parms.cpp
+++ b/libcutils/str_parms.cpp
@@ -30,8 +30,6 @@
#include <cutils/memory.h>
#include <log/log.h>
-#define UNUSED __attribute__((unused))
-
/* When an object is allocated but not freed in a function,
* because its ownership is released to other object like a hashmap,
* call RELEASE_OWNERSHIP to tell the clang analyzer and avoid
@@ -364,8 +362,7 @@
return str;
}
-static bool dump_entry(void *key, void *value, void *context UNUSED)
-{
+static bool dump_entry(void* key, void* value, void* /*context*/) {
ALOGI("key: '%s' value: '%s'\n", (char *)key, (char *)value);
return true;
}
diff --git a/libcutils/threads.cpp b/libcutils/threads.cpp
index beea8bd..a7e6b2d 100644
--- a/libcutils/threads.cpp
+++ b/libcutils/threads.cpp
@@ -84,7 +84,7 @@
void thread_store_set( thread_store_t* store,
void* value,
- thread_store_destruct_t destroy )
+ thread_store_destruct_t /*destroy*/ )
{
/* XXX: can't use destructor on thread exit */
if (!store->lock_init) {
diff --git a/libcutils/trace-host.cpp b/libcutils/trace-host.cpp
index 05842cd..d47cc18 100644
--- a/libcutils/trace-host.cpp
+++ b/libcutils/trace-host.cpp
@@ -16,21 +16,17 @@
#include <cutils/trace.h>
-#ifndef __unused
-#define __unused __attribute__((__unused__))
-#endif
-
atomic_bool atrace_is_ready = ATOMIC_VAR_INIT(true);
int atrace_marker_fd = -1;
uint64_t atrace_enabled_tags = 0;
-void atrace_set_debuggable(bool debuggable __unused) { }
-void atrace_set_tracing_enabled(bool enabled __unused) { }
+void atrace_set_debuggable(bool /*debuggable*/) {}
+void atrace_set_tracing_enabled(bool /*enabled*/) {}
void atrace_update_tags() { }
void atrace_setup() { }
-void atrace_begin_body(const char* name __unused) { }
+void atrace_begin_body(const char* /*name*/) {}
void atrace_end_body() { }
-void atrace_async_begin_body(const char* name __unused, int32_t cookie __unused) { }
-void atrace_async_end_body(const char* name __unused, int32_t cookie __unused) { }
-void atrace_int_body(const char* name __unused, int32_t value __unused) { }
-void atrace_int64_body(const char* name __unused, int64_t value __unused) { }
+void atrace_async_begin_body(const char* /*name*/, int32_t /*cookie*/) {}
+void atrace_async_end_body(const char* /*name*/, int32_t /*cookie*/) {}
+void atrace_int_body(const char* /*name*/, int32_t /*value*/) {}
+void atrace_int64_body(const char* /*name*/, int64_t /*value*/) {}
diff --git a/liblog/event_tag_map.cpp b/liblog/event_tag_map.cpp
index 83064fd..2e2bf87 100644
--- a/liblog/event_tag_map.cpp
+++ b/liblog/event_tag_map.cpp
@@ -25,9 +25,9 @@
#include <string.h>
#include <sys/mman.h>
-#include <experimental/string_view>
#include <functional>
#include <string>
+#include <string_view>
#include <unordered_map>
#include <log/event_tag_map.h>
@@ -44,10 +44,10 @@
class MapString {
private:
const std::string* alloc; // HAS-AN
- const std::experimental::string_view str; // HAS-A
+ const std::string_view str; // HAS-A
public:
- operator const std::experimental::string_view() const {
+ operator const std::string_view() const {
return str;
}
@@ -92,8 +92,7 @@
: public std::unary_function<const MapString&, size_t> {
size_t operator()(const MapString& __t) const noexcept {
if (!__t.length()) return 0;
- return std::hash<std::experimental::string_view>()(
- std::experimental::string_view(__t));
+ return std::hash<std::string_view>()(std::string_view(__t));
}
};
diff --git a/libunwindstack/DwarfMemory.cpp b/libunwindstack/DwarfMemory.cpp
index 901f492..6ffdc0d 100644
--- a/libunwindstack/DwarfMemory.cpp
+++ b/libunwindstack/DwarfMemory.cpp
@@ -27,7 +27,7 @@
namespace unwindstack {
bool DwarfMemory::ReadBytes(void* dst, size_t num_bytes) {
- if (!memory_->Read(cur_offset_, dst, num_bytes)) {
+ if (!memory_->ReadFully(cur_offset_, dst, num_bytes)) {
return false;
}
cur_offset_ += num_bytes;
diff --git a/libunwindstack/DwarfOp.cpp b/libunwindstack/DwarfOp.cpp
index b3fd0df..3b3d340 100644
--- a/libunwindstack/DwarfOp.cpp
+++ b/libunwindstack/DwarfOp.cpp
@@ -141,7 +141,7 @@
// Read the address and dereference it.
AddressType addr = StackPop();
AddressType value;
- if (!regular_memory()->Read(addr, &value, sizeof(value))) {
+ if (!regular_memory()->ReadFully(addr, &value, sizeof(value))) {
last_error_ = DWARF_ERROR_MEMORY_INVALID;
return false;
}
@@ -159,7 +159,7 @@
// Read the address and dereference it.
AddressType addr = StackPop();
AddressType value = 0;
- if (!regular_memory()->Read(addr, &value, bytes_to_read)) {
+ if (!regular_memory()->ReadFully(addr, &value, bytes_to_read)) {
last_error_ = DWARF_ERROR_MEMORY_INVALID;
return false;
}
diff --git a/libunwindstack/DwarfSection.cpp b/libunwindstack/DwarfSection.cpp
index 805dcd3..0954187 100644
--- a/libunwindstack/DwarfSection.cpp
+++ b/libunwindstack/DwarfSection.cpp
@@ -142,7 +142,7 @@
return false;
}
if (loc->type == DWARF_LOCATION_EXPRESSION) {
- if (!regular_memory->Read(value, &cfa, sizeof(AddressType))) {
+ if (!regular_memory->ReadFully(value, &cfa, sizeof(AddressType))) {
last_error_ = DWARF_ERROR_MEMORY_INVALID;
return false;
}
@@ -175,7 +175,8 @@
const DwarfLocation* loc = &entry.second;
switch (loc->type) {
case DWARF_LOCATION_OFFSET:
- if (!regular_memory->Read(cfa + loc->values[0], &(*cur_regs)[reg], sizeof(AddressType))) {
+ if (!regular_memory->ReadFully(cfa + loc->values[0], &(*cur_regs)[reg],
+ sizeof(AddressType))) {
last_error_ = DWARF_ERROR_MEMORY_INVALID;
return false;
}
@@ -210,7 +211,7 @@
return false;
}
if (loc->type == DWARF_LOCATION_EXPRESSION) {
- if (!regular_memory->Read(value, &(*cur_regs)[reg], sizeof(AddressType))) {
+ if (!regular_memory->ReadFully(value, &(*cur_regs)[reg], sizeof(AddressType))) {
last_error_ = DWARF_ERROR_MEMORY_INVALID;
return false;
}
diff --git a/libunwindstack/Elf.cpp b/libunwindstack/Elf.cpp
index 48e33ee..97ade56 100644
--- a/libunwindstack/Elf.cpp
+++ b/libunwindstack/Elf.cpp
@@ -136,7 +136,7 @@
// Verify that this is a valid elf file.
uint8_t e_ident[SELFMAG + 1];
- if (!memory->Read(0, e_ident, SELFMAG)) {
+ if (!memory->ReadFully(0, e_ident, SELFMAG)) {
return false;
}
@@ -156,7 +156,7 @@
// Now read the section header information.
uint8_t class_type;
- if (!memory->Read(EI_CLASS, &class_type, 1)) {
+ if (!memory->ReadFully(EI_CLASS, &class_type, 1)) {
return;
}
if (class_type == ELFCLASS32) {
@@ -174,12 +174,12 @@
}
std::unique_ptr<ElfInterface> interface;
- if (!memory->Read(EI_CLASS, &class_type_, 1)) {
+ if (!memory->ReadFully(EI_CLASS, &class_type_, 1)) {
return nullptr;
}
if (class_type_ == ELFCLASS32) {
Elf32_Half e_machine;
- if (!memory->Read(EI_NIDENT + sizeof(Elf32_Half), &e_machine, sizeof(e_machine))) {
+ if (!memory->ReadFully(EI_NIDENT + sizeof(Elf32_Half), &e_machine, sizeof(e_machine))) {
return nullptr;
}
@@ -200,7 +200,7 @@
}
} else if (class_type_ == ELFCLASS64) {
Elf64_Half e_machine;
- if (!memory->Read(EI_NIDENT + sizeof(Elf64_Half), &e_machine, sizeof(e_machine))) {
+ if (!memory->ReadFully(EI_NIDENT + sizeof(Elf64_Half), &e_machine, sizeof(e_machine))) {
return nullptr;
}
if (e_machine != EM_AARCH64 && e_machine != EM_X86_64) {
diff --git a/libunwindstack/ElfInterface.cpp b/libunwindstack/ElfInterface.cpp
index d5d158f..9bdb094 100644
--- a/libunwindstack/ElfInterface.cpp
+++ b/libunwindstack/ElfInterface.cpp
@@ -53,7 +53,7 @@
Crc64GenerateTable();
std::vector<uint8_t> src(gnu_debugdata_size_);
- if (!memory_->Read(gnu_debugdata_offset_, src.data(), gnu_debugdata_size_)) {
+ if (!memory_->ReadFully(gnu_debugdata_offset_, src.data(), gnu_debugdata_size_)) {
gnu_debugdata_offset_ = 0;
gnu_debugdata_size_ = static_cast<uint64_t>(-1);
return nullptr;
@@ -131,7 +131,7 @@
template <typename EhdrType, typename PhdrType, typename ShdrType>
bool ElfInterface::ReadAllHeaders(uint64_t* load_bias) {
EhdrType ehdr;
- if (!memory_->Read(0, &ehdr, sizeof(ehdr))) {
+ if (!memory_->ReadFully(0, &ehdr, sizeof(ehdr))) {
return false;
}
@@ -242,7 +242,7 @@
}
if (shdr.sh_type == SHT_SYMTAB || shdr.sh_type == SHT_DYNSYM) {
- if (!memory_->Read(offset, &shdr, sizeof(shdr))) {
+ if (!memory_->ReadFully(offset, &shdr, sizeof(shdr))) {
return false;
}
// Need to go get the information about the section that contains
@@ -324,7 +324,7 @@
uint64_t offset = dynamic_offset_;
uint64_t max_offset = offset + dynamic_size_;
for (uint64_t offset = dynamic_offset_; offset < max_offset; offset += sizeof(DynType)) {
- if (!memory_->Read(offset, &dyn, sizeof(dyn))) {
+ if (!memory_->ReadFully(offset, &dyn, sizeof(dyn))) {
return false;
}
@@ -388,7 +388,7 @@
template <typename EhdrType>
void ElfInterface::GetMaxSizeWithTemplate(Memory* memory, uint64_t* size) {
EhdrType ehdr;
- if (!memory->Read(0, &ehdr, sizeof(ehdr))) {
+ if (!memory->ReadFully(0, &ehdr, sizeof(ehdr))) {
return;
}
if (ehdr.e_shnum == 0) {
diff --git a/libunwindstack/MapInfo.cpp b/libunwindstack/MapInfo.cpp
index 5417659..8a7ad9c 100644
--- a/libunwindstack/MapInfo.cpp
+++ b/libunwindstack/MapInfo.cpp
@@ -102,7 +102,7 @@
if (!(flags & PROT_READ)) {
return nullptr;
}
- return new MemoryRange(process_memory, start, end);
+ return new MemoryRange(process_memory, start, end - start, 0);
}
Elf* MapInfo::GetElf(const std::shared_ptr<Memory>& process_memory, bool init_gnu_debugdata) {
diff --git a/libunwindstack/Memory.cpp b/libunwindstack/Memory.cpp
index 32753df..2479655 100644
--- a/libunwindstack/Memory.cpp
+++ b/libunwindstack/Memory.cpp
@@ -32,14 +32,69 @@
#include "Check.h"
+static size_t ProcessVmRead(pid_t pid, void* dst, uint64_t remote_src, size_t len) {
+ struct iovec dst_iov = {
+ .iov_base = dst,
+ .iov_len = len,
+ };
+
+ // Split up the remote read across page boundaries.
+ // From the manpage:
+ // A partial read/write may result if one of the remote_iov elements points to an invalid
+ // memory region in the remote process.
+ //
+ // Partial transfers apply at the granularity of iovec elements. These system calls won't
+ // perform a partial transfer that splits a single iovec element.
+ constexpr size_t kMaxIovecs = 64;
+ struct iovec src_iovs[kMaxIovecs];
+ size_t iovecs_used = 0;
+
+ uint64_t cur = remote_src;
+ while (len > 0) {
+ if (iovecs_used == kMaxIovecs) {
+ errno = EINVAL;
+ return 0;
+ }
+
+ // struct iovec uses void* for iov_base.
+ if (cur >= UINTPTR_MAX) {
+ errno = EFAULT;
+ return 0;
+ }
+
+ src_iovs[iovecs_used].iov_base = reinterpret_cast<void*>(cur);
+
+ uintptr_t misalignment = cur & (getpagesize() - 1);
+ size_t iov_len = getpagesize() - misalignment;
+ iov_len = std::min(iov_len, len);
+
+ len -= iov_len;
+ if (__builtin_add_overflow(cur, iov_len, &cur)) {
+ errno = EFAULT;
+ return 0;
+ }
+
+ src_iovs[iovecs_used].iov_len = iov_len;
+ ++iovecs_used;
+ }
+
+ ssize_t rc = process_vm_readv(pid, &dst_iov, 1, src_iovs, iovecs_used, 0);
+ return rc == -1 ? 0 : rc;
+}
+
namespace unwindstack {
+bool Memory::ReadFully(uint64_t addr, void* dst, size_t size) {
+ size_t rc = Read(addr, dst, size);
+ return rc == size;
+}
+
bool Memory::ReadString(uint64_t addr, std::string* string, uint64_t max_read) {
string->clear();
uint64_t bytes_read = 0;
while (bytes_read < max_read) {
uint8_t value;
- if (!Read(addr, &value, sizeof(value))) {
+ if (!ReadFully(addr, &value, sizeof(value))) {
return false;
}
if (value == '\0') {
@@ -59,16 +114,17 @@
return std::shared_ptr<Memory>(new MemoryRemote(pid));
}
-bool MemoryBuffer::Read(uint64_t addr, void* dst, size_t size) {
- uint64_t last_read_byte;
- if (__builtin_add_overflow(size, addr, &last_read_byte)) {
- return false;
+size_t MemoryBuffer::Read(uint64_t addr, void* dst, size_t size) {
+ if (addr >= raw_.size()) {
+ return 0;
}
- if (last_read_byte > raw_.size()) {
- return false;
- }
- memcpy(dst, &raw_[addr], size);
- return true;
+
+ size_t bytes_left = raw_.size() - static_cast<size_t>(addr);
+ const unsigned char* actual_base = static_cast<const unsigned char*>(raw_.data()) + addr;
+ size_t actual_len = std::min(bytes_left, size);
+
+ memcpy(dst, actual_base, actual_len);
+ return actual_len;
}
uint8_t* MemoryBuffer::GetPtr(size_t offset) {
@@ -129,145 +185,77 @@
return true;
}
-bool MemoryFileAtOffset::Read(uint64_t addr, void* dst, size_t size) {
- uint64_t max_size;
- if (__builtin_add_overflow(addr, size, &max_size) || max_size > size_) {
- return false;
+size_t MemoryFileAtOffset::Read(uint64_t addr, void* dst, size_t size) {
+ if (addr >= size_) {
+ return 0;
}
- memcpy(dst, &data_[addr], size);
- return true;
+
+ size_t bytes_left = size_ - static_cast<size_t>(addr);
+ const unsigned char* actual_base = static_cast<const unsigned char*>(data_) + addr;
+ size_t actual_len = std::min(bytes_left, size);
+
+ memcpy(dst, actual_base, actual_len);
+ return actual_len;
}
-bool MemoryRemote::PtraceRead(uint64_t addr, long* value) {
-#if !defined(__LP64__)
- // Cannot read an address greater than 32 bits.
- if (addr > UINT32_MAX) {
- return false;
- }
-#endif
- // ptrace() returns -1 and sets errno when the operation fails.
- // To disambiguate -1 from a valid result, we clear errno beforehand.
- errno = 0;
- *value = ptrace(PTRACE_PEEKTEXT, pid_, reinterpret_cast<void*>(addr), nullptr);
- if (*value == -1 && errno) {
- return false;
- }
- return true;
+size_t MemoryRemote::Read(uint64_t addr, void* dst, size_t size) {
+ return ProcessVmRead(pid_, dst, addr, size);
}
-bool MemoryRemote::Read(uint64_t addr, void* dst, size_t bytes) {
- // Make sure that there is no overflow.
- uint64_t max_size;
- if (__builtin_add_overflow(addr, bytes, &max_size)) {
- return false;
- }
-
- size_t bytes_read = 0;
- long data;
- size_t align_bytes = addr & (sizeof(long) - 1);
- if (align_bytes != 0) {
- if (!PtraceRead(addr & ~(sizeof(long) - 1), &data)) {
- return false;
- }
- size_t copy_bytes = std::min(sizeof(long) - align_bytes, bytes);
- memcpy(dst, reinterpret_cast<uint8_t*>(&data) + align_bytes, copy_bytes);
- addr += copy_bytes;
- dst = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(dst) + copy_bytes);
- bytes -= copy_bytes;
- bytes_read += copy_bytes;
- }
-
- for (size_t i = 0; i < bytes / sizeof(long); i++) {
- if (!PtraceRead(addr, &data)) {
- return false;
- }
- memcpy(dst, &data, sizeof(long));
- dst = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(dst) + sizeof(long));
- addr += sizeof(long);
- bytes_read += sizeof(long);
- }
-
- size_t left_over = bytes & (sizeof(long) - 1);
- if (left_over) {
- if (!PtraceRead(addr, &data)) {
- return false;
- }
- memcpy(dst, &data, left_over);
- bytes_read += left_over;
- }
- return true;
+size_t MemoryLocal::Read(uint64_t addr, void* dst, size_t size) {
+ return ProcessVmRead(getpid(), dst, addr, size);
}
-bool MemoryLocal::Read(uint64_t addr, void* dst, size_t size) {
- // Make sure that there is no overflow.
- uint64_t max_size;
- if (__builtin_add_overflow(addr, size, &max_size)) {
- return false;
+MemoryRange::MemoryRange(const std::shared_ptr<Memory>& memory, uint64_t begin, uint64_t length,
+ uint64_t offset)
+ : memory_(memory), begin_(begin), length_(length), offset_(offset) {}
+
+size_t MemoryRange::Read(uint64_t addr, void* dst, size_t size) {
+ if (addr < offset_) {
+ return 0;
}
- // The process_vm_readv call will not always work on remote
- // processes, so only use it for reads from the current pid.
- // Use this method to avoid crashes if an address is invalid since
- // unwind data could try to access any part of the address space.
- struct iovec local_io;
- local_io.iov_base = dst;
- local_io.iov_len = size;
-
- struct iovec remote_io;
- remote_io.iov_base = reinterpret_cast<void*>(static_cast<uintptr_t>(addr));
- remote_io.iov_len = size;
-
- ssize_t bytes_read = process_vm_readv(getpid(), &local_io, 1, &remote_io, 1, 0);
- if (bytes_read == -1) {
- return false;
+ uint64_t read_offset = addr - offset_;
+ if (read_offset >= length_) {
+ return 0;
}
- return static_cast<size_t>(bytes_read) == size;
+
+ uint64_t read_length = std::min(static_cast<uint64_t>(size), length_ - read_offset);
+ uint64_t read_addr;
+ if (__builtin_add_overflow(read_offset, begin_, &read_addr)) {
+ return 0;
+ }
+
+ return memory_->Read(read_addr, dst, read_length);
}
bool MemoryOffline::Init(const std::string& file, uint64_t offset) {
- if (!MemoryFileAtOffset::Init(file, offset)) {
+ auto memory_file = std::make_shared<MemoryFileAtOffset>();
+ if (!memory_file->Init(file, offset)) {
return false;
}
+
// The first uint64_t value is the start of memory.
- if (!MemoryFileAtOffset::Read(0, &start_, sizeof(start_))) {
+ uint64_t start;
+ if (!memory_file->ReadFully(0, &start, sizeof(start))) {
return false;
}
- // Subtract the first 64 bit value from the total size.
- size_ -= sizeof(start_);
+
+ uint64_t size = memory_file->Size();
+ if (__builtin_sub_overflow(size, sizeof(start), &size)) {
+ return false;
+ }
+
+ memory_ = std::make_unique<MemoryRange>(memory_file, sizeof(start), size, start);
return true;
}
-bool MemoryOffline::Read(uint64_t addr, void* dst, size_t size) {
- uint64_t max_size;
- if (__builtin_add_overflow(addr, size, &max_size)) {
- return false;
+size_t MemoryOffline::Read(uint64_t addr, void* dst, size_t size) {
+ if (!memory_) {
+ return 0;
}
- uint64_t real_size;
- if (__builtin_add_overflow(start_, offset_, &real_size) ||
- __builtin_add_overflow(real_size, size_, &real_size)) {
- return false;
- }
-
- if (addr < start_ || max_size > real_size) {
- return false;
- }
- memcpy(dst, &data_[addr + offset_ - start_ + sizeof(start_)], size);
- return true;
-}
-
-MemoryRange::MemoryRange(const std::shared_ptr<Memory>& memory, uint64_t begin, uint64_t end)
- : memory_(memory), begin_(begin), length_(end - begin) {
- CHECK(end > begin);
-}
-
-bool MemoryRange::Read(uint64_t addr, void* dst, size_t size) {
- uint64_t max_read;
- if (__builtin_add_overflow(addr, size, &max_read) || max_read > length_) {
- return false;
- }
- // The check above guarantees that addr + begin_ will not overflow.
- return memory_->Read(addr + begin_, dst, size);
+ return memory_->Read(addr, dst, size);
}
} // namespace unwindstack
diff --git a/libunwindstack/Regs.cpp b/libunwindstack/Regs.cpp
index 36b8e25..28a77dc 100644
--- a/libunwindstack/Regs.cpp
+++ b/libunwindstack/Regs.cpp
@@ -58,7 +58,7 @@
if (adjusted_rel_pc & 1) {
// This is a thumb instruction, it could be 2 or 4 bytes.
uint32_t value;
- if (rel_pc < 5 || !elf->memory()->Read(adjusted_rel_pc - 5, &value, sizeof(value)) ||
+ if (rel_pc < 5 || !elf->memory()->ReadFully(adjusted_rel_pc - 5, &value, sizeof(value)) ||
(value & 0xe000f000) != 0xe000f000) {
return rel_pc - 2;
}
@@ -193,7 +193,7 @@
bool RegsX86::SetPcFromReturnAddress(Memory* process_memory) {
// Attempt to get the return address from the top of the stack.
uint32_t new_pc;
- if (!process_memory->Read(sp_, &new_pc, sizeof(new_pc)) || new_pc == pc()) {
+ if (!process_memory->ReadFully(sp_, &new_pc, sizeof(new_pc)) || new_pc == pc()) {
return false;
}
@@ -240,7 +240,7 @@
bool RegsX86_64::SetPcFromReturnAddress(Memory* process_memory) {
// Attempt to get the return address from the top of the stack.
uint64_t new_pc;
- if (!process_memory->Read(sp_, &new_pc, sizeof(new_pc)) || new_pc == pc()) {
+ if (!process_memory->ReadFully(sp_, &new_pc, sizeof(new_pc)) || new_pc == pc()) {
return false;
}
@@ -474,7 +474,7 @@
Memory* elf_memory = elf->memory();
// Read from elf memory since it is usually more expensive to read from
// process memory.
- if (!elf_memory->Read(rel_pc, &data, sizeof(data))) {
+ if (!elf_memory->ReadFully(rel_pc, &data, sizeof(data))) {
return false;
}
@@ -493,7 +493,7 @@
// Form 3 (thumb):
// 0x77 0x27 movs r7, #77
// 0x00 0xdf svc 0
- if (!process_memory->Read(sp(), &data, sizeof(data))) {
+ if (!process_memory->ReadFully(sp(), &data, sizeof(data))) {
return false;
}
if (data == 0x5ac3c35a) {
@@ -517,7 +517,7 @@
// Form 3 (thumb):
// 0xad 0x27 movs r7, #ad
// 0x00 0xdf svc 0
- if (!process_memory->Read(sp(), &data, sizeof(data))) {
+ if (!process_memory->ReadFully(sp(), &data, sizeof(data))) {
return false;
}
if (data == sp() + 8) {
@@ -532,7 +532,7 @@
return false;
}
- if (!process_memory->Read(offset, regs_.data(), sizeof(uint32_t) * ARM_REG_LAST)) {
+ if (!process_memory->ReadFully(offset, regs_.data(), sizeof(uint32_t) * ARM_REG_LAST)) {
return false;
}
SetFromRaw();
@@ -544,7 +544,7 @@
Memory* elf_memory = elf->memory();
// Read from elf memory since it is usually more expensive to read from
// process memory.
- if (!elf_memory->Read(rel_pc, &data, sizeof(data))) {
+ if (!elf_memory->ReadFully(rel_pc, &data, sizeof(data))) {
return false;
}
@@ -557,8 +557,8 @@
}
// SP + sizeof(siginfo_t) + uc_mcontext offset + X0 offset.
- if (!process_memory->Read(sp() + 0x80 + 0xb0 + 0x08, regs_.data(),
- sizeof(uint64_t) * ARM64_REG_LAST)) {
+ if (!process_memory->ReadFully(sp() + 0x80 + 0xb0 + 0x08, regs_.data(),
+ sizeof(uint64_t) * ARM64_REG_LAST)) {
return false;
}
@@ -571,7 +571,7 @@
Memory* elf_memory = elf->memory();
// Read from elf memory since it is usually more expensive to read from
// process memory.
- if (!elf_memory->Read(rel_pc, &data, sizeof(data))) {
+ if (!elf_memory->ReadFully(rel_pc, &data, sizeof(data))) {
return false;
}
@@ -587,7 +587,7 @@
// int signum
// struct sigcontext (same format as mcontext)
struct x86_mcontext_t context;
- if (!process_memory->Read(sp() + 4, &context, sizeof(context))) {
+ if (!process_memory->ReadFully(sp() + 4, &context, sizeof(context))) {
return false;
}
regs_[X86_REG_EBP] = context.ebp;
@@ -613,12 +613,12 @@
// Get the location of the sigcontext data.
uint32_t ptr;
- if (!process_memory->Read(sp() + 8, &ptr, sizeof(ptr))) {
+ if (!process_memory->ReadFully(sp() + 8, &ptr, sizeof(ptr))) {
return false;
}
// Only read the portion of the data structure we care about.
x86_ucontext_t x86_ucontext;
- if (!process_memory->Read(ptr + 0x14, &x86_ucontext.uc_mcontext, sizeof(x86_mcontext_t))) {
+ if (!process_memory->ReadFully(ptr + 0x14, &x86_ucontext.uc_mcontext, sizeof(x86_mcontext_t))) {
return false;
}
SetFromUcontext(&x86_ucontext);
@@ -632,12 +632,12 @@
Memory* elf_memory = elf->memory();
// Read from elf memory since it is usually more expensive to read from
// process memory.
- if (!elf_memory->Read(rel_pc, &data, sizeof(data)) || data != 0x0f0000000fc0c748) {
+ if (!elf_memory->ReadFully(rel_pc, &data, sizeof(data)) || data != 0x0f0000000fc0c748) {
return false;
}
uint16_t data2;
- if (!elf_memory->Read(rel_pc + 8, &data2, sizeof(data2)) || data2 != 0x0f05) {
+ if (!elf_memory->ReadFully(rel_pc + 8, &data2, sizeof(data2)) || data2 != 0x0f05) {
return false;
}
@@ -649,7 +649,8 @@
// Read the mcontext data from the stack.
// sp points to the ucontext data structure, read only the mcontext part.
x86_64_ucontext_t x86_64_ucontext;
- if (!process_memory->Read(sp() + 0x28, &x86_64_ucontext.uc_mcontext, sizeof(x86_64_mcontext_t))) {
+ if (!process_memory->ReadFully(sp() + 0x28, &x86_64_ucontext.uc_mcontext,
+ sizeof(x86_64_mcontext_t))) {
return false;
}
SetFromUcontext(&x86_64_ucontext);
diff --git a/libunwindstack/Symbols.cpp b/libunwindstack/Symbols.cpp
index 42d816a..b4b92d6 100644
--- a/libunwindstack/Symbols.cpp
+++ b/libunwindstack/Symbols.cpp
@@ -71,7 +71,7 @@
bool return_value = false;
while (cur_offset_ + entry_size_ <= end_) {
SymType entry;
- if (!elf_memory->Read(cur_offset_, &entry, sizeof(entry))) {
+ if (!elf_memory->ReadFully(cur_offset_, &entry, sizeof(entry))) {
// Stop all processing, something looks like it is corrupted.
cur_offset_ = UINT64_MAX;
return false;
diff --git a/libunwindstack/include/unwindstack/Memory.h b/libunwindstack/include/unwindstack/Memory.h
index 183b899..8163152 100644
--- a/libunwindstack/include/unwindstack/Memory.h
+++ b/libunwindstack/include/unwindstack/Memory.h
@@ -36,7 +36,9 @@
virtual bool ReadString(uint64_t addr, std::string* string, uint64_t max_read = UINT64_MAX);
- virtual bool Read(uint64_t addr, void* dst, size_t size) = 0;
+ virtual size_t Read(uint64_t addr, void* dst, size_t size) = 0;
+
+ bool ReadFully(uint64_t addr, void* dst, size_t size);
inline bool ReadField(uint64_t addr, void* start, void* field, size_t size) {
if (reinterpret_cast<uintptr_t>(field) < reinterpret_cast<uintptr_t>(start)) {
@@ -47,12 +49,16 @@
return false;
}
// The read will check if offset + size overflows.
- return Read(offset, field, size);
+ return ReadFully(offset, field, size);
}
- inline bool Read32(uint64_t addr, uint32_t* dst) { return Read(addr, dst, sizeof(uint32_t)); }
+ inline bool Read32(uint64_t addr, uint32_t* dst) {
+ return ReadFully(addr, dst, sizeof(uint32_t));
+ }
- inline bool Read64(uint64_t addr, uint64_t* dst) { return Read(addr, dst, sizeof(uint64_t)); }
+ inline bool Read64(uint64_t addr, uint64_t* dst) {
+ return ReadFully(addr, dst, sizeof(uint64_t));
+ }
};
class MemoryBuffer : public Memory {
@@ -60,7 +66,7 @@
MemoryBuffer() = default;
virtual ~MemoryBuffer() = default;
- bool Read(uint64_t addr, void* dst, size_t size) override;
+ size_t Read(uint64_t addr, void* dst, size_t size) override;
uint8_t* GetPtr(size_t offset);
@@ -79,7 +85,9 @@
bool Init(const std::string& file, uint64_t offset, uint64_t size = UINT64_MAX);
- bool Read(uint64_t addr, void* dst, size_t size) override;
+ size_t Read(uint64_t addr, void* dst, size_t size) override;
+
+ size_t Size() { return size_; }
void Clear();
@@ -89,31 +97,15 @@
uint8_t* data_ = nullptr;
};
-class MemoryOffline : public MemoryFileAtOffset {
- public:
- MemoryOffline() = default;
- virtual ~MemoryOffline() = default;
-
- bool Init(const std::string& file, uint64_t offset);
-
- bool Read(uint64_t addr, void* dst, size_t size) override;
-
- private:
- uint64_t start_;
-};
-
class MemoryRemote : public Memory {
public:
MemoryRemote(pid_t pid) : pid_(pid) {}
virtual ~MemoryRemote() = default;
- bool Read(uint64_t addr, void* dst, size_t size) override;
+ size_t Read(uint64_t addr, void* dst, size_t size) override;
pid_t pid() { return pid_; }
- protected:
- virtual bool PtraceRead(uint64_t addr, long* value);
-
private:
pid_t pid_;
};
@@ -123,20 +115,38 @@
MemoryLocal() = default;
virtual ~MemoryLocal() = default;
- bool Read(uint64_t addr, void* dst, size_t size) override;
+ size_t Read(uint64_t addr, void* dst, size_t size) override;
};
+// MemoryRange maps one address range onto another.
+// The range [src_begin, src_begin + length) in the underlying Memory is mapped onto offset,
+// such that range.read(offset) is equivalent to underlying.read(src_begin).
class MemoryRange : public Memory {
public:
- MemoryRange(const std::shared_ptr<Memory>& memory, uint64_t begin, uint64_t end);
+ MemoryRange(const std::shared_ptr<Memory>& memory, uint64_t begin, uint64_t length,
+ uint64_t offset);
virtual ~MemoryRange() = default;
- bool Read(uint64_t addr, void* dst, size_t size) override;
+ size_t Read(uint64_t addr, void* dst, size_t size) override;
private:
std::shared_ptr<Memory> memory_;
uint64_t begin_;
uint64_t length_;
+ uint64_t offset_;
+};
+
+class MemoryOffline : public Memory {
+ public:
+ MemoryOffline() = default;
+ virtual ~MemoryOffline() = default;
+
+ bool Init(const std::string& file, uint64_t offset);
+
+ size_t Read(uint64_t addr, void* dst, size_t size) override;
+
+ private:
+ std::unique_ptr<MemoryRange> memory_;
};
} // namespace unwindstack
diff --git a/libunwindstack/tests/MapInfoCreateMemoryTest.cpp b/libunwindstack/tests/MapInfoCreateMemoryTest.cpp
index bdcb652..866b5b4 100644
--- a/libunwindstack/tests/MapInfoCreateMemoryTest.cpp
+++ b/libunwindstack/tests/MapInfoCreateMemoryTest.cpp
@@ -120,14 +120,14 @@
// Read the entire file.
std::vector<uint8_t> buffer(1024);
- ASSERT_TRUE(memory->Read(0, buffer.data(), 1024));
+ ASSERT_TRUE(memory->ReadFully(0, buffer.data(), 1024));
ASSERT_TRUE(memcmp(buffer.data(), ELFMAG, SELFMAG) == 0);
ASSERT_EQ(ELFCLASS32, buffer[EI_CLASS]);
for (size_t i = EI_CLASS + 1; i < buffer.size(); i++) {
ASSERT_EQ(0, buffer[i]) << "Failed at byte " << i;
}
- ASSERT_FALSE(memory->Read(1024, buffer.data(), 1));
+ ASSERT_FALSE(memory->ReadFully(1024, buffer.data(), 1));
}
// Verify that if the offset is non-zero and there is an elf at that
@@ -141,14 +141,14 @@
// Read the valid part of the file.
std::vector<uint8_t> buffer(0x100);
- ASSERT_TRUE(memory->Read(0, buffer.data(), 0x100));
+ ASSERT_TRUE(memory->ReadFully(0, buffer.data(), 0x100));
ASSERT_TRUE(memcmp(buffer.data(), ELFMAG, SELFMAG) == 0);
ASSERT_EQ(ELFCLASS64, buffer[EI_CLASS]);
for (size_t i = EI_CLASS + 1; i < buffer.size(); i++) {
ASSERT_EQ(0, buffer[i]) << "Failed at byte " << i;
}
- ASSERT_FALSE(memory->Read(0x100, buffer.data(), 1));
+ ASSERT_FALSE(memory->ReadFully(0x100, buffer.data(), 1));
}
// Verify that if the offset is non-zero and there is an elf at that
@@ -164,11 +164,11 @@
// Verify the memory is a valid elf.
uint8_t e_ident[SELFMAG + 1];
- ASSERT_TRUE(memory->Read(0, e_ident, SELFMAG));
+ ASSERT_TRUE(memory->ReadFully(0, e_ident, SELFMAG));
ASSERT_EQ(0, memcmp(e_ident, ELFMAG, SELFMAG));
// Read past the end of what would normally be the size of the map.
- ASSERT_TRUE(memory->Read(0x1000, e_ident, 1));
+ ASSERT_TRUE(memory->ReadFully(0x1000, e_ident, 1));
}
TEST_F(MapInfoCreateMemoryTest, file_backed_non_zero_offset_partial_file_whole_elf64) {
@@ -180,11 +180,11 @@
// Verify the memory is a valid elf.
uint8_t e_ident[SELFMAG + 1];
- ASSERT_TRUE(memory->Read(0, e_ident, SELFMAG));
+ ASSERT_TRUE(memory->ReadFully(0, e_ident, SELFMAG));
ASSERT_EQ(0, memcmp(e_ident, ELFMAG, SELFMAG));
// Read past the end of what would normally be the size of the map.
- ASSERT_TRUE(memory->Read(0x1000, e_ident, 1));
+ ASSERT_TRUE(memory->ReadFully(0x1000, e_ident, 1));
}
// Verify that device file names will never result in Memory object creation.
@@ -221,13 +221,13 @@
ASSERT_TRUE(memory.get() != nullptr);
memset(buffer.data(), 0, buffer.size());
- ASSERT_TRUE(memory->Read(0, buffer.data(), buffer.size()));
+ ASSERT_TRUE(memory->ReadFully(0, buffer.data(), buffer.size()));
for (size_t i = 0; i < buffer.size(); i++) {
ASSERT_EQ(i % 256, buffer[i]) << "Failed at byte " << i;
}
// Try to read outside of the map size.
- ASSERT_FALSE(memory->Read(buffer.size(), buffer.data(), 1));
+ ASSERT_FALSE(memory->ReadFully(buffer.size(), buffer.data(), 1));
}
} // namespace unwindstack
diff --git a/libunwindstack/tests/MapInfoGetElfTest.cpp b/libunwindstack/tests/MapInfoGetElfTest.cpp
index 9973794..948597b 100644
--- a/libunwindstack/tests/MapInfoGetElfTest.cpp
+++ b/libunwindstack/tests/MapInfoGetElfTest.cpp
@@ -216,13 +216,13 @@
// Read the entire file.
memset(buffer.data(), 0, buffer.size());
- ASSERT_TRUE(elf->memory()->Read(0, buffer.data(), buffer.size()));
+ ASSERT_TRUE(elf->memory()->ReadFully(0, buffer.data(), buffer.size()));
ASSERT_EQ(0, memcmp(buffer.data(), &ehdr, sizeof(ehdr)));
for (size_t i = sizeof(ehdr); i < buffer.size(); i++) {
ASSERT_EQ(0, buffer[i]) << "Failed at byte " << i;
}
- ASSERT_FALSE(elf->memory()->Read(buffer.size(), buffer.data(), 1));
+ ASSERT_FALSE(elf->memory()->ReadFully(buffer.size(), buffer.data(), 1));
}
// Verify that if the offset is non-zero and there is an elf at that
@@ -244,13 +244,13 @@
ASSERT_EQ(0U, info.elf_offset);
// Read the valid part of the file.
- ASSERT_TRUE(elf->memory()->Read(0, buffer.data(), 0x1000));
+ ASSERT_TRUE(elf->memory()->ReadFully(0, buffer.data(), 0x1000));
ASSERT_EQ(0, memcmp(buffer.data(), &ehdr, sizeof(ehdr)));
for (size_t i = sizeof(ehdr); i < 0x1000; i++) {
ASSERT_EQ(0, buffer[i]) << "Failed at byte " << i;
}
- ASSERT_FALSE(elf->memory()->Read(0x1000, buffer.data(), 1));
+ ASSERT_FALSE(elf->memory()->ReadFully(0x1000, buffer.data(), 1));
}
// Verify that if the offset is non-zero and there is an elf at that
@@ -278,11 +278,11 @@
// Verify the memory is a valid elf.
memset(buffer.data(), 0, buffer.size());
- ASSERT_TRUE(elf->memory()->Read(0, buffer.data(), 0x1000));
+ ASSERT_TRUE(elf->memory()->ReadFully(0, buffer.data(), 0x1000));
ASSERT_EQ(0, memcmp(buffer.data(), &ehdr, sizeof(ehdr)));
// Read past the end of what would normally be the size of the map.
- ASSERT_TRUE(elf->memory()->Read(0x1000, buffer.data(), 1));
+ ASSERT_TRUE(elf->memory()->ReadFully(0x1000, buffer.data(), 1));
}
TEST_F(MapInfoGetElfTest, file_backed_non_zero_offset_partial_file_whole_elf64) {
@@ -306,11 +306,11 @@
// Verify the memory is a valid elf.
memset(buffer.data(), 0, buffer.size());
- ASSERT_TRUE(elf->memory()->Read(0, buffer.data(), 0x1000));
+ ASSERT_TRUE(elf->memory()->ReadFully(0, buffer.data(), 0x1000));
ASSERT_EQ(0, memcmp(buffer.data(), &ehdr, sizeof(ehdr)));
// Read past the end of what would normally be the size of the map.
- ASSERT_TRUE(elf->memory()->Read(0x1000, buffer.data(), 1));
+ ASSERT_TRUE(elf->memory()->ReadFully(0x1000, buffer.data(), 1));
}
TEST_F(MapInfoGetElfTest, process_memory_not_read_only) {
diff --git a/libunwindstack/tests/MemoryBufferTest.cpp b/libunwindstack/tests/MemoryBufferTest.cpp
index 50a8a1b..28e0e76 100644
--- a/libunwindstack/tests/MemoryBufferTest.cpp
+++ b/libunwindstack/tests/MemoryBufferTest.cpp
@@ -36,7 +36,7 @@
TEST_F(MemoryBufferTest, empty) {
ASSERT_EQ(0U, memory_->Size());
std::vector<uint8_t> buffer(1024);
- ASSERT_FALSE(memory_->Read(0, buffer.data(), 1));
+ ASSERT_FALSE(memory_->ReadFully(0, buffer.data(), 1));
ASSERT_EQ(nullptr, memory_->GetPtr(0));
ASSERT_EQ(nullptr, memory_->GetPtr(1));
}
@@ -55,7 +55,7 @@
}
std::vector<uint8_t> buffer(memory_->Size());
- ASSERT_TRUE(memory_->Read(0, buffer.data(), buffer.size()));
+ ASSERT_TRUE(memory_->ReadFully(0, buffer.data(), buffer.size()));
for (size_t i = 0; i < buffer.size(); i++) {
ASSERT_EQ(i, buffer[i]) << "Failed at byte " << i;
}
@@ -64,18 +64,38 @@
TEST_F(MemoryBufferTest, read_failures) {
memory_->Resize(100);
std::vector<uint8_t> buffer(200);
- ASSERT_FALSE(memory_->Read(0, buffer.data(), 101));
- ASSERT_FALSE(memory_->Read(100, buffer.data(), 1));
- ASSERT_FALSE(memory_->Read(101, buffer.data(), 2));
- ASSERT_FALSE(memory_->Read(99, buffer.data(), 2));
- ASSERT_TRUE(memory_->Read(99, buffer.data(), 1));
+ ASSERT_FALSE(memory_->ReadFully(0, buffer.data(), 101));
+ ASSERT_FALSE(memory_->ReadFully(100, buffer.data(), 1));
+ ASSERT_FALSE(memory_->ReadFully(101, buffer.data(), 2));
+ ASSERT_FALSE(memory_->ReadFully(99, buffer.data(), 2));
+ ASSERT_TRUE(memory_->ReadFully(99, buffer.data(), 1));
}
TEST_F(MemoryBufferTest, read_failure_overflow) {
memory_->Resize(100);
std::vector<uint8_t> buffer(200);
- ASSERT_FALSE(memory_->Read(UINT64_MAX - 100, buffer.data(), 200));
+ ASSERT_FALSE(memory_->ReadFully(UINT64_MAX - 100, buffer.data(), 200));
+}
+
+TEST_F(MemoryBufferTest, Read) {
+ memory_->Resize(256);
+ ASSERT_EQ(256U, memory_->Size());
+ ASSERT_TRUE(memory_->GetPtr(0) != nullptr);
+ ASSERT_TRUE(memory_->GetPtr(1) != nullptr);
+ ASSERT_TRUE(memory_->GetPtr(255) != nullptr);
+ ASSERT_TRUE(memory_->GetPtr(256) == nullptr);
+
+ uint8_t* data = memory_->GetPtr(0);
+ for (size_t i = 0; i < memory_->Size(); i++) {
+ data[i] = i;
+ }
+
+ std::vector<uint8_t> buffer(memory_->Size());
+ ASSERT_EQ(128U, memory_->Read(128, buffer.data(), buffer.size()));
+ for (size_t i = 0; i < 128; i++) {
+ ASSERT_EQ(128 + i, buffer[i]) << "Failed at byte " << i;
+ }
}
} // namespace unwindstack
diff --git a/libunwindstack/tests/MemoryFake.cpp b/libunwindstack/tests/MemoryFake.cpp
index 2026acc..60936cd 100644
--- a/libunwindstack/tests/MemoryFake.cpp
+++ b/libunwindstack/tests/MemoryFake.cpp
@@ -35,16 +35,16 @@
}
}
-bool MemoryFake::Read(uint64_t addr, void* memory, size_t size) {
+size_t MemoryFake::Read(uint64_t addr, void* memory, size_t size) {
uint8_t* dst = reinterpret_cast<uint8_t*>(memory);
for (size_t i = 0; i < size; i++, addr++) {
auto value = data_.find(addr);
if (value == data_.end()) {
- return false;
+ return i;
}
dst[i] = value->second;
}
- return true;
+ return size;
}
} // namespace unwindstack
diff --git a/libunwindstack/tests/MemoryFake.h b/libunwindstack/tests/MemoryFake.h
index d374261..764a6c3 100644
--- a/libunwindstack/tests/MemoryFake.h
+++ b/libunwindstack/tests/MemoryFake.h
@@ -32,7 +32,7 @@
MemoryFake() = default;
virtual ~MemoryFake() = default;
- bool Read(uint64_t addr, void* buffer, size_t size) override;
+ size_t Read(uint64_t addr, void* buffer, size_t size) override;
void SetMemory(uint64_t addr, const void* memory, size_t length);
@@ -71,21 +71,9 @@
MemoryFakeAlwaysReadZero() = default;
virtual ~MemoryFakeAlwaysReadZero() = default;
- bool Read(uint64_t, void* buffer, size_t size) override {
+ size_t Read(uint64_t, void* buffer, size_t size) override {
memset(buffer, 0, size);
- return true;
- }
-};
-
-class MemoryFakeRemote : public MemoryRemote {
- public:
- MemoryFakeRemote() : MemoryRemote(0) {}
- virtual ~MemoryFakeRemote() = default;
-
- protected:
- bool PtraceRead(uint64_t, long* value) override {
- *value = 0;
- return true;
+ return size;
}
};
diff --git a/libunwindstack/tests/MemoryFileTest.cpp b/libunwindstack/tests/MemoryFileTest.cpp
index a204bae..d7d1ace 100644
--- a/libunwindstack/tests/MemoryFileTest.cpp
+++ b/libunwindstack/tests/MemoryFileTest.cpp
@@ -49,7 +49,7 @@
ASSERT_TRUE(memory_.Init(tf_->path, 0));
std::vector<char> buffer(11);
- ASSERT_TRUE(memory_.Read(0, buffer.data(), 10));
+ ASSERT_TRUE(memory_.ReadFully(0, buffer.data(), 10));
buffer[10] = '\0';
ASSERT_STREQ("0123456789", buffer.data());
}
@@ -59,7 +59,7 @@
ASSERT_TRUE(memory_.Init(tf_->path, 10));
std::vector<char> buffer(11);
- ASSERT_TRUE(memory_.Read(0, buffer.data(), 10));
+ ASSERT_TRUE(memory_.ReadFully(0, buffer.data(), 10));
buffer[10] = '\0';
ASSERT_STREQ("abcdefghij", buffer.data());
}
@@ -75,7 +75,7 @@
ASSERT_TRUE(memory_.Init(tf_->path, pagesize + 15));
std::vector<char> buffer(9);
- ASSERT_TRUE(memory_.Read(0, buffer.data(), 8));
+ ASSERT_TRUE(memory_.ReadFully(0, buffer.data(), 8));
buffer[8] = '\0';
ASSERT_STREQ("abcdefgh", buffer.data());
}
@@ -91,7 +91,7 @@
ASSERT_TRUE(memory_.Init(tf_->path, 2 * pagesize));
std::vector<char> buffer(11);
- ASSERT_TRUE(memory_.Read(0, buffer.data(), 10));
+ ASSERT_TRUE(memory_.ReadFully(0, buffer.data(), 10));
buffer[10] = '\0';
std::string expected_str;
for (size_t i = 0; i < 5; i++) {
@@ -112,7 +112,7 @@
ASSERT_TRUE(memory_.Init(tf_->path, 2 * pagesize + 10));
std::vector<char> buffer(11);
- ASSERT_TRUE(memory_.Read(0, buffer.data(), 10));
+ ASSERT_TRUE(memory_.ReadFully(0, buffer.data(), 10));
buffer[10] = '\0';
std::string expected_str;
for (size_t i = 0; i < 5; i++) {
@@ -149,19 +149,19 @@
std::vector<char> buffer(100);
// Read before init.
- ASSERT_FALSE(memory_.Read(0, buffer.data(), 10));
+ ASSERT_FALSE(memory_.ReadFully(0, buffer.data(), 10));
ASSERT_TRUE(memory_.Init(tf_->path, 0));
- ASSERT_FALSE(memory_.Read(10000, buffer.data(), 10));
- ASSERT_FALSE(memory_.Read(5000, buffer.data(), 10));
- ASSERT_FALSE(memory_.Read(4990, buffer.data(), 11));
- ASSERT_TRUE(memory_.Read(4990, buffer.data(), 10));
- ASSERT_FALSE(memory_.Read(4999, buffer.data(), 2));
- ASSERT_TRUE(memory_.Read(4999, buffer.data(), 1));
+ ASSERT_FALSE(memory_.ReadFully(10000, buffer.data(), 10));
+ ASSERT_FALSE(memory_.ReadFully(5000, buffer.data(), 10));
+ ASSERT_FALSE(memory_.ReadFully(4990, buffer.data(), 11));
+ ASSERT_TRUE(memory_.ReadFully(4990, buffer.data(), 10));
+ ASSERT_FALSE(memory_.ReadFully(4999, buffer.data(), 2));
+ ASSERT_TRUE(memory_.ReadFully(4999, buffer.data(), 1));
// Check that overflow fails properly.
- ASSERT_FALSE(memory_.Read(UINT64_MAX - 100, buffer.data(), 200));
+ ASSERT_FALSE(memory_.ReadFully(UINT64_MAX - 100, buffer.data(), 200));
}
TEST_F(MemoryFileTest, read_past_file_within_mapping) {
@@ -178,7 +178,8 @@
for (size_t i = 0; i < 100; i++) {
uint8_t value;
- ASSERT_FALSE(memory_.Read(buffer.size() + i, &value, 1)) << "Should have failed at value " << i;
+ ASSERT_FALSE(memory_.ReadFully(buffer.size() + i, &value, 1))
+ << "Should have failed at value " << i;
}
}
@@ -195,8 +196,8 @@
std::vector<uint8_t> read_buffer(pagesize * 2);
// Make sure that reading after mapped data is a failure.
- ASSERT_FALSE(memory_.Read(pagesize * 2, read_buffer.data(), 1));
- ASSERT_TRUE(memory_.Read(0, read_buffer.data(), pagesize * 2));
+ ASSERT_FALSE(memory_.ReadFully(pagesize * 2, read_buffer.data(), 1));
+ ASSERT_TRUE(memory_.ReadFully(0, read_buffer.data(), pagesize * 2));
for (size_t i = 0; i < pagesize; i++) {
ASSERT_EQ(2, read_buffer[i]) << "Failed at byte " << i;
}
@@ -219,8 +220,8 @@
std::vector<uint8_t> read_buffer(pagesize * 2);
// Make sure that reading after mapped data is a failure.
- ASSERT_FALSE(memory_.Read(pagesize * 2, read_buffer.data(), 1));
- ASSERT_TRUE(memory_.Read(0, read_buffer.data(), pagesize * 2));
+ ASSERT_FALSE(memory_.ReadFully(pagesize * 2, read_buffer.data(), 1));
+ ASSERT_TRUE(memory_.ReadFully(0, read_buffer.data(), pagesize * 2));
for (size_t i = 0; i < pagesize - 0x100; i++) {
ASSERT_EQ(2, read_buffer[i]) << "Failed at byte " << i;
}
@@ -245,8 +246,8 @@
ASSERT_TRUE(memory_.Init(tf_->path, pagesize + 0x100, UINT64_MAX));
std::vector<uint8_t> read_buffer(pagesize * 10);
- ASSERT_FALSE(memory_.Read(pagesize * 9 - 0x100 + 1, read_buffer.data(), 1));
- ASSERT_TRUE(memory_.Read(0, read_buffer.data(), pagesize * 9 - 0x100));
+ ASSERT_FALSE(memory_.ReadFully(pagesize * 9 - 0x100 + 1, read_buffer.data(), 1));
+ ASSERT_TRUE(memory_.ReadFully(0, read_buffer.data(), pagesize * 9 - 0x100));
}
TEST_F(MemoryFileTest, init_reinit) {
@@ -259,14 +260,14 @@
ASSERT_TRUE(memory_.Init(tf_->path, 0));
std::vector<uint8_t> read_buffer(buffer.size());
- ASSERT_TRUE(memory_.Read(0, read_buffer.data(), pagesize));
+ ASSERT_TRUE(memory_.ReadFully(0, read_buffer.data(), pagesize));
for (size_t i = 0; i < pagesize; i++) {
ASSERT_EQ(1, read_buffer[i]) << "Failed at byte " << i;
}
// Now reinit.
ASSERT_TRUE(memory_.Init(tf_->path, pagesize));
- ASSERT_TRUE(memory_.Read(0, read_buffer.data(), pagesize));
+ ASSERT_TRUE(memory_.ReadFully(0, read_buffer.data(), pagesize));
for (size_t i = 0; i < pagesize; i++) {
ASSERT_EQ(2, read_buffer[i]) << "Failed at byte " << i;
}
diff --git a/libunwindstack/tests/MemoryLocalTest.cpp b/libunwindstack/tests/MemoryLocalTest.cpp
index 73eebdd..5a389d0 100644
--- a/libunwindstack/tests/MemoryLocalTest.cpp
+++ b/libunwindstack/tests/MemoryLocalTest.cpp
@@ -16,6 +16,7 @@
#include <stdint.h>
#include <string.h>
+#include <sys/mman.h>
#include <vector>
@@ -32,14 +33,14 @@
MemoryLocal local;
std::vector<uint8_t> dst(1024);
- ASSERT_TRUE(local.Read(reinterpret_cast<uint64_t>(src.data()), dst.data(), 1024));
+ ASSERT_TRUE(local.ReadFully(reinterpret_cast<uint64_t>(src.data()), dst.data(), 1024));
ASSERT_EQ(0, memcmp(src.data(), dst.data(), 1024));
for (size_t i = 0; i < 1024; i++) {
ASSERT_EQ(0x4cU, dst[i]);
}
memset(src.data(), 0x23, 512);
- ASSERT_TRUE(local.Read(reinterpret_cast<uint64_t>(src.data()), dst.data(), 1024));
+ ASSERT_TRUE(local.ReadFully(reinterpret_cast<uint64_t>(src.data()), dst.data(), 1024));
ASSERT_EQ(0, memcmp(src.data(), dst.data(), 1024));
for (size_t i = 0; i < 512; i++) {
ASSERT_EQ(0x23U, dst[i]);
@@ -53,8 +54,8 @@
MemoryLocal local;
std::vector<uint8_t> dst(100);
- ASSERT_FALSE(local.Read(0, dst.data(), 1));
- ASSERT_FALSE(local.Read(0, dst.data(), 100));
+ ASSERT_FALSE(local.ReadFully(0, dst.data(), 1));
+ ASSERT_FALSE(local.ReadFully(0, dst.data(), 100));
}
TEST(MemoryLocalTest, read_overflow) {
@@ -64,7 +65,47 @@
// version will always go through the overflow check.
std::vector<uint8_t> dst(100);
uint64_t value;
- ASSERT_FALSE(local.Read(reinterpret_cast<uint64_t>(&value), dst.data(), SIZE_MAX));
+ ASSERT_FALSE(local.ReadFully(reinterpret_cast<uint64_t>(&value), dst.data(), SIZE_MAX));
+}
+
+TEST(MemoryLocalTest, Read) {
+ char* mapping = static_cast<char*>(
+ mmap(nullptr, 2 * getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0));
+
+ ASSERT_NE(MAP_FAILED, mapping);
+
+ mprotect(mapping + getpagesize(), getpagesize(), PROT_NONE);
+ memset(mapping + getpagesize() - 1024, 0x4c, 1024);
+
+ MemoryLocal local;
+
+ std::vector<uint8_t> dst(4096);
+ ASSERT_EQ(1024U, local.Read(reinterpret_cast<uint64_t>(mapping + getpagesize() - 1024),
+ dst.data(), 4096));
+ for (size_t i = 0; i < 1024; i++) {
+ ASSERT_EQ(0x4cU, dst[i]) << "Failed at byte " << i;
+ }
+
+ ASSERT_EQ(0, munmap(mapping, 2 * getpagesize()));
+}
+
+TEST(MemoryLocalTest, read_hole) {
+ void* mapping =
+ mmap(nullptr, 3 * 4096, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ ASSERT_NE(MAP_FAILED, mapping);
+ memset(mapping, 0xFF, 3 * 4096);
+ mprotect(static_cast<char*>(mapping) + 4096, 4096, PROT_NONE);
+
+ MemoryLocal local;
+ std::vector<uint8_t> dst(4096 * 3, 0xCC);
+ ASSERT_EQ(4096U, local.Read(reinterpret_cast<uintptr_t>(mapping), dst.data(), 4096 * 3));
+ for (size_t i = 0; i < 4096; ++i) {
+ ASSERT_EQ(0xFF, dst[i]);
+ }
+ for (size_t i = 4096; i < 4096 * 3; ++i) {
+ ASSERT_EQ(0xCC, dst[i]);
+ }
+ ASSERT_EQ(0, munmap(mapping, 3 * 4096));
}
} // namespace unwindstack
diff --git a/libunwindstack/tests/MemoryRangeTest.cpp b/libunwindstack/tests/MemoryRangeTest.cpp
index 680fae9..cb1a0c9 100644
--- a/libunwindstack/tests/MemoryRangeTest.cpp
+++ b/libunwindstack/tests/MemoryRangeTest.cpp
@@ -35,10 +35,10 @@
std::shared_ptr<Memory> process_memory(memory_fake);
memory_fake->SetMemory(9001, src);
- MemoryRange range(process_memory, 9001, 9001 + src.size());
+ MemoryRange range(process_memory, 9001, src.size(), 0);
std::vector<uint8_t> dst(1024);
- ASSERT_TRUE(range.Read(0, dst.data(), src.size()));
+ ASSERT_TRUE(range.ReadFully(0, dst.data(), src.size()));
for (size_t i = 0; i < 1024; i++) {
ASSERT_EQ(0x4cU, dst[i]) << "Failed at byte " << i;
}
@@ -51,29 +51,44 @@
std::shared_ptr<Memory> process_memory(memory_fake);
memory_fake->SetMemory(1000, src);
- MemoryRange range(process_memory, 1000, 2024);
+ MemoryRange range(process_memory, 1000, 1024, 0);
std::vector<uint8_t> dst(1024);
- ASSERT_TRUE(range.Read(1020, dst.data(), 4));
+ ASSERT_TRUE(range.ReadFully(1020, dst.data(), 4));
for (size_t i = 0; i < 4; i++) {
ASSERT_EQ(0x4cU, dst[i]) << "Failed at byte " << i;
}
// Verify that reads outside of the range will fail.
- ASSERT_FALSE(range.Read(1020, dst.data(), 5));
- ASSERT_FALSE(range.Read(1024, dst.data(), 1));
- ASSERT_FALSE(range.Read(1024, dst.data(), 1024));
+ ASSERT_FALSE(range.ReadFully(1020, dst.data(), 5));
+ ASSERT_FALSE(range.ReadFully(1024, dst.data(), 1));
+ ASSERT_FALSE(range.ReadFully(1024, dst.data(), 1024));
// Verify that reading up to the end works.
- ASSERT_TRUE(range.Read(1020, dst.data(), 4));
+ ASSERT_TRUE(range.ReadFully(1020, dst.data(), 4));
}
TEST(MemoryRangeTest, read_overflow) {
std::vector<uint8_t> buffer(100);
std::shared_ptr<Memory> process_memory(new MemoryFakeAlwaysReadZero);
- std::unique_ptr<MemoryRange> overflow(new MemoryRange(process_memory, 100, 200));
- ASSERT_FALSE(overflow->Read(UINT64_MAX - 10, buffer.data(), 100));
+ std::unique_ptr<MemoryRange> overflow(new MemoryRange(process_memory, 100, 200, 0));
+ ASSERT_FALSE(overflow->ReadFully(UINT64_MAX - 10, buffer.data(), 100));
+}
+
+TEST(MemoryRangeTest, Read) {
+ std::vector<uint8_t> src(4096);
+ memset(src.data(), 0x4c, 4096);
+ MemoryFake* memory_fake = new MemoryFake;
+ std::shared_ptr<Memory> process_memory(memory_fake);
+ memory_fake->SetMemory(1000, src);
+
+ MemoryRange range(process_memory, 1000, 1024, 0);
+ std::vector<uint8_t> dst(1024);
+ ASSERT_EQ(4U, range.Read(1020, dst.data(), 1024));
+ for (size_t i = 0; i < 4; i++) {
+ ASSERT_EQ(0x4cU, dst[i]) << "Failed at byte " << i;
+ }
}
} // namespace unwindstack
diff --git a/libunwindstack/tests/MemoryRemoteTest.cpp b/libunwindstack/tests/MemoryRemoteTest.cpp
index a66d0c5..8aa4c3f 100644
--- a/libunwindstack/tests/MemoryRemoteTest.cpp
+++ b/libunwindstack/tests/MemoryRemoteTest.cpp
@@ -71,7 +71,7 @@
MemoryRemote remote(pid);
std::vector<uint8_t> dst(1024);
- ASSERT_TRUE(remote.Read(reinterpret_cast<uint64_t>(src.data()), dst.data(), 1024));
+ ASSERT_TRUE(remote.ReadFully(reinterpret_cast<uint64_t>(src.data()), dst.data(), 1024));
for (size_t i = 0; i < 1024; i++) {
ASSERT_EQ(0x4cU, dst[i]) << "Failed at byte " << i;
}
@@ -79,6 +79,39 @@
ASSERT_TRUE(Detach(pid));
}
+TEST_F(MemoryRemoteTest, Read) {
+ char* mapping = static_cast<char*>(
+ mmap(nullptr, 2 * getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0));
+
+ ASSERT_NE(MAP_FAILED, mapping);
+
+ mprotect(mapping + getpagesize(), getpagesize(), PROT_NONE);
+ memset(mapping + getpagesize() - 1024, 0x4c, 1024);
+
+ pid_t pid;
+ if ((pid = fork()) == 0) {
+ while (true)
+ ;
+ exit(1);
+ }
+ ASSERT_LT(0, pid);
+ TestScopedPidReaper reap(pid);
+
+ ASSERT_TRUE(Attach(pid));
+
+ MemoryRemote remote(pid);
+
+ std::vector<uint8_t> dst(4096);
+ ASSERT_EQ(1024U, remote.Read(reinterpret_cast<uint64_t>(mapping + getpagesize() - 1024),
+ dst.data(), 4096));
+ for (size_t i = 0; i < 1024; i++) {
+ ASSERT_EQ(0x4cU, dst[i]) << "Failed at byte " << i;
+ }
+
+ ASSERT_TRUE(Detach(pid));
+ ASSERT_EQ(0, munmap(mapping, 2 * getpagesize()));
+}
+
TEST_F(MemoryRemoteTest, read_fail) {
int pagesize = getpagesize();
void* src = mmap(nullptr, pagesize * 2, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE,-1, 0);
@@ -101,17 +134,17 @@
MemoryRemote remote(pid);
std::vector<uint8_t> dst(pagesize);
- ASSERT_TRUE(remote.Read(reinterpret_cast<uint64_t>(src), dst.data(), pagesize));
+ ASSERT_TRUE(remote.ReadFully(reinterpret_cast<uint64_t>(src), dst.data(), pagesize));
for (size_t i = 0; i < 1024; i++) {
ASSERT_EQ(0x4cU, dst[i]) << "Failed at byte " << i;
}
- ASSERT_FALSE(remote.Read(reinterpret_cast<uint64_t>(src) + pagesize, dst.data(), 1));
- ASSERT_TRUE(remote.Read(reinterpret_cast<uint64_t>(src) + pagesize - 1, dst.data(), 1));
- ASSERT_FALSE(remote.Read(reinterpret_cast<uint64_t>(src) + pagesize - 4, dst.data(), 8));
+ ASSERT_FALSE(remote.ReadFully(reinterpret_cast<uint64_t>(src) + pagesize, dst.data(), 1));
+ ASSERT_TRUE(remote.ReadFully(reinterpret_cast<uint64_t>(src) + pagesize - 1, dst.data(), 1));
+ ASSERT_FALSE(remote.ReadFully(reinterpret_cast<uint64_t>(src) + pagesize - 4, dst.data(), 8));
// Check overflow condition is caught properly.
- ASSERT_FALSE(remote.Read(UINT64_MAX - 100, dst.data(), 200));
+ ASSERT_FALSE(remote.ReadFully(UINT64_MAX - 100, dst.data(), 200));
ASSERT_EQ(0, munmap(src, pagesize));
@@ -119,11 +152,24 @@
}
TEST_F(MemoryRemoteTest, read_overflow) {
- MemoryFakeRemote remote;
+ pid_t pid;
+ if ((pid = fork()) == 0) {
+ while (true)
+ ;
+ exit(1);
+ }
+ ASSERT_LT(0, pid);
+ TestScopedPidReaper reap(pid);
+
+ ASSERT_TRUE(Attach(pid));
+
+ MemoryRemote remote(pid);
// Check overflow condition is caught properly.
std::vector<uint8_t> dst(200);
- ASSERT_FALSE(remote.Read(UINT64_MAX - 100, dst.data(), 200));
+ ASSERT_FALSE(remote.ReadFully(UINT64_MAX - 100, dst.data(), 200));
+
+ ASSERT_TRUE(Detach(pid));
}
TEST_F(MemoryRemoteTest, read_illegal) {
@@ -140,10 +186,38 @@
MemoryRemote remote(pid);
std::vector<uint8_t> dst(100);
- ASSERT_FALSE(remote.Read(0, dst.data(), 1));
- ASSERT_FALSE(remote.Read(0, dst.data(), 100));
+ ASSERT_FALSE(remote.ReadFully(0, dst.data(), 1));
+ ASSERT_FALSE(remote.ReadFully(0, dst.data(), 100));
ASSERT_TRUE(Detach(pid));
}
+TEST_F(MemoryRemoteTest, read_hole) {
+ void* mapping =
+ mmap(nullptr, 3 * 4096, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ ASSERT_NE(MAP_FAILED, mapping);
+ memset(mapping, 0xFF, 3 * 4096);
+ mprotect(static_cast<char*>(mapping) + 4096, 4096, PROT_NONE);
+
+ pid_t pid;
+ if ((pid = fork()) == 0) {
+ while (true);
+ exit(1);
+ }
+ ASSERT_LT(0, pid);
+ TestScopedPidReaper reap(pid);
+
+ ASSERT_TRUE(Attach(pid));
+
+ MemoryRemote remote(pid);
+ std::vector<uint8_t> dst(4096 * 3, 0xCC);
+ ASSERT_EQ(4096U, remote.Read(reinterpret_cast<uintptr_t>(mapping), dst.data(), 4096 * 3));
+ for (size_t i = 0; i < 4096; ++i) {
+ ASSERT_EQ(0xFF, dst[i]);
+ }
+ for (size_t i = 4096; i < 4096 * 3; ++i) {
+ ASSERT_EQ(0xCC, dst[i]);
+ }
+}
+
} // namespace unwindstack
diff --git a/libunwindstack/tests/UnwindTest.cpp b/libunwindstack/tests/UnwindTest.cpp
index 66c8ba6..b372fd0 100644
--- a/libunwindstack/tests/UnwindTest.cpp
+++ b/libunwindstack/tests/UnwindTest.cpp
@@ -174,7 +174,7 @@
MemoryRemote memory(pid);
// Read the remote value to see if we are ready.
bool value;
- if (memory.Read(addr, &value, sizeof(value)) && value) {
+ if (memory.ReadFully(addr, &value, sizeof(value)) && value) {
*completed = true;
}
if (!*completed || !leave_attached) {
diff --git a/libutils/Android.bp b/libutils/Android.bp
index 4bd2a98..6b50f0c 100644
--- a/libutils/Android.bp
+++ b/libutils/Android.bp
@@ -136,9 +136,12 @@
cflags: ["-Wno-unused-parameter"],
},
- // Under MinGW, ctype.h doesn't need multi-byte support
windows: {
- cflags: ["-DMB_CUR_MAX=1"],
+ cflags: [
+ // Under MinGW, ctype.h doesn't need multi-byte support
+ "-DMB_CUR_MAX=1",
+ "-Wno-unused-private-field",
+ ],
enabled: true,
},
diff --git a/libutils/Threads.cpp b/libutils/Threads.cpp
index 6317c32..7d7f0e2 100644
--- a/libutils/Threads.cpp
+++ b/libutils/Threads.cpp
@@ -348,7 +348,7 @@
mState = (void*) hMutex;
}
-Mutex::Mutex(const char* name)
+Mutex::Mutex(const char* /*name*/)
{
// XXX: name not used for now
HANDLE hMutex;
@@ -359,7 +359,7 @@
mState = (void*) hMutex;
}
-Mutex::Mutex(int type, const char* name)
+Mutex::Mutex(int /*type*/, const char* /*name*/)
{
// XXX: type and name not used for now
HANDLE hMutex;
diff --git a/libutils/misc.cpp b/libutils/misc.cpp
index d95fd05..da28dfa 100644
--- a/libutils/misc.cpp
+++ b/libutils/misc.cpp
@@ -44,8 +44,8 @@
static Vector<sysprop_change_callback_info>* gSyspropList = NULL;
#endif
-void add_sysprop_change_callback(sysprop_change_callback cb, int priority) {
#if !defined(_WIN32)
+void add_sysprop_change_callback(sysprop_change_callback cb, int priority) {
pthread_mutex_lock(&gSyspropMutex);
if (gSyspropList == NULL) {
gSyspropList = new Vector<sysprop_change_callback_info>();
@@ -65,8 +65,10 @@
gSyspropList->add(info);
}
pthread_mutex_unlock(&gSyspropMutex);
-#endif
}
+#else
+void add_sysprop_change_callback(sysprop_change_callback, int) {}
+#endif
#if defined(__ANDROID__)
void (*get_report_sysprop_change_func())() {
diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc
index 91e775f..5ccbcc2 100644
--- a/libziparchive/zip_archive.cc
+++ b/libziparchive/zip_archive.cc
@@ -100,6 +100,11 @@
}
static uint32_t ComputeHash(const ZipString& name) {
+#if !defined(_WIN32)
+ return std::hash<std::string_view>{}(
+ std::string_view(reinterpret_cast<const char*>(name.name), name.name_length));
+#else
+ // Remove this code path once the windows compiler knows how to compile the above statement.
uint32_t hash = 0;
uint16_t len = name.name_length;
const uint8_t* str = name.name;
@@ -109,6 +114,7 @@
}
return hash;
+#endif
}
/*
diff --git a/logd/LogStatistics.h b/logd/LogStatistics.h
index 8808aac..ac3cf9a 100644
--- a/logd/LogStatistics.h
+++ b/logd/LogStatistics.h
@@ -25,9 +25,9 @@
#include <sys/types.h>
#include <algorithm> // std::max
-#include <experimental/string_view>
#include <memory>
-#include <string> // std::string
+#include <string>
+#include <string_view>
#include <unordered_map>
#include <android-base/stringprintf.h>
@@ -495,7 +495,7 @@
struct TagNameKey {
std::string* alloc;
- std::experimental::string_view name; // Saves space if const char*
+ std::string_view name; // Saves space if const char*
explicit TagNameKey(const LogBufferElement* element)
: alloc(nullptr), name("", strlen("")) {
@@ -504,31 +504,31 @@
if (tag) {
const char* cp = android::tagToName(tag);
if (cp) {
- name = std::experimental::string_view(cp, strlen(cp));
+ name = std::string_view(cp, strlen(cp));
return;
}
}
alloc = new std::string(
android::base::StringPrintf("[%" PRIu32 "]", tag));
if (!alloc) return;
- name = std::experimental::string_view(alloc->c_str(), alloc->size());
+ name = std::string_view(alloc->c_str(), alloc->size());
return;
}
const char* msg = element->getMsg();
if (!msg) {
- name = std::experimental::string_view("chatty", strlen("chatty"));
+ name = std::string_view("chatty", strlen("chatty"));
return;
}
++msg;
unsigned short len = element->getMsgLen();
len = (len <= 1) ? 0 : strnlen(msg, len - 1);
if (!len) {
- name = std::experimental::string_view("<NULL>", strlen("<NULL>"));
+ name = std::string_view("<NULL>", strlen("<NULL>"));
return;
}
alloc = new std::string(msg, len);
if (!alloc) return;
- name = std::experimental::string_view(alloc->c_str(), alloc->size());
+ name = std::string_view(alloc->c_str(), alloc->size());
}
explicit TagNameKey(TagNameKey&& rval)
@@ -545,7 +545,7 @@
if (alloc) delete alloc;
}
- operator const std::experimental::string_view() const {
+ operator const std::string_view() const {
return name;
}
@@ -576,8 +576,7 @@
: public std::unary_function<const TagNameKey&, size_t> {
size_t operator()(const TagNameKey& __t) const noexcept {
if (!__t.length()) return 0;
- return std::hash<std::experimental::string_view>()(
- std::experimental::string_view(__t));
+ return std::hash<std::string_view>()(std::string_view(__t));
}
};
diff --git a/logd/logd.rc b/logd/logd.rc
index 8804246..bd303b7 100644
--- a/logd/logd.rc
+++ b/logd/logd.rc
@@ -20,4 +20,3 @@
"
chown logd logd /dev/event-log-tags
chmod 0644 /dev/event-log-tags
- restorecon /dev/event-log-tags