Merge "first stage mount: abort when failed to parse fstab in device-tree"
diff --git a/adb/daemon/main.cpp b/adb/daemon/main.cpp
index 1c94298..3c27582 100644
--- a/adb/daemon/main.cpp
+++ b/adb/daemon/main.cpp
@@ -233,8 +233,8 @@
adb_device_banner = optarg;
break;
case 'v':
- printf("Android Debug Bridge Daemon version %d.%d.%d (%s)\n", ADB_VERSION_MAJOR,
- ADB_VERSION_MINOR, ADB_SERVER_VERSION, ADB_VERSION);
+ printf("Android Debug Bridge Daemon version %d.%d.%d\n", ADB_VERSION_MAJOR,
+ ADB_VERSION_MINOR, ADB_SERVER_VERSION);
return 0;
default:
// getopt already prints "adbd: invalid option -- %c" for us.
diff --git a/adb/test_device.py b/adb/test_device.py
index ddceda9..4cf2206 100644
--- a/adb/test_device.py
+++ b/adb/test_device.py
@@ -34,11 +34,8 @@
import time
import unittest
-import mock
-
import adb
-
def requires_root(func):
def wrapper(self, *args):
if self.device.get_prop('ro.debuggable') != '1':
@@ -76,59 +73,6 @@
return wrapper
-class GetDeviceTest(unittest.TestCase):
- def setUp(self):
- self.android_serial = os.getenv('ANDROID_SERIAL')
- if 'ANDROID_SERIAL' in os.environ:
- del os.environ['ANDROID_SERIAL']
-
- def tearDown(self):
- if self.android_serial is not None:
- os.environ['ANDROID_SERIAL'] = self.android_serial
- else:
- if 'ANDROID_SERIAL' in os.environ:
- del os.environ['ANDROID_SERIAL']
-
- @mock.patch('adb.device.get_devices')
- def test_explicit(self, mock_get_devices):
- mock_get_devices.return_value = ['foo', 'bar']
- device = adb.get_device('foo')
- self.assertEqual(device.serial, 'foo')
-
- @mock.patch('adb.device.get_devices')
- def test_from_env(self, mock_get_devices):
- mock_get_devices.return_value = ['foo', 'bar']
- os.environ['ANDROID_SERIAL'] = 'foo'
- device = adb.get_device()
- self.assertEqual(device.serial, 'foo')
-
- @mock.patch('adb.device.get_devices')
- def test_arg_beats_env(self, mock_get_devices):
- mock_get_devices.return_value = ['foo', 'bar']
- os.environ['ANDROID_SERIAL'] = 'bar'
- device = adb.get_device('foo')
- self.assertEqual(device.serial, 'foo')
-
- @mock.patch('adb.device.get_devices')
- def test_no_such_device(self, mock_get_devices):
- mock_get_devices.return_value = ['foo', 'bar']
- self.assertRaises(adb.DeviceNotFoundError, adb.get_device, ['baz'])
-
- os.environ['ANDROID_SERIAL'] = 'baz'
- self.assertRaises(adb.DeviceNotFoundError, adb.get_device)
-
- @mock.patch('adb.device.get_devices')
- def test_unique_device(self, mock_get_devices):
- mock_get_devices.return_value = ['foo']
- device = adb.get_device()
- self.assertEqual(device.serial, 'foo')
-
- @mock.patch('adb.device.get_devices')
- def test_no_unique_device(self, mock_get_devices):
- mock_get_devices.return_value = ['foo', 'bar']
- self.assertRaises(adb.NoUniqueDeviceError, adb.get_device)
-
-
class DeviceTest(unittest.TestCase):
def setUp(self):
self.device = adb.get_device()
diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp
index 45e768d..8d0c98b 100644
--- a/debuggerd/debuggerd_test.cpp
+++ b/debuggerd/debuggerd_test.cpp
@@ -16,6 +16,7 @@
#include <err.h>
#include <fcntl.h>
+#include <stdlib.h>
#include <sys/capability.h>
#include <sys/prctl.h>
#include <sys/ptrace.h>
@@ -298,6 +299,26 @@
ASSERT_MATCH(result, R"(signal 11 \(SIGSEGV\), code 1 \(SEGV_MAPERR\), fault addr 0xdead)");
}
+TEST_F(CrasherTest, LD_PRELOAD) {
+ int intercept_result;
+ unique_fd output_fd;
+ StartProcess([]() {
+ setenv("LD_PRELOAD", "nonexistent.so", 1);
+ *reinterpret_cast<volatile char*>(0xdead) = '1';
+ });
+
+ StartIntercept(&output_fd);
+ FinishCrasher();
+ AssertDeath(SIGSEGV);
+ FinishIntercept(&intercept_result);
+
+ ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
+
+ std::string result;
+ ConsumeFd(std::move(output_fd), &result);
+ ASSERT_MATCH(result, R"(signal 11 \(SIGSEGV\), code 1 \(SEGV_MAPERR\), fault addr 0xdead)");
+}
+
TEST_F(CrasherTest, abort) {
int intercept_result;
unique_fd output_fd;
diff --git a/debuggerd/handler/debuggerd_handler.cpp b/debuggerd/handler/debuggerd_handler.cpp
index d41dc67..d6b6d58 100644
--- a/debuggerd/handler/debuggerd_handler.cpp
+++ b/debuggerd/handler/debuggerd_handler.cpp
@@ -330,8 +330,8 @@
async_safe_format_buffer(debuggerd_dump_type, sizeof(debuggerd_dump_type), "%d",
get_dump_type(thread_info));
- execl(CRASH_DUMP_PATH, CRASH_DUMP_NAME, main_tid, pseudothread_tid, debuggerd_dump_type,
- nullptr);
+ execle(CRASH_DUMP_PATH, CRASH_DUMP_NAME, main_tid, pseudothread_tid, debuggerd_dump_type,
+ nullptr, nullptr);
fatal_errno("exec failed");
} else {
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 40c18e0..6175f59 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -485,7 +485,7 @@
return bdata;
}
-static void* unzip_file(ZipArchiveHandle zip, const char* entry_name, int64_t* sz) {
+static void* unzip_to_memory(ZipArchiveHandle zip, const char* entry_name, int64_t* sz) {
ZipString zip_entry_name(entry_name);
ZipEntry zip_entry;
if (FindEntry(zip, zip_entry_name, &zip_entry) != 0) {
@@ -495,7 +495,7 @@
*sz = zip_entry.uncompressed_length;
- fprintf(stderr, "extracting %s (%" PRId64 " MB)...\n", entry_name, *sz / 1024 / 1024);
+ fprintf(stderr, "extracting %s (%" PRId64 " MB) to RAM...\n", entry_name, *sz / 1024 / 1024);
uint8_t* data = reinterpret_cast<uint8_t*>(malloc(zip_entry.uncompressed_length));
if (data == nullptr) die("failed to allocate %" PRId64 " bytes for '%s'", *sz, entry_name);
@@ -613,17 +613,20 @@
return -1;
}
- fprintf(stderr, "extracting %s (%" PRIu32 " MB)...\n", entry_name,
+ fprintf(stderr, "extracting %s (%" PRIu32 " MB) to disk...", entry_name,
zip_entry.uncompressed_length / 1024 / 1024);
+ double start = now();
int error = ExtractEntryToFile(zip, &zip_entry, fd);
if (error != 0) {
- die("failed to extract '%s': %s", entry_name, ErrorCodeString(error));
+ die("\nfailed to extract '%s': %s", entry_name, ErrorCodeString(error));
}
if (lseek(fd, 0, SEEK_SET) != 0) {
- die("lseek on extracted file '%s' failed: %s", entry_name, strerror(errno));
+ die("\nlseek on extracted file '%s' failed: %s", entry_name, strerror(errno));
}
+ fprintf(stderr, " took %.3fs\n", now() - start);
+
return fd.release();
}
@@ -1091,7 +1094,7 @@
static void do_update_signature(ZipArchiveHandle zip, const char* filename) {
int64_t sz;
- void* data = unzip_file(zip, filename, &sz);
+ void* data = unzip_to_memory(zip, filename, &sz);
if (data == nullptr) return;
fb_queue_download("signature", data, sz);
fb_queue_command("signature", "installing signature");
@@ -1130,7 +1133,7 @@
}
int64_t sz;
- void* data = unzip_file(zip, "android-info.txt", &sz);
+ void* data = unzip_to_memory(zip, "android-info.txt", &sz);
if (data == nullptr) {
die("update package '%s' has no android-info.txt", filename);
}
diff --git a/libcutils/Android.bp b/libcutils/Android.bp
index cfe8d29..a21d1ca 100644
--- a/libcutils/Android.bp
+++ b/libcutils/Android.bp
@@ -19,14 +19,14 @@
// which are also hard or even impossible to port to native Win32
libcutils_nonwindows_sources = [
"android_get_control_file.cpp",
- "fs.c",
+ "fs.cpp",
"multiuser.c",
- "socket_inaddr_any_server_unix.c",
- "socket_local_client_unix.c",
- "socket_local_server_unix.c",
- "socket_network_client_unix.c",
+ "socket_inaddr_any_server_unix.cpp",
+ "socket_local_client_unix.cpp",
+ "socket_local_server_unix.cpp",
+ "socket_network_client_unix.cpp",
"sockets_unix.cpp",
- "str_parms.c",
+ "str_parms.cpp",
]
cc_library_headers {
@@ -56,21 +56,21 @@
},
host_supported: true,
srcs: [
- "config_utils.c",
+ "config_utils.cpp",
"fs_config.cpp",
- "canned_fs_config.c",
- "hashmap.c",
- "iosched_policy.c",
- "load_file.c",
- "native_handle.c",
+ "canned_fs_config.cpp",
+ "hashmap.cpp",
+ "iosched_policy.cpp",
+ "load_file.cpp",
+ "native_handle.cpp",
"open_memstream.c",
- "record_stream.c",
+ "record_stream.cpp",
"sched_policy.cpp",
"sockets.cpp",
- "strdup16to8.c",
- "strdup8to16.c",
+ "strdup16to8.cpp",
+ "strdup8to16.cpp",
"strlcpy.c",
- "threads.c",
+ "threads.cpp",
],
target: {
@@ -83,14 +83,14 @@
},
not_windows: {
srcs: libcutils_nonwindows_sources + [
- "ashmem-host.c",
- "trace-host.c",
+ "ashmem-host.cpp",
+ "trace-host.cpp",
],
},
windows: {
srcs: [
- "socket_inaddr_any_server_windows.c",
- "socket_network_client_windows.c",
+ "socket_inaddr_any_server_windows.cpp",
+ "socket_network_client_windows.cpp",
"sockets_windows.cpp",
],
@@ -105,32 +105,41 @@
android: {
srcs: libcutils_nonwindows_sources + [
- "android_reboot.c",
- "ashmem-dev.c",
+ "android_reboot.cpp",
+ "ashmem-dev.cpp",
"klog.cpp",
- "partition_utils.c",
+ "partition_utils.cpp",
"properties.cpp",
- "qtaguid.c",
- "trace-dev.c",
- "uevent.c",
+ "qtaguid.cpp",
+ "trace-dev.cpp",
+ "uevent.cpp",
],
+ },
+
+ android_arm: {
+ srcs: ["arch-arm/memset32.S"],
+ sanitize: {
+ misc_undefined: ["integer"],
+ },
+ },
+ android_arm64: {
+ srcs: ["arch-arm64/android_memset.S"],
sanitize: {
misc_undefined: ["integer"],
},
},
- android_arm: {
- srcs: ["arch-arm/memset32.S"],
- },
- android_arm64: {
- srcs: ["arch-arm64/android_memset.S"],
- },
-
android_mips: {
srcs: ["arch-mips/android_memset.c"],
+ sanitize: {
+ misc_undefined: ["integer"],
+ },
},
android_mips64: {
srcs: ["arch-mips/android_memset.c"],
+ sanitize: {
+ misc_undefined: ["integer"],
+ },
},
android_x86: {
@@ -138,6 +147,12 @@
"arch-x86/android_memset16.S",
"arch-x86/android_memset32.S",
],
+ // TODO: This is to work around b/29412086.
+ // Remove once __mulodi4 is available and move the "sanitize" block
+ // to the android target.
+ sanitize: {
+ misc_undefined: [],
+ },
},
android_x86_64: {
@@ -145,6 +160,9 @@
"arch-x86_64/android_memset16.S",
"arch-x86_64/android_memset32.S",
],
+ sanitize: {
+ misc_undefined: ["integer"],
+ },
},
},
diff --git a/libcutils/android_get_control_file.cpp b/libcutils/android_get_control_file.cpp
index 780d9f1..d8121f5 100644
--- a/libcutils/android_get_control_file.cpp
+++ b/libcutils/android_get_control_file.cpp
@@ -25,6 +25,9 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
+#include <cutils/android_get_control_file.h>
+
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@@ -36,8 +39,6 @@
#include <sys/types.h>
#include <unistd.h>
-#include <cutils/android_get_control_file.h>
-
#include "android_get_control_env.h"
#ifndef TEMP_FAILURE_RETRY
diff --git a/libcutils/android_reboot.c b/libcutils/android_reboot.cpp
similarity index 96%
rename from libcutils/android_reboot.c
rename to libcutils/android_reboot.cpp
index 996d89d..5e864d4 100644
--- a/libcutils/android_reboot.c
+++ b/libcutils/android_reboot.cpp
@@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#include <cutils/android_reboot.h>
+
#include <stdio.h>
#include <stdlib.h>
-#include <cutils/android_reboot.h>
#include <cutils/properties.h>
#define TAG "android_reboot"
@@ -26,7 +28,7 @@
const char* restart_cmd = NULL;
char* prop_value;
- switch (cmd) {
+ switch (static_cast<unsigned>(cmd)) {
case ANDROID_RB_RESTART: // deprecated
case ANDROID_RB_RESTART2:
restart_cmd = "reboot";
diff --git a/libcutils/ashmem-dev.c b/libcutils/ashmem-dev.cpp
similarity index 94%
rename from libcutils/ashmem-dev.c
rename to libcutils/ashmem-dev.cpp
index 95f2259..15ace0e 100644
--- a/libcutils/ashmem-dev.c
+++ b/libcutils/ashmem-dev.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <cutils/ashmem.h>
+
/*
* Implementation of the user-space ashmem API for devices, which have our
* ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
@@ -31,8 +33,6 @@
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <unistd.h>
-
-#include <cutils/ashmem.h>
#include <log/log.h>
#define ASHMEM_DEVICE "/dev/ashmem"
@@ -192,7 +192,8 @@
int ashmem_pin_region(int fd, size_t offset, size_t len)
{
- struct ashmem_pin pin = { offset, len };
+ // TODO: should LP64 reject too-large offset/len?
+ ashmem_pin pin = { static_cast<uint32_t>(offset), static_cast<uint32_t>(len) };
int ret = __ashmem_is_ashmem(fd, 1);
if (ret < 0) {
@@ -204,7 +205,8 @@
int ashmem_unpin_region(int fd, size_t offset, size_t len)
{
- struct ashmem_pin pin = { offset, len };
+ // TODO: should LP64 reject too-large offset/len?
+ ashmem_pin pin = { static_cast<uint32_t>(offset), static_cast<uint32_t>(len) };
int ret = __ashmem_is_ashmem(fd, 1);
if (ret < 0) {
diff --git a/libcutils/ashmem-host.c b/libcutils/ashmem-host.cpp
similarity index 92%
rename from libcutils/ashmem-host.c
rename to libcutils/ashmem-host.cpp
index 1f9f753..d2c28f3 100644
--- a/libcutils/ashmem-host.c
+++ b/libcutils/ashmem-host.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <cutils/ashmem.h>
+
/*
* Implementation of the user-space ashmem API for the simulator, which lacks
* an ashmem-enabled kernel. See ashmem-dev.c for the real ashmem-based version.
@@ -31,7 +33,6 @@
#include <time.h>
#include <unistd.h>
-#include <cutils/ashmem.h>
#include <utils/Compat.h>
#ifndef __unused
@@ -40,12 +41,12 @@
int ashmem_create_region(const char *ignored __unused, size_t size)
{
- char template[PATH_MAX];
- snprintf(template, sizeof(template), "/tmp/android-ashmem-%d-XXXXXXXXX", getpid());
- int fd = mkstemp(template);
+ char pattern[PATH_MAX];
+ snprintf(pattern, sizeof(pattern), "/tmp/android-ashmem-%d-XXXXXXXXX", getpid());
+ int fd = mkstemp(pattern);
if (fd == -1) return -1;
- unlink(template);
+ unlink(pattern);
if (TEMP_FAILURE_RETRY(ftruncate(fd, size)) == -1) {
close(fd);
diff --git a/libcutils/canned_fs_config.c b/libcutils/canned_fs_config.cpp
similarity index 99%
rename from libcutils/canned_fs_config.c
rename to libcutils/canned_fs_config.cpp
index 819a846..6b5763b 100644
--- a/libcutils/canned_fs_config.c
+++ b/libcutils/canned_fs_config.cpp
@@ -14,6 +14,10 @@
* limitations under the License.
*/
+#include <private/android_filesystem_config.h>
+#include <private/canned_fs_config.h>
+#include <private/fs_config.h>
+
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
@@ -22,10 +26,6 @@
#include <stdlib.h>
#include <string.h>
-#include <private/android_filesystem_config.h>
-#include <private/fs_config.h>
-#include <private/canned_fs_config.h>
-
typedef struct {
const char* path;
unsigned uid;
diff --git a/libcutils/config_utils.c b/libcutils/config_utils.cpp
similarity index 97%
rename from libcutils/config_utils.c
rename to libcutils/config_utils.cpp
index fc5ca78..a3af01a 100644
--- a/libcutils/config_utils.c
+++ b/libcutils/config_utils.cpp
@@ -14,20 +14,19 @@
* limitations under the License.
*/
+#include <cutils/config_utils.h>
+
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
-#include <cutils/config_utils.h>
#include <cutils/misc.h>
cnode* config_node(const char *name, const char *value)
{
- cnode *node;
-
- node = calloc(sizeof(cnode), 1);
+ cnode* node = static_cast<cnode*>(calloc(sizeof(cnode), 1));
if(node) {
node->name = name ? name : "";
node->value = value ? value : "";
@@ -311,9 +310,9 @@
void config_load_file(cnode *root, const char *fn)
{
- char *data;
- data = load_file(fn, 0);
+ char* data = static_cast<char*>(load_file(fn, nullptr));
config_load(root, data);
+ // TODO: deliberate leak :-/
}
void config_free(cnode *root)
diff --git a/libcutils/fs.c b/libcutils/fs.cpp
similarity index 93%
rename from libcutils/fs.c
rename to libcutils/fs.cpp
index b253b1c..ef85acc 100644
--- a/libcutils/fs.c
+++ b/libcutils/fs.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <cutils/fs.h>
+
#define LOG_TAG "cutils"
/* These defines are only needed because prebuilt headers are out of date */
@@ -32,7 +34,6 @@
#include <sys/types.h>
#include <unistd.h>
-#include <cutils/fs.h>
#include <log/log.h>
#define ALL_PERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
@@ -40,6 +41,11 @@
static int fs_prepare_path_impl(const char* path, mode_t mode, uid_t uid, gid_t gid,
int allow_fixup, int prepare_as_dir) {
+ // TODO: fix the goto hell below.
+ int type_ok;
+ int owner_match;
+ int mode_match;
+
// Check if path needs to be created
struct stat sb;
int create_result = -1;
@@ -53,14 +59,14 @@
}
// Exists, verify status
- int type_ok = prepare_as_dir ? S_ISDIR(sb.st_mode) : S_ISREG(sb.st_mode);
+ type_ok = prepare_as_dir ? S_ISDIR(sb.st_mode) : S_ISREG(sb.st_mode);
if (!type_ok) {
ALOGE("Not a %s: %s", (prepare_as_dir ? "directory" : "regular file"), path);
return -1;
}
- int owner_match = ((sb.st_uid == uid) && (sb.st_gid == gid));
- int mode_match = ((sb.st_mode & ALL_PERMS) == mode);
+ owner_match = ((sb.st_uid == uid) && (sb.st_gid == gid));
+ mode_match = ((sb.st_mode & ALL_PERMS) == mode);
if (owner_match && mode_match) {
return 0;
} else if (allow_fixup) {
@@ -188,23 +194,20 @@
#ifndef __APPLE__
int fs_mkdirs(const char* path, mode_t mode) {
- int res = 0;
- int fd = 0;
- struct stat sb;
- char* buf = strdup(path);
-
- if (*buf != '/') {
- ALOGE("Relative paths are not allowed: %s", buf);
- res = -EINVAL;
- goto done;
+ if (*path != '/') {
+ ALOGE("Relative paths are not allowed: %s", path);
+ return -EINVAL;
}
- if ((fd = open("/", 0)) == -1) {
+ int fd = open("/", 0);
+ if (fd == -1) {
ALOGE("Failed to open(/): %s", strerror(errno));
- res = -errno;
- goto done;
+ return -errno;
}
+ struct stat sb;
+ int res = 0;
+ char* buf = strdup(path);
char* segment = buf + 1;
char* p = segment;
while (*p != '\0') {
@@ -266,7 +269,6 @@
done_close:
close(fd);
-done:
free(buf);
return res;
}
diff --git a/libcutils/fs_config.cpp b/libcutils/fs_config.cpp
index 7603ffc..f45472e 100644
--- a/libcutils/fs_config.cpp
+++ b/libcutils/fs_config.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <private/fs_config.h>
+
// This file is used to define the properties of the filesystem
// images generated by build tools (mkbootfs and mkyaffs2image) and
// by the device side of adb.
@@ -31,7 +33,6 @@
#include <log/log.h>
#include <private/android_filesystem_config.h>
-#include <private/fs_config.h>
#include <utils/Compat.h>
#ifndef O_BINARY
diff --git a/libcutils/hashmap.c b/libcutils/hashmap.cpp
similarity index 96%
rename from libcutils/hashmap.c
rename to libcutils/hashmap.cpp
index ede3b98..65b6ab1 100644
--- a/libcutils/hashmap.c
+++ b/libcutils/hashmap.cpp
@@ -15,6 +15,7 @@
*/
#include <cutils/hashmap.h>
+
#include <assert.h>
#include <errno.h>
#include <cutils/threads.h>
@@ -45,7 +46,7 @@
assert(hash != NULL);
assert(equals != NULL);
- Hashmap* map = malloc(sizeof(Hashmap));
+ Hashmap* map = static_cast<Hashmap*>(malloc(sizeof(Hashmap)));
if (map == NULL) {
return NULL;
}
@@ -58,7 +59,7 @@
map->bucketCount <<= 1;
}
- map->buckets = calloc(map->bucketCount, sizeof(Entry*));
+ map->buckets = static_cast<Entry**>(calloc(map->bucketCount, sizeof(Entry*)));
if (map->buckets == NULL) {
free(map);
return NULL;
@@ -106,7 +107,7 @@
if (map->size > (map->bucketCount * 3 / 4)) {
// Start off with a 0.33 load factor.
size_t newBucketCount = map->bucketCount << 1;
- Entry** newBuckets = calloc(newBucketCount, sizeof(Entry*));
+ Entry** newBuckets = static_cast<Entry**>(calloc(newBucketCount, sizeof(Entry*)));
if (newBuckets == NULL) {
// Abort expansion.
return;
@@ -171,7 +172,7 @@
}
static Entry* createEntry(void* key, int hash, void* value) {
- Entry* entry = malloc(sizeof(Entry));
+ Entry* entry = static_cast<Entry*>(malloc(sizeof(Entry)));
if (entry == NULL) {
return NULL;
}
diff --git a/libcutils/include/cutils/android_reboot.h b/libcutils/include/cutils/android_reboot.h
index a903adb..99030ed 100644
--- a/libcutils/include/cutils/android_reboot.h
+++ b/libcutils/include/cutils/android_reboot.h
@@ -17,6 +17,7 @@
#ifndef __CUTILS_ANDROID_REBOOT_H__
#define __CUTILS_ANDROID_REBOOT_H__
+#include <sys/cdefs.h>
__BEGIN_DECLS
diff --git a/libcutils/include/cutils/partition_utils.h b/libcutils/include/cutils/partition_utils.h
index 72ca80d..7518559 100644
--- a/libcutils/include/cutils/partition_utils.h
+++ b/libcutils/include/cutils/partition_utils.h
@@ -17,6 +17,8 @@
#ifndef __CUTILS_PARTITION_WIPED_H__
#define __CUTILS_PARTITION_WIPED_H__
+#include <sys/cdefs.h>
+
__BEGIN_DECLS
int partition_wiped(char *source);
diff --git a/libcutils/include/cutils/qtaguid.h b/libcutils/include/cutils/qtaguid.h
index 803fe0d..3f5e41f 100644
--- a/libcutils/include/cutils/qtaguid.h
+++ b/libcutils/include/cutils/qtaguid.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 The Android Open Source Project
+ * Copyright (C) 2017 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.
@@ -17,18 +17,14 @@
#ifndef __CUTILS_QTAGUID_H
#define __CUTILS_QTAGUID_H
-#include <stdint.h>
#include <sys/types.h>
-#include <unistd.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
- * Set tags (and owning UIDs) for network sockets. The socket must be untagged
- * by calling qtaguid_untagSocket() before closing it, otherwise the qtaguid
- * module will keep a reference to it even after close.
+ * Set tags (and owning UIDs) for network sockets.
*/
extern int qtaguid_tagSocket(int sockfd, int tag, uid_t uid);
@@ -46,8 +42,8 @@
/*
* Delete all tag info that relates to the given tag an uid.
- * If the tag is 0, then ALL info about the uid is freeded.
- * The delete data also affects active tagged socketd, which are
+ * If the tag is 0, then ALL info about the uid is freed.
+ * The delete data also affects active tagged sockets, which are
* then untagged.
* The calling process can only operate on its own tags.
* Unless it is part of the happy AID_NET_BW_ACCT group.
diff --git a/libcutils/include/cutils/record_stream.h b/libcutils/include/cutils/record_stream.h
index bfac87a..bcfc80d 100644
--- a/libcutils/include/cutils/record_stream.h
+++ b/libcutils/include/cutils/record_stream.h
@@ -25,6 +25,7 @@
extern "C" {
#endif
+#include <stddef.h>
typedef struct RecordStream RecordStream;
diff --git a/libcutils/include/private/android_filesystem_config.h b/libcutils/include/private/android_filesystem_config.h
index 55ece54..2ecf5bc 100644
--- a/libcutils/include/private/android_filesystem_config.h
+++ b/libcutils/include/private/android_filesystem_config.h
@@ -170,6 +170,14 @@
#define AID_SHARED_GID_START 50000 /* start of gids for apps in each user to share */
#define AID_SHARED_GID_END 59999 /* end of gids for apps in each user to share */
+/*
+ * This is a magic number in the kernel and not something that was picked
+ * arbitrarily. This value is returned whenever a uid that has no mapping in the
+ * user namespace is returned to userspace:
+ * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/highuid.h?h=v4.4#n40
+ */
+#define AID_OVERFLOWUID 65534 /* unmapped user in the user namespace */
+
#define AID_ISOLATED_START 99000 /* start of uids for fully isolated sandboxed processes */
#define AID_ISOLATED_END 99999 /* end of uids for fully isolated sandboxed processes */
diff --git a/libcutils/include/private/canned_fs_config.h b/libcutils/include/private/canned_fs_config.h
index 71e1537..135b91c 100644
--- a/libcutils/include/private/canned_fs_config.h
+++ b/libcutils/include/private/canned_fs_config.h
@@ -19,8 +19,12 @@
#include <inttypes.h>
+__BEGIN_DECLS
+
int load_canned_fs_config(const char* fn);
void canned_fs_config(const char* path, int dir, const char* target_out_path, unsigned* uid,
unsigned* gid, unsigned* mode, uint64_t* capabilities);
+__END_DECLS
+
#endif
diff --git a/libcutils/include/private/fs_config.h b/libcutils/include/private/fs_config.h
index aab5042..8926491 100644
--- a/libcutils/include/private/fs_config.h
+++ b/libcutils/include/private/fs_config.h
@@ -24,6 +24,7 @@
#include <stdint.h>
#include <sys/cdefs.h>
+#include <sys/types.h>
#if defined(__BIONIC__)
#include <linux/capability.h>
diff --git a/libcutils/iosched_policy.c b/libcutils/iosched_policy.cpp
similarity index 95%
rename from libcutils/iosched_policy.c
rename to libcutils/iosched_policy.cpp
index 13c2ceb..012c537 100644
--- a/libcutils/iosched_policy.c
+++ b/libcutils/iosched_policy.cpp
@@ -14,6 +14,8 @@
** limitations under the License.
*/
+#include <cutils/iosched_policy.h>
+
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@@ -21,8 +23,6 @@
#include <string.h>
#include <unistd.h>
-#include <cutils/iosched_policy.h>
-
#if defined(__ANDROID__)
#define IOPRIO_WHO_PROCESS (1)
#define IOPRIO_CLASS_SHIFT (13)
@@ -49,7 +49,7 @@
return -1;
}
- *clazz = (rc >> IOPRIO_CLASS_SHIFT);
+ *clazz = static_cast<IoSchedClass>(rc >> IOPRIO_CLASS_SHIFT);
*ioprio = (rc & 0xff);
#else
*clazz = IoSchedClass_NONE;
diff --git a/libcutils/klog.cpp b/libcutils/klog.cpp
index d301276..6a9f4df 100644
--- a/libcutils/klog.cpp
+++ b/libcutils/klog.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <cutils/klog.h>
+
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
@@ -25,7 +27,6 @@
#include <unistd.h>
#include <cutils/android_get_control_file.h>
-#include <cutils/klog.h>
static int klog_level = KLOG_INFO_LEVEL;
diff --git a/libcutils/load_file.c b/libcutils/load_file.cpp
similarity index 97%
rename from libcutils/load_file.c
rename to libcutils/load_file.cpp
index 99f2965..346105c 100644
--- a/libcutils/load_file.c
+++ b/libcutils/load_file.cpp
@@ -15,6 +15,8 @@
** limitations under the License.
*/
+#include <cutils/misc.h>
+
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
diff --git a/libcutils/native_handle.c b/libcutils/native_handle.cpp
similarity index 96%
rename from libcutils/native_handle.c
rename to libcutils/native_handle.cpp
index 95bbc41..66f7a3d 100644
--- a/libcutils/native_handle.c
+++ b/libcutils/native_handle.cpp
@@ -45,7 +45,7 @@
}
size_t mallocSize = sizeof(native_handle_t) + (sizeof(int) * (numFds + numInts));
- native_handle_t* h = malloc(mallocSize);
+ native_handle_t* h = static_cast<native_handle_t*>(malloc(mallocSize));
if (h) {
h->version = sizeof(native_handle_t);
h->numFds = numFds;
diff --git a/libcutils/partition_utils.c b/libcutils/partition_utils.cpp
similarity index 97%
rename from libcutils/partition_utils.c
rename to libcutils/partition_utils.cpp
index 823b162..6735d6c 100644
--- a/libcutils/partition_utils.c
+++ b/libcutils/partition_utils.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <cutils/partition_utils.h>
+
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mount.h> /* for BLKGETSIZE */
diff --git a/libcutils/properties.cpp b/libcutils/properties.cpp
index 25ff1a3..5dbbeba 100644
--- a/libcutils/properties.cpp
+++ b/libcutils/properties.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <cutils/properties.h>
+
#define LOG_TAG "properties"
// #define LOG_NDEBUG 0
@@ -25,7 +27,6 @@
#include <string.h>
#include <unistd.h>
-#include <cutils/properties.h>
#include <cutils/sockets.h>
#include <log/log.h>
diff --git a/libcutils/qtaguid.cpp b/libcutils/qtaguid.cpp
new file mode 100644
index 0000000..b94d134
--- /dev/null
+++ b/libcutils/qtaguid.cpp
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2017, 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 <cutils/qtaguid.h>
+
+// #define LOG_NDEBUG 0
+
+#define LOG_TAG "qtaguid"
+
+#include <dlfcn.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <log/log.h>
+
+class netdHandler {
+ public:
+ int (*netdTagSocket)(int, uint32_t, uid_t);
+ int (*netdUntagSocket)(int);
+ int (*netdSetCounterSet)(uint32_t, uid_t);
+ int (*netdDeleteTagData)(uint32_t, uid_t);
+};
+
+int dummyTagSocket(int, uint32_t, uid_t) {
+ return -EREMOTEIO;
+}
+
+int dummyUntagSocket(int) {
+ return -EREMOTEIO;
+}
+
+int dummySetCounterSet(uint32_t, uid_t) {
+ return -EREMOTEIO;
+}
+
+int dummyDeleteTagData(uint32_t, uid_t) {
+ return -EREMOTEIO;
+}
+
+netdHandler initHandler(void) {
+ netdHandler handler = {dummyTagSocket, dummyUntagSocket, dummySetCounterSet, dummyDeleteTagData};
+
+ void* netdClientHandle = dlopen("libnetd_client.so", RTLD_NOW);
+ if (!netdClientHandle) {
+ ALOGE("Failed to open libnetd_client.so: %s", dlerror());
+ return handler;
+ }
+
+ handler.netdTagSocket = (int (*)(int, uint32_t, uid_t))dlsym(netdClientHandle, "tagSocket");
+ if (!handler.netdTagSocket) {
+ ALOGE("load netdTagSocket handler failed: %s", dlerror());
+ }
+
+ handler.netdUntagSocket = (int (*)(int))dlsym(netdClientHandle, "untagSocket");
+ if (!handler.netdUntagSocket) {
+ ALOGE("load netdUntagSocket handler failed: %s", dlerror());
+ }
+
+ handler.netdSetCounterSet = (int (*)(uint32_t, uid_t))dlsym(netdClientHandle, "setCounterSet");
+ if (!handler.netdSetCounterSet) {
+ ALOGE("load netdSetCounterSet handler failed: %s", dlerror());
+ }
+
+ handler.netdDeleteTagData = (int (*)(uint32_t, uid_t))dlsym(netdClientHandle, "deleteTagData");
+ if (!handler.netdDeleteTagData) {
+ ALOGE("load netdDeleteTagData handler failed: %s", dlerror());
+ }
+ return handler;
+}
+
+// The language guarantees that this object will be initialized in a thread-safe way.
+static netdHandler& getHandler() {
+ static netdHandler instance = initHandler();
+ return instance;
+}
+
+int qtaguid_tagSocket(int sockfd, int tag, uid_t uid) {
+ // Check the socket fd passed to us is still valid before we load the netd
+ // client. Pass a already closed socket fd to netd client may let netd open
+ // the unix socket with the same fd number and pass it to server for
+ // tagging.
+ // TODO: move the check into netdTagSocket.
+ int res = fcntl(sockfd, F_GETFD);
+ if (res < 0) return res;
+
+ ALOGV("Tagging socket %d with tag %u for uid %d", sockfd, tag, uid);
+ return getHandler().netdTagSocket(sockfd, tag, uid);
+}
+
+int qtaguid_untagSocket(int sockfd) {
+ // Similiar to tag socket. We need a check before untag to make sure untag a closed socket fail
+ // as expected.
+ // TODO: move the check into netdTagSocket.
+ int res = fcntl(sockfd, F_GETFD);
+ if (res < 0) return res;
+
+ ALOGV("Untagging socket %d", sockfd);
+ return getHandler().netdUntagSocket(sockfd);
+}
+
+int qtaguid_setCounterSet(int counterSetNum, uid_t uid) {
+ ALOGV("Setting counters to set %d for uid %d", counterSetNum, uid);
+ return getHandler().netdSetCounterSet(counterSetNum, uid);
+}
+
+int qtaguid_deleteTagData(int tag, uid_t uid) {
+ ALOGV("Deleting tag data with tag %u for uid %d", tag, uid);
+ return getHandler().netdDeleteTagData(tag, uid);
+}
diff --git a/libcutils/record_stream.c b/libcutils/record_stream.cpp
similarity index 99%
rename from libcutils/record_stream.c
rename to libcutils/record_stream.cpp
index 2bc4226..5a86b83 100644
--- a/libcutils/record_stream.c
+++ b/libcutils/record_stream.cpp
@@ -15,11 +15,12 @@
** limitations under the License.
*/
+#include <cutils/record_stream.h>
+
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
-#include <cutils/record_stream.h>
#include <string.h>
#include <stdint.h>
#if defined(_WIN32)
diff --git a/libcutils/sched_policy.cpp b/libcutils/sched_policy.cpp
index b00fa85..0e6d333 100644
--- a/libcutils/sched_policy.cpp
+++ b/libcutils/sched_policy.cpp
@@ -14,6 +14,8 @@
** limitations under the License.
*/
+#include <cutils/sched_policy.h>
+
#define LOG_TAG "SchedPolicy"
#include <errno.h>
@@ -24,7 +26,6 @@
#include <unistd.h>
#include <log/log.h>
-#include <cutils/sched_policy.h>
#define UNUSED __attribute__((__unused__))
diff --git a/libcutils/socket_inaddr_any_server_unix.c b/libcutils/socket_inaddr_any_server_unix.cpp
similarity index 99%
rename from libcutils/socket_inaddr_any_server_unix.c
rename to libcutils/socket_inaddr_any_server_unix.cpp
index 387258f..27c5333 100644
--- a/libcutils/socket_inaddr_any_server_unix.c
+++ b/libcutils/socket_inaddr_any_server_unix.cpp
@@ -14,6 +14,8 @@
** limitations under the License.
*/
+#include <cutils/sockets.h>
+
#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
@@ -25,8 +27,6 @@
#include <sys/types.h>
#include <netinet/in.h>
-#include <cutils/sockets.h>
-
#define LISTEN_BACKLOG 4
/* open listen() port on any interface */
diff --git a/libcutils/socket_inaddr_any_server_windows.c b/libcutils/socket_inaddr_any_server_windows.cpp
similarity index 99%
rename from libcutils/socket_inaddr_any_server_windows.c
rename to libcutils/socket_inaddr_any_server_windows.cpp
index c15200a..1d73206 100644
--- a/libcutils/socket_inaddr_any_server_windows.c
+++ b/libcutils/socket_inaddr_any_server_windows.cpp
@@ -26,10 +26,10 @@
* SUCH DAMAGE.
*/
-#include <errno.h>
-
#include <cutils/sockets.h>
+#include <errno.h>
+
#define LISTEN_BACKLOG 4
extern bool initialize_windows_sockets();
diff --git a/libcutils/socket_local_client_unix.c b/libcutils/socket_local_client_unix.cpp
similarity index 99%
rename from libcutils/socket_local_client_unix.c
rename to libcutils/socket_local_client_unix.cpp
index 92fb9f1..68b2b0c 100644
--- a/libcutils/socket_local_client_unix.c
+++ b/libcutils/socket_local_client_unix.cpp
@@ -14,14 +14,14 @@
* limitations under the License.
*/
+#include <cutils/sockets.h>
+
#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <cutils/sockets.h>
-
#if defined(_WIN32)
int socket_local_client(const char *name, int namespaceId, int type)
diff --git a/libcutils/socket_local_server_unix.c b/libcutils/socket_local_server_unix.cpp
similarity index 94%
rename from libcutils/socket_local_server_unix.c
rename to libcutils/socket_local_server_unix.cpp
index db9e1e0..855e5da 100644
--- a/libcutils/socket_local_server_unix.c
+++ b/libcutils/socket_local_server_unix.cpp
@@ -94,7 +94,7 @@
* Returns fd on success, -1 on fail
*/
-int socket_local_server(const char *name, int namespace, int type)
+int socket_local_server(const char *name, int namespaceId, int type)
{
int err;
int s;
@@ -102,7 +102,7 @@
s = socket(AF_LOCAL, type, 0);
if (s < 0) return -1;
- err = socket_local_server_bind(s, name, namespace);
+ err = socket_local_server_bind(s, name, namespaceId);
if (err < 0) {
close(s);
diff --git a/libcutils/socket_network_client_unix.c b/libcutils/socket_network_client_unix.cpp
similarity index 99%
rename from libcutils/socket_network_client_unix.c
rename to libcutils/socket_network_client_unix.cpp
index 1b87c49..be3c535 100644
--- a/libcutils/socket_network_client_unix.c
+++ b/libcutils/socket_network_client_unix.cpp
@@ -14,6 +14,8 @@
** limitations under the License.
*/
+#include <cutils/sockets.h>
+
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
@@ -27,8 +29,6 @@
#include <netinet/in.h>
#include <netdb.h>
-#include <cutils/sockets.h>
-
static int toggle_O_NONBLOCK(int s) {
int flags = fcntl(s, F_GETFL);
if (flags == -1 || fcntl(s, F_SETFL, flags ^ O_NONBLOCK) == -1) {
diff --git a/libcutils/socket_network_client_windows.c b/libcutils/socket_network_client_windows.cpp
similarity index 100%
rename from libcutils/socket_network_client_windows.c
rename to libcutils/socket_network_client_windows.cpp
diff --git a/libcutils/sockets_unix.cpp b/libcutils/sockets_unix.cpp
index e91f358..2849aa8 100644
--- a/libcutils/sockets_unix.cpp
+++ b/libcutils/sockets_unix.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <cutils/sockets.h>
+
#define LOG_TAG "socket-unix"
#include <stdio.h>
@@ -26,7 +28,6 @@
#include <unistd.h>
#include <cutils/android_get_control_file.h>
-#include <cutils/sockets.h>
#include <log/log.h>
#include "android_get_control_env.h"
diff --git a/libcutils/sockets_windows.cpp b/libcutils/sockets_windows.cpp
index 3064c70..3e49b85 100644
--- a/libcutils/sockets_windows.cpp
+++ b/libcutils/sockets_windows.cpp
@@ -37,7 +37,7 @@
// Both adb (1) and Chrome (2) purposefully avoid WSACleanup() with no issues.
// (1) https://android.googlesource.com/platform/system/core.git/+/master/adb/sysdeps_win32.cpp
// (2) https://code.google.com/p/chromium/codesearch#chromium/src/net/base/winsock_init.cc
-extern "C" bool initialize_windows_sockets() {
+bool initialize_windows_sockets() {
// There's no harm in calling WSAStartup() multiple times but no benefit
// either, we may as well skip it after the first.
static bool init_success = false;
diff --git a/libcutils/str_parms.c b/libcutils/str_parms.cpp
similarity index 90%
rename from libcutils/str_parms.c
rename to libcutils/str_parms.cpp
index 8dafded..139d62f 100644
--- a/libcutils/str_parms.c
+++ b/libcutils/str_parms.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <cutils/str_parms.h>
+
#define LOG_TAG "str_params"
//#define LOG_NDEBUG 0
@@ -26,7 +28,6 @@
#include <cutils/hashmap.h>
#include <cutils/memory.h>
-#include <cutils/str_parms.h>
#include <log/log.h>
#define UNUSED __attribute__((unused))
@@ -62,30 +63,24 @@
static int str_hash_fn(void *str)
{
uint32_t hash = 5381;
- char *p;
- for (p = str; p && *p; p++)
+ for (char* p = static_cast<char*>(str); p && *p; p++)
hash = ((hash << 5) + hash) + *p;
return (int)hash;
}
struct str_parms *str_parms_create(void)
{
- struct str_parms *str_parms;
+ str_parms* s = static_cast<str_parms*>(calloc(1, sizeof(str_parms)));
+ if (!s) return NULL;
- str_parms = calloc(1, sizeof(struct str_parms));
- if (!str_parms)
+ s->map = hashmapCreate(5, str_hash_fn, str_eq);
+ if (!s->map) {
+ free(s);
return NULL;
+ }
- str_parms->map = hashmapCreate(5, str_hash_fn, str_eq);
- if (!str_parms->map)
- goto err;
-
- return str_parms;
-
-err:
- free(str_parms);
- return NULL;
+ return s;
}
struct remove_ctxt {
@@ -95,7 +90,7 @@
static bool remove_pair(void *key, void *value, void *context)
{
- struct remove_ctxt *ctxt = context;
+ remove_ctxt* ctxt = static_cast<remove_ctxt*>(context);
bool should_continue;
/*
@@ -109,7 +104,7 @@
if (!ctxt->key) {
should_continue = true;
goto do_remove;
- } else if (!strcmp(ctxt->key, key)) {
+ } else if (!strcmp(ctxt->key, static_cast<const char*>(key))) {
should_continue = false;
goto do_remove;
}
@@ -292,9 +287,8 @@
int str_parms_get_str(struct str_parms *str_parms, const char *key, char *val,
int len)
{
- char *value;
-
- value = hashmapGet(str_parms->map, (void *)key);
+ // TODO: hashmapGet should take a const* key.
+ char* value = static_cast<char*>(hashmapGet(str_parms->map, (void*)key));
if (value)
return strlcpy(val, value, len);
@@ -303,10 +297,10 @@
int str_parms_get_int(struct str_parms *str_parms, const char *key, int *val)
{
- char *value;
char *end;
- value = hashmapGet(str_parms->map, (void *)key);
+ // TODO: hashmapGet should take a const* key.
+ char* value = static_cast<char*>(hashmapGet(str_parms->map, (void*)key));
if (!value)
return -ENOENT;
@@ -321,10 +315,10 @@
float *val)
{
float out;
- char *value;
char *end;
- value = hashmapGet(str_parms->map, (void *)key);
+ // TODO: hashmapGet should take a const* key.
+ char* value = static_cast<char*>(hashmapGet(str_parms->map, (void*)(key)));
if (!value)
return -ENOENT;
@@ -338,7 +332,7 @@
static bool combine_strings(void *key, void *value, void *context)
{
- char **old_str = context;
+ char** old_str = static_cast<char**>(context);
char *new_str;
int ret;
diff --git a/libcutils/strdup16to8.c b/libcutils/strdup16to8.cpp
similarity index 97%
rename from libcutils/strdup16to8.c
rename to libcutils/strdup16to8.cpp
index 4dc987e..d89181e 100644
--- a/libcutils/strdup16to8.c
+++ b/libcutils/strdup16to8.cpp
@@ -15,10 +15,10 @@
** limitations under the License.
*/
-#include <limits.h> /* for SIZE_MAX */
-
#include <cutils/jstring.h>
+
#include <assert.h>
+#include <limits.h> /* for SIZE_MAX */
#include <stdlib.h>
@@ -145,14 +145,11 @@
*/
char * strndup16to8 (const char16_t* s, size_t n)
{
- char* ret;
- size_t len;
-
if (s == NULL) {
return NULL;
}
- len = strnlen16to8(s, n);
+ size_t len = strnlen16to8(s, n);
/* We are paranoid, and we check for SIZE_MAX-1
* too since it is an overflow value for our
@@ -161,7 +158,7 @@
if (len >= SIZE_MAX-1)
return NULL;
- ret = malloc(len + 1);
+ char* ret = static_cast<char*>(malloc(len + 1));
if (ret == NULL)
return NULL;
diff --git a/libcutils/strdup8to16.c b/libcutils/strdup8to16.cpp
similarity index 98%
rename from libcutils/strdup8to16.c
rename to libcutils/strdup8to16.cpp
index c23cf8b..d1e51b9 100644
--- a/libcutils/strdup8to16.c
+++ b/libcutils/strdup8to16.cpp
@@ -16,9 +16,10 @@
*/
#include <cutils/jstring.h>
+
#include <assert.h>
-#include <stdlib.h>
#include <limits.h>
+#include <stdlib.h>
/* See http://www.unicode.org/reports/tr22/ for discussion
* on invalid sequences
@@ -116,7 +117,7 @@
int i;
/* Mask for leader byte for lengths 1, 2, 3, and 4 respectively*/
- static const char leaderMask[4] = {0xff, 0x1f, 0x0f, 0x07};
+ static const unsigned char leaderMask[4] = {0xff, 0x1f, 0x0f, 0x07};
/* Bytes that start with bits "10" are not leading characters. */
if (((**pUtf8Ptr) & 0xc0) == 0x80) {
diff --git a/libcutils/tests/trace-dev_test.cpp b/libcutils/tests/trace-dev_test.cpp
index edf981b..f8d4f00 100644
--- a/libcutils/tests/trace-dev_test.cpp
+++ b/libcutils/tests/trace-dev_test.cpp
@@ -25,7 +25,7 @@
#include <android-base/test_utils.h>
#include <gtest/gtest.h>
-#include "../trace-dev.c"
+#include "../trace-dev.cpp"
class TraceDevTest : public ::testing::Test {
protected:
diff --git a/libcutils/threads.c b/libcutils/threads.cpp
similarity index 98%
rename from libcutils/threads.c
rename to libcutils/threads.cpp
index 4bae39e..beea8bd 100644
--- a/libcutils/threads.c
+++ b/libcutils/threads.cpp
@@ -14,7 +14,7 @@
** limitations under the License.
*/
-#include "cutils/threads.h"
+#include <cutils/threads.h>
// For gettid.
#if defined(__APPLE__)
diff --git a/libcutils/trace-container.c b/libcutils/trace-container.cpp
similarity index 99%
rename from libcutils/trace-container.c
rename to libcutils/trace-container.cpp
index 03e91b1..d981f8f 100644
--- a/libcutils/trace-container.c
+++ b/libcutils/trace-container.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <cutils/trace.h>
+
#include "trace-dev.inc"
#include <cutils/sockets.h>
diff --git a/libcutils/trace-dev.c b/libcutils/trace-dev.cpp
similarity index 98%
rename from libcutils/trace-dev.c
rename to libcutils/trace-dev.cpp
index 4468e83..4da8215 100644
--- a/libcutils/trace-dev.c
+++ b/libcutils/trace-dev.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <cutils/trace.h>
+
#include "trace-dev.inc"
static pthread_once_t atrace_once_control = PTHREAD_ONCE_INIT;
diff --git a/libcutils/trace-host.c b/libcutils/trace-host.cpp
similarity index 100%
rename from libcutils/trace-host.c
rename to libcutils/trace-host.cpp
diff --git a/libcutils/uevent.c b/libcutils/uevent.c
deleted file mode 100644
index f548dca..0000000
--- a/libcutils/uevent.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (C) 2011 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 <cutils/uevent.h>
-
-#include <errno.h>
-#include <stdbool.h>
-#include <string.h>
-#include <strings.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <unistd.h>
-
-#include <linux/netlink.h>
-
-/**
- * Like recv(), but checks that messages actually originate from the kernel.
- */
-ssize_t uevent_kernel_multicast_recv(int socket, void *buffer, size_t length)
-{
- uid_t uid = -1;
- return uevent_kernel_multicast_uid_recv(socket, buffer, length, &uid);
-}
-
-/**
- * Like the above, but passes a uid_t in by pointer. In the event that this
- * fails due to a bad uid check, the uid_t will be set to the uid of the
- * socket's peer.
- *
- * If this method rejects a netlink message from outside the kernel, it
- * returns -1, sets errno to EIO, and sets "user" to the UID associated with the
- * message. If the peer UID cannot be determined, "user" is set to -1."
- */
-ssize_t uevent_kernel_multicast_uid_recv(int socket, void *buffer, size_t length, uid_t *uid)
-{
- return uevent_kernel_recv(socket, buffer, length, true, uid);
-}
-
-ssize_t uevent_kernel_recv(int socket, void *buffer, size_t length, bool require_group, uid_t *uid)
-{
- struct iovec iov = { buffer, length };
- struct sockaddr_nl addr;
- char control[CMSG_SPACE(sizeof(struct ucred))];
- struct msghdr hdr = {
- &addr,
- sizeof(addr),
- &iov,
- 1,
- control,
- sizeof(control),
- 0,
- };
-
- *uid = -1;
- ssize_t n = recvmsg(socket, &hdr, 0);
- if (n <= 0) {
- return n;
- }
-
- struct cmsghdr *cmsg = CMSG_FIRSTHDR(&hdr);
- if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) {
- /* ignoring netlink message with no sender credentials */
- goto out;
- }
-
- struct ucred *cred = (struct ucred *)CMSG_DATA(cmsg);
- *uid = cred->uid;
- if (cred->uid != 0) {
- /* ignoring netlink message from non-root user */
- goto out;
- }
-
- if (addr.nl_pid != 0) {
- /* ignore non-kernel */
- goto out;
- }
- if (require_group && addr.nl_groups == 0) {
- /* ignore unicast messages when requested */
- goto out;
- }
-
- return n;
-
-out:
- /* clear residual potentially malicious data */
- bzero(buffer, length);
- errno = EIO;
- return -1;
-}
-
-int uevent_open_socket(int buf_sz, bool passcred)
-{
- struct sockaddr_nl addr;
- int on = passcred;
- int s;
-
- memset(&addr, 0, sizeof(addr));
- addr.nl_family = AF_NETLINK;
- addr.nl_pid = getpid();
- addr.nl_groups = 0xffffffff;
-
- s = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT);
- if(s < 0)
- return -1;
-
- /* buf_sz should be less than net.core.rmem_max for this to succeed */
- if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &buf_sz, sizeof(buf_sz)) < 0) {
- close(s);
- return -1;
- }
-
- setsockopt(s, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
-
- if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- close(s);
- return -1;
- }
-
- return s;
-}
diff --git a/libcutils/uevent.cpp b/libcutils/uevent.cpp
new file mode 100644
index 0000000..a84e5b0
--- /dev/null
+++ b/libcutils/uevent.cpp
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2011 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 <cutils/uevent.h>
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+#include <linux/netlink.h>
+
+#include <fstream>
+
+#include <private/android_filesystem_config.h>
+
+namespace {
+
+// Returns the uid of root in the current user namespace.
+// Returns AID_OVERFLOWUID if the root user is not mapped in the current
+// namespace.
+// Returns 0 if the kernel is not user namespace-aware (for backwards
+// compatibility) or if AID_OVERFLOWUID could not be validated to match what the
+// kernel would return.
+uid_t GetRootUid() {
+ constexpr uid_t kParentRootUid = 0;
+
+ std::ifstream uid_map_file("/proc/self/uid_map");
+ if (!uid_map_file) {
+ // The kernel does not support user namespaces.
+ return kParentRootUid;
+ }
+
+ uid_t current_namespace_uid, parent_namespace_uid;
+ uint32_t length;
+ while (uid_map_file >> current_namespace_uid >> parent_namespace_uid >> length) {
+ // Since kParentRootUid is 0, it should be the first entry in the mapped
+ // range.
+ if (parent_namespace_uid != kParentRootUid || length < 1) continue;
+ return current_namespace_uid;
+ }
+
+ // Sanity check: verify that the overflow UID is the one to be returned by
+ // the kernel.
+ std::ifstream overflowuid_file("/proc/sys/kernel/overflowuid");
+ if (!overflowuid_file) {
+ // It's better to return 0 in case we cannot make sure that the overflow
+ // UID matches.
+ return kParentRootUid;
+ }
+ uid_t kernel_overflow_uid;
+ if (!(overflowuid_file >> kernel_overflow_uid) || kernel_overflow_uid != AID_OVERFLOWUID)
+ return kParentRootUid;
+
+ // root is unmapped, use the kernel "overflow" uid.
+ return AID_OVERFLOWUID;
+}
+
+} // namespace
+
+extern "C" {
+
+/**
+ * Like recv(), but checks that messages actually originate from the kernel.
+ */
+ssize_t uevent_kernel_multicast_recv(int socket, void* buffer, size_t length) {
+ uid_t uid = -1;
+ return uevent_kernel_multicast_uid_recv(socket, buffer, length, &uid);
+}
+
+/**
+ * Like the above, but passes a uid_t in by pointer. In the event that this
+ * fails due to a bad uid check, the uid_t will be set to the uid of the
+ * socket's peer.
+ *
+ * If this method rejects a netlink message from outside the kernel, it
+ * returns -1, sets errno to EIO, and sets "user" to the UID associated with the
+ * message. If the peer UID cannot be determined, "user" is set to -1."
+ */
+ssize_t uevent_kernel_multicast_uid_recv(int socket, void* buffer, size_t length, uid_t* uid) {
+ return uevent_kernel_recv(socket, buffer, length, true, uid);
+}
+
+ssize_t uevent_kernel_recv(int socket, void* buffer, size_t length, bool require_group, uid_t* uid) {
+ static const uid_t root_uid = GetRootUid();
+ struct iovec iov = {buffer, length};
+ struct sockaddr_nl addr;
+ char control[CMSG_SPACE(sizeof(struct ucred))];
+ struct msghdr hdr = {
+ &addr, sizeof(addr), &iov, 1, control, sizeof(control), 0,
+ };
+ struct ucred* cred;
+
+ *uid = -1;
+ ssize_t n = recvmsg(socket, &hdr, 0);
+ if (n <= 0) {
+ return n;
+ }
+
+ struct cmsghdr* cmsg = CMSG_FIRSTHDR(&hdr);
+ if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) {
+ /* ignoring netlink message with no sender credentials */
+ goto out;
+ }
+
+ cred = (struct ucred*)CMSG_DATA(cmsg);
+ *uid = cred->uid;
+ if (cred->uid != root_uid) {
+ /* ignoring netlink message from non-root user */
+ goto out;
+ }
+
+ if (addr.nl_pid != 0) {
+ /* ignore non-kernel */
+ goto out;
+ }
+ if (require_group && addr.nl_groups == 0) {
+ /* ignore unicast messages when requested */
+ goto out;
+ }
+
+ return n;
+
+out:
+ /* clear residual potentially malicious data */
+ bzero(buffer, length);
+ errno = EIO;
+ return -1;
+}
+
+int uevent_open_socket(int buf_sz, bool passcred) {
+ struct sockaddr_nl addr;
+ int on = passcred;
+ int s;
+
+ memset(&addr, 0, sizeof(addr));
+ addr.nl_family = AF_NETLINK;
+ addr.nl_pid = getpid();
+ addr.nl_groups = 0xffffffff;
+
+ s = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT);
+ if (s < 0) return -1;
+
+ /* buf_sz should be less than net.core.rmem_max for this to succeed */
+ if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &buf_sz, sizeof(buf_sz)) < 0) {
+ close(s);
+ return -1;
+ }
+
+ setsockopt(s, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
+
+ if (bind(s, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
+ close(s);
+ return -1;
+ }
+
+ return s;
+}
+
+} // extern "C"
diff --git a/libpixelflinger/codeflinger/MIPS64Assembler.cpp b/libpixelflinger/codeflinger/MIPS64Assembler.cpp
index d5e4cea..d6d2156 100644
--- a/libpixelflinger/codeflinger/MIPS64Assembler.cpp
+++ b/libpixelflinger/codeflinger/MIPS64Assembler.cpp
@@ -39,6 +39,7 @@
#include "mips64_disassem.h"
#define NOT_IMPLEMENTED() LOG_ALWAYS_FATAL("Arm instruction %s not yet implemented\n", __func__)
+#define __unused __attribute__((__unused__))
// ----------------------------------------------------------------------------
@@ -146,7 +147,7 @@
mMips->MOVE(R_v0, R_a0); // move context * passed in a0 to v0 (arm r0)
}
-void ArmToMips64Assembler::epilog(uint32_t touched)
+void ArmToMips64Assembler::epilog(uint32_t touched __unused)
{
mArmPC[mInum++] = pc(); // save starting PC for this instr
@@ -205,7 +206,7 @@
// shifters...
-bool ArmToMips64Assembler::isValidImmediate(uint32_t immediate)
+bool ArmToMips64Assembler::isValidImmediate(uint32_t immediate __unused)
{
// for MIPS, any 32-bit immediate is OK
return true;
@@ -225,13 +226,14 @@
return AMODE_REG_IMM;
}
-uint32_t ArmToMips64Assembler::reg_rrx(int Rm)
+uint32_t ArmToMips64Assembler::reg_rrx(int Rm __unused)
{
// reg_rrx mode is not used in the GLLAssember code at this time
return AMODE_UNSUPPORTED;
}
-uint32_t ArmToMips64Assembler::reg_reg(int Rm, int type, int Rs)
+uint32_t ArmToMips64Assembler::reg_reg(int Rm __unused, int type __unused,
+ int Rs __unused)
{
// reg_reg mode is not used in the GLLAssember code at this time
return AMODE_UNSUPPORTED;
@@ -272,14 +274,15 @@
return AMODE_REG_SCALE_PRE;
}
-uint32_t ArmToMips64Assembler::reg_scale_post(int Rm, int type, uint32_t shift)
+uint32_t ArmToMips64Assembler::reg_scale_post(int Rm __unused, int type __unused,
+ uint32_t shift __unused)
{
LOG_ALWAYS_FATAL("adr mode reg_scale_post not yet implemented\n");
return AMODE_UNSUPPORTED;
}
// LDRH/LDRSB/LDRSH/STRH (immediate and Rm can be negative, which indicate U=0)
-uint32_t ArmToMips64Assembler::immed8_pre(int32_t immed8, int W)
+uint32_t ArmToMips64Assembler::immed8_pre(int32_t immed8, int W __unused)
{
LOG_ALWAYS_FATAL("adr mode immed8_pre not yet implemented\n");
@@ -305,7 +308,7 @@
return AMODE_REG_PRE;
}
-uint32_t ArmToMips64Assembler::reg_post(int Rm)
+uint32_t ArmToMips64Assembler::reg_post(int Rm __unused)
{
LOG_ALWAYS_FATAL("adr mode reg_post not yet implemented\n");
return AMODE_UNSUPPORTED;
@@ -320,12 +323,6 @@
#pragma mark Data Processing...
#endif
-
-static const char * const dpOpNames[] = {
- "AND", "EOR", "SUB", "RSB", "ADD", "ADC", "SBC", "RSC",
- "TST", "TEQ", "CMP", "CMN", "ORR", "MOV", "BIC", "MVN"
-};
-
// check if the operand registers from a previous CMP or S-bit instruction
// would be overwritten by this instruction. If so, move the value to a
// safe register.
@@ -594,7 +591,7 @@
#endif
// multiply, accumulate
-void ArmToMips64Assembler::MLA(int cc, int s,
+void ArmToMips64Assembler::MLA(int cc __unused, int s,
int Rd, int Rm, int Rs, int Rn) {
//ALOGW("MLA");
@@ -608,7 +605,7 @@
}
}
-void ArmToMips64Assembler::MUL(int cc, int s,
+void ArmToMips64Assembler::MUL(int cc __unused, int s,
int Rd, int Rm, int Rs) {
mArmPC[mInum++] = pc();
mMips->MUL(Rd, Rm, Rs);
@@ -618,7 +615,7 @@
}
}
-void ArmToMips64Assembler::UMULL(int cc, int s,
+void ArmToMips64Assembler::UMULL(int cc __unused, int s,
int RdLo, int RdHi, int Rm, int Rs) {
mArmPC[mInum++] = pc();
mMips->MUH(RdHi, Rm, Rs);
@@ -631,8 +628,8 @@
}
}
-void ArmToMips64Assembler::UMUAL(int cc, int s,
- int RdLo, int RdHi, int Rm, int Rs) {
+void ArmToMips64Assembler::UMUAL(int cc __unused, int s,
+ int RdLo __unused, int RdHi, int Rm __unused, int Rs __unused) {
LOG_FATAL_IF(RdLo==Rm || RdHi==Rm || RdLo==RdHi,
"UMUAL(r%u,r%u,r%u,r%u)", RdLo,RdHi,Rm,Rs);
// *mPC++ = (cc<<28) | (1<<23) | (1<<21) | (s<<20) |
@@ -647,8 +644,8 @@
}
}
-void ArmToMips64Assembler::SMULL(int cc, int s,
- int RdLo, int RdHi, int Rm, int Rs) {
+void ArmToMips64Assembler::SMULL(int cc __unused, int s,
+ int RdLo __unused, int RdHi, int Rm __unused, int Rs __unused) {
LOG_FATAL_IF(RdLo==Rm || RdHi==Rm || RdLo==RdHi,
"SMULL(r%u,r%u,r%u,r%u)", RdLo,RdHi,Rm,Rs);
// *mPC++ = (cc<<28) | (1<<23) | (1<<22) | (s<<20) |
@@ -662,8 +659,8 @@
LOG_ALWAYS_FATAL("Condition on SMULL must be on 64-bit result\n");
}
}
-void ArmToMips64Assembler::SMUAL(int cc, int s,
- int RdLo, int RdHi, int Rm, int Rs) {
+void ArmToMips64Assembler::SMUAL(int cc __unused, int s,
+ int RdLo __unused, int RdHi, int Rm __unused, int Rs __unused) {
LOG_FATAL_IF(RdLo==Rm || RdHi==Rm || RdLo==RdHi,
"SMUAL(r%u,r%u,r%u,r%u)", RdLo,RdHi,Rm,Rs);
// *mPC++ = (cc<<28) | (1<<23) | (1<<22) | (1<<21) | (s<<20) |
@@ -717,26 +714,26 @@
}
}
-void ArmToMips64Assembler::BL(int cc, const char* label)
+void ArmToMips64Assembler::BL(int cc __unused, const char* label __unused)
{
LOG_ALWAYS_FATAL("branch-and-link not supported yet\n");
mArmPC[mInum++] = pc();
}
// no use for Branches with integer PC, but they're in the Interface class ....
-void ArmToMips64Assembler::B(int cc, uint32_t* to_pc)
+void ArmToMips64Assembler::B(int cc __unused, uint32_t* to_pc __unused)
{
LOG_ALWAYS_FATAL("branch to absolute PC not supported, use Label\n");
mArmPC[mInum++] = pc();
}
-void ArmToMips64Assembler::BL(int cc, uint32_t* to_pc)
+void ArmToMips64Assembler::BL(int cc __unused, uint32_t* to_pc __unused)
{
LOG_ALWAYS_FATAL("branch to absolute PC not supported, use Label\n");
mArmPC[mInum++] = pc();
}
-void ArmToMips64Assembler::BX(int cc, int Rn)
+void ArmToMips64Assembler::BX(int cc __unused, int Rn __unused)
{
LOG_ALWAYS_FATAL("branch to absolute PC not supported, use Label\n");
mArmPC[mInum++] = pc();
@@ -750,7 +747,7 @@
#endif
// data transfer...
-void ArmToMips64Assembler::LDR(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMips64Assembler::LDR(int cc __unused, int Rd, int Rn, uint32_t offset)
{
mArmPC[mInum++] = pc();
// work-around for ARM default address mode of immed12_pre(0)
@@ -784,7 +781,7 @@
}
}
-void ArmToMips64Assembler::LDRB(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMips64Assembler::LDRB(int cc __unused, int Rd, int Rn, uint32_t offset)
{
mArmPC[mInum++] = pc();
// work-around for ARM default address mode of immed12_pre(0)
@@ -813,7 +810,7 @@
}
-void ArmToMips64Assembler::STR(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMips64Assembler::STR(int cc __unused, int Rd, int Rn, uint32_t offset)
{
mArmPC[mInum++] = pc();
// work-around for ARM default address mode of immed12_pre(0)
@@ -849,7 +846,7 @@
}
}
-void ArmToMips64Assembler::STRB(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMips64Assembler::STRB(int cc __unused, int Rd, int Rn, uint32_t offset)
{
mArmPC[mInum++] = pc();
// work-around for ARM default address mode of immed12_pre(0)
@@ -877,7 +874,7 @@
}
}
-void ArmToMips64Assembler::LDRH(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMips64Assembler::LDRH(int cc __unused, int Rd, int Rn, uint32_t offset)
{
mArmPC[mInum++] = pc();
// work-around for ARM default address mode of immed8_pre(0)
@@ -905,21 +902,23 @@
}
}
-void ArmToMips64Assembler::LDRSB(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMips64Assembler::LDRSB(int cc __unused, int Rd __unused,
+ int Rn __unused, uint32_t offset __unused)
{
mArmPC[mInum++] = pc();
mMips->NOP2();
NOT_IMPLEMENTED();
}
-void ArmToMips64Assembler::LDRSH(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMips64Assembler::LDRSH(int cc __unused, int Rd __unused,
+ int Rn __unused, uint32_t offset __unused)
{
mArmPC[mInum++] = pc();
mMips->NOP2();
NOT_IMPLEMENTED();
}
-void ArmToMips64Assembler::STRH(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMips64Assembler::STRH(int cc __unused, int Rd, int Rn, uint32_t offset)
{
mArmPC[mInum++] = pc();
// work-around for ARM default address mode of immed8_pre(0)
@@ -955,8 +954,8 @@
#endif
// block data transfer...
-void ArmToMips64Assembler::LDM(int cc, int dir,
- int Rn, int W, uint32_t reg_list)
+void ArmToMips64Assembler::LDM(int cc __unused, int dir __unused,
+ int Rn __unused, int W __unused, uint32_t reg_list __unused)
{ // ED FD EA FA IB IA DB DA
// const uint8_t P[8] = { 1, 0, 1, 0, 1, 0, 1, 0 };
// const uint8_t U[8] = { 1, 1, 0, 0, 1, 1, 0, 0 };
@@ -967,8 +966,8 @@
NOT_IMPLEMENTED();
}
-void ArmToMips64Assembler::STM(int cc, int dir,
- int Rn, int W, uint32_t reg_list)
+void ArmToMips64Assembler::STM(int cc __unused, int dir __unused,
+ int Rn __unused, int W __unused, uint32_t reg_list __unused)
{ // FA EA FD ED IB IA DB DA
// const uint8_t P[8] = { 0, 1, 0, 1, 1, 0, 1, 0 };
// const uint8_t U[8] = { 0, 0, 1, 1, 1, 1, 0, 0 };
@@ -987,21 +986,23 @@
#endif
// special...
-void ArmToMips64Assembler::SWP(int cc, int Rn, int Rd, int Rm) {
+void ArmToMips64Assembler::SWP(int cc __unused, int Rn __unused,
+ int Rd __unused, int Rm __unused) {
// *mPC++ = (cc<<28) | (2<<23) | (Rn<<16) | (Rd << 12) | 0x90 | Rm;
mArmPC[mInum++] = pc();
mMips->NOP2();
NOT_IMPLEMENTED();
}
-void ArmToMips64Assembler::SWPB(int cc, int Rn, int Rd, int Rm) {
+void ArmToMips64Assembler::SWPB(int cc __unused, int Rn __unused,
+ int Rd __unused, int Rm __unused) {
// *mPC++ = (cc<<28) | (2<<23) | (1<<22) | (Rn<<16) | (Rd << 12) | 0x90 | Rm;
mArmPC[mInum++] = pc();
mMips->NOP2();
NOT_IMPLEMENTED();
}
-void ArmToMips64Assembler::SWI(int cc, uint32_t comment) {
+void ArmToMips64Assembler::SWI(int cc __unused, uint32_t comment __unused) {
// *mPC++ = (cc<<28) | (0xF<<24) | comment;
mArmPC[mInum++] = pc();
mMips->NOP2();
@@ -1015,7 +1016,7 @@
#endif
// DSP instructions...
-void ArmToMips64Assembler::PLD(int Rn, uint32_t offset) {
+void ArmToMips64Assembler::PLD(int Rn __unused, uint32_t offset) {
LOG_ALWAYS_FATAL_IF(!((offset&(1<<24)) && !(offset&(1<<21))),
"PLD only P=1, W=0");
// *mPC++ = 0xF550F000 | (Rn<<16) | offset;
@@ -1024,13 +1025,14 @@
NOT_IMPLEMENTED();
}
-void ArmToMips64Assembler::CLZ(int cc, int Rd, int Rm)
+void ArmToMips64Assembler::CLZ(int cc __unused, int Rd, int Rm)
{
mArmPC[mInum++] = pc();
mMips->CLZ(Rd, Rm);
}
-void ArmToMips64Assembler::QADD(int cc, int Rd, int Rm, int Rn)
+void ArmToMips64Assembler::QADD(int cc __unused, int Rd __unused,
+ int Rm __unused, int Rn __unused)
{
// *mPC++ = (cc<<28) | 0x1000050 | (Rn<<16) | (Rd<<12) | Rm;
mArmPC[mInum++] = pc();
@@ -1038,7 +1040,8 @@
NOT_IMPLEMENTED();
}
-void ArmToMips64Assembler::QDADD(int cc, int Rd, int Rm, int Rn)
+void ArmToMips64Assembler::QDADD(int cc __unused, int Rd __unused,
+ int Rm __unused, int Rn __unused)
{
// *mPC++ = (cc<<28) | 0x1400050 | (Rn<<16) | (Rd<<12) | Rm;
mArmPC[mInum++] = pc();
@@ -1046,7 +1049,8 @@
NOT_IMPLEMENTED();
}
-void ArmToMips64Assembler::QSUB(int cc, int Rd, int Rm, int Rn)
+void ArmToMips64Assembler::QSUB(int cc __unused, int Rd __unused,
+ int Rm __unused, int Rn __unused)
{
// *mPC++ = (cc<<28) | 0x1200050 | (Rn<<16) | (Rd<<12) | Rm;
mArmPC[mInum++] = pc();
@@ -1054,7 +1058,8 @@
NOT_IMPLEMENTED();
}
-void ArmToMips64Assembler::QDSUB(int cc, int Rd, int Rm, int Rn)
+void ArmToMips64Assembler::QDSUB(int cc __unused, int Rd __unused,
+ int Rm __unused, int Rn __unused)
{
// *mPC++ = (cc<<28) | 0x1600050 | (Rn<<16) | (Rd<<12) | Rm;
mArmPC[mInum++] = pc();
@@ -1063,7 +1068,7 @@
}
// 16 x 16 signed multiply (like SMLAxx without the accumulate)
-void ArmToMips64Assembler::SMUL(int cc, int xy,
+void ArmToMips64Assembler::SMUL(int cc __unused, int xy,
int Rd, int Rm, int Rs)
{
mArmPC[mInum++] = pc();
@@ -1092,7 +1097,7 @@
}
// signed 32b x 16b multiple, save top 32-bits of 48-bit result
-void ArmToMips64Assembler::SMULW(int cc, int y,
+void ArmToMips64Assembler::SMULW(int cc __unused, int y,
int Rd, int Rm, int Rs)
{
mArmPC[mInum++] = pc();
@@ -1111,7 +1116,7 @@
}
// 16 x 16 signed multiply, accumulate: Rd = Rm{16} * Rs{16} + Rn
-void ArmToMips64Assembler::SMLA(int cc, int xy,
+void ArmToMips64Assembler::SMLA(int cc __unused, int xy,
int Rd, int Rm, int Rs, int Rn)
{
mArmPC[mInum++] = pc();
@@ -1141,8 +1146,9 @@
mMips->ADDU(Rd, R_at, Rn);
}
-void ArmToMips64Assembler::SMLAL(int cc, int xy,
- int RdHi, int RdLo, int Rs, int Rm)
+void ArmToMips64Assembler::SMLAL(int cc __unused, int xy __unused,
+ int RdHi __unused, int RdLo __unused,
+ int Rs __unused, int Rm __unused)
{
// *mPC++ = (cc<<28) | 0x1400080 | (RdHi<<16) | (RdLo<<12) | (Rs<<8) | (xy<<4) | Rm;
mArmPC[mInum++] = pc();
@@ -1150,8 +1156,9 @@
NOT_IMPLEMENTED();
}
-void ArmToMips64Assembler::SMLAW(int cc, int y,
- int Rd, int Rm, int Rs, int Rn)
+void ArmToMips64Assembler::SMLAW(int cc __unused, int y __unused,
+ int Rd __unused, int Rm __unused,
+ int Rs __unused, int Rn __unused)
{
// *mPC++ = (cc<<28) | 0x1200080 | (Rd<<16) | (Rn<<12) | (Rs<<8) | (y<<4) | Rm;
mArmPC[mInum++] = pc();
@@ -1160,7 +1167,7 @@
}
// used by ARMv6 version of GGLAssembler::filter32
-void ArmToMips64Assembler::UXTB16(int cc, int Rd, int Rm, int rotate)
+void ArmToMips64Assembler::UXTB16(int cc __unused, int Rd, int Rm, int rotate)
{
mArmPC[mInum++] = pc();
@@ -1173,7 +1180,8 @@
mMips->AND(Rd, R_at2, R_at);
}
-void ArmToMips64Assembler::UBFX(int cc, int Rd, int Rn, int lsb, int width)
+void ArmToMips64Assembler::UBFX(int cc __unused, int Rd __unused, int Rn __unused,
+ int lsb __unused, int width __unused)
{
/* Placeholder for UBFX */
mArmPC[mInum++] = pc();
@@ -1202,7 +1210,8 @@
dataProcessing(opSUB64, cc, s, Rd, Rn, Op2);
}
-void ArmToMips64Assembler::ADDR_LDR(int cc, int Rd, int Rn, uint32_t offset) {
+void ArmToMips64Assembler::ADDR_LDR(int cc __unused, int Rd,
+ int Rn, uint32_t offset) {
mArmPC[mInum++] = pc();
// work-around for ARM default address mode of immed12_pre(0)
if (offset > AMODE_UNSUPPORTED) offset = 0;
@@ -1235,7 +1244,8 @@
}
}
-void ArmToMips64Assembler::ADDR_STR(int cc, int Rd, int Rn, uint32_t offset) {
+void ArmToMips64Assembler::ADDR_STR(int cc __unused, int Rd,
+ int Rn, uint32_t offset) {
mArmPC[mInum++] = pc();
// work-around for ARM default address mode of immed12_pre(0)
if (offset > AMODE_UNSUPPORTED) offset = 0;
@@ -1290,14 +1300,12 @@
*/
MIPS64Assembler::MIPS64Assembler(const sp<Assembly>& assembly, ArmToMips64Assembler *parent)
- : mParent(parent),
- MIPSAssembler::MIPSAssembler(assembly, NULL)
+ : MIPSAssembler::MIPSAssembler(assembly, NULL), mParent(parent)
{
}
MIPS64Assembler::MIPS64Assembler(void* assembly, ArmToMips64Assembler *parent)
- : mParent(parent),
- MIPSAssembler::MIPSAssembler(assembly)
+ : MIPSAssembler::MIPSAssembler(assembly), mParent(parent)
{
}
@@ -1319,7 +1327,7 @@
}
-void MIPS64Assembler::disassemble(const char* name)
+void MIPS64Assembler::disassemble(const char* name __unused)
{
char di_buf[140];
@@ -1334,11 +1342,6 @@
}
}
- // iArm is an index to Arm instructions 1...n for this assembly sequence
- // mArmPC[iArm] holds the value of the Mips-PC for the first MIPS
- // instruction corresponding to that Arm instruction number
-
- int iArm = 0;
size_t count = pc()-base();
uint32_t* mipsPC = base();
diff --git a/libpixelflinger/codeflinger/MIPSAssembler.cpp b/libpixelflinger/codeflinger/MIPSAssembler.cpp
index 865a568..039a725 100644
--- a/libpixelflinger/codeflinger/MIPSAssembler.cpp
+++ b/libpixelflinger/codeflinger/MIPSAssembler.cpp
@@ -51,6 +51,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <inttypes.h>
#include <cutils/properties.h>
#include <log/log.h>
@@ -60,6 +61,8 @@
#include "MIPSAssembler.h"
#include "mips_disassem.h"
+#define __unused __attribute__((__unused__))
+
// Choose MIPS arch variant following gcc flags
#if defined(__mips__) && __mips==32 && __mips_isa_rev>=2
#define mips32r2 1
@@ -167,7 +170,7 @@
mMips->MOVE(R_v0, R_a0); // move context * passed in a0 to v0 (arm r0)
}
-void ArmToMipsAssembler::epilog(uint32_t touched)
+void ArmToMipsAssembler::epilog(uint32_t touched __unused)
{
mArmPC[mInum++] = pc(); // save starting PC for this instr
@@ -213,7 +216,7 @@
// shifters...
-bool ArmToMipsAssembler::isValidImmediate(uint32_t immediate)
+bool ArmToMipsAssembler::isValidImmediate(uint32_t immediate __unused)
{
// for MIPS, any 32-bit immediate is OK
return true;
@@ -234,13 +237,14 @@
return AMODE_REG_IMM;
}
-uint32_t ArmToMipsAssembler::reg_rrx(int Rm)
+uint32_t ArmToMipsAssembler::reg_rrx(int Rm __unused)
{
// reg_rrx mode is not used in the GLLAssember code at this time
return AMODE_UNSUPPORTED;
}
-uint32_t ArmToMipsAssembler::reg_reg(int Rm, int type, int Rs)
+uint32_t ArmToMipsAssembler::reg_reg(int Rm __unused, int type __unused,
+ int Rs __unused)
{
// reg_reg mode is not used in the GLLAssember code at this time
return AMODE_UNSUPPORTED;
@@ -281,14 +285,15 @@
return AMODE_REG_SCALE_PRE;
}
-uint32_t ArmToMipsAssembler::reg_scale_post(int Rm, int type, uint32_t shift)
+uint32_t ArmToMipsAssembler::reg_scale_post(int Rm __unused, int type __unused,
+ uint32_t shift __unused)
{
LOG_ALWAYS_FATAL("adr mode reg_scale_post not yet implemented\n");
return AMODE_UNSUPPORTED;
}
// LDRH/LDRSB/LDRSH/STRH (immediate and Rm can be negative, which indicate U=0)
-uint32_t ArmToMipsAssembler::immed8_pre(int32_t immed8, int W)
+uint32_t ArmToMipsAssembler::immed8_pre(int32_t immed8, int W __unused)
{
// uint32_t offset = abs(immed8);
@@ -318,7 +323,7 @@
return AMODE_REG_PRE;
}
-uint32_t ArmToMipsAssembler::reg_post(int Rm)
+uint32_t ArmToMipsAssembler::reg_post(int Rm __unused)
{
LOG_ALWAYS_FATAL("adr mode reg_post not yet implemented\n");
return AMODE_UNSUPPORTED;
@@ -333,12 +338,6 @@
#pragma mark Data Processing...
#endif
-
-static const char * const dpOpNames[] = {
- "AND", "EOR", "SUB", "RSB", "ADD", "ADC", "SBC", "RSC",
- "TST", "TEQ", "CMP", "CMN", "ORR", "MOV", "BIC", "MVN"
-};
-
// check if the operand registers from a previous CMP or S-bit instruction
// would be overwritten by this instruction. If so, move the value to a
// safe register.
@@ -605,7 +604,7 @@
#endif
// multiply, accumulate
-void ArmToMipsAssembler::MLA(int cc, int s,
+void ArmToMipsAssembler::MLA(int cc __unused, int s,
int Rd, int Rm, int Rs, int Rn) {
mArmPC[mInum++] = pc(); // save starting PC for this instr
@@ -618,7 +617,7 @@
}
}
-void ArmToMipsAssembler::MUL(int cc, int s,
+void ArmToMipsAssembler::MUL(int cc __unused, int s,
int Rd, int Rm, int Rs) {
mArmPC[mInum++] = pc();
mMips->MUL(Rd, Rm, Rs);
@@ -628,7 +627,7 @@
}
}
-void ArmToMipsAssembler::UMULL(int cc, int s,
+void ArmToMipsAssembler::UMULL(int cc __unused, int s,
int RdLo, int RdHi, int Rm, int Rs) {
mArmPC[mInum++] = pc();
mMips->MULT(Rm, Rs);
@@ -641,8 +640,8 @@
}
}
-void ArmToMipsAssembler::UMUAL(int cc, int s,
- int RdLo, int RdHi, int Rm, int Rs) {
+void ArmToMipsAssembler::UMUAL(int cc __unused, int s,
+ int RdLo __unused, int RdHi, int Rm __unused, int Rs __unused) {
LOG_FATAL_IF(RdLo==Rm || RdHi==Rm || RdLo==RdHi,
"UMUAL(r%u,r%u,r%u,r%u)", RdLo,RdHi,Rm,Rs);
// *mPC++ = (cc<<28) | (1<<23) | (1<<21) | (s<<20) |
@@ -657,8 +656,8 @@
}
}
-void ArmToMipsAssembler::SMULL(int cc, int s,
- int RdLo, int RdHi, int Rm, int Rs) {
+void ArmToMipsAssembler::SMULL(int cc __unused, int s,
+ int RdLo __unused, int RdHi, int Rm __unused, int Rs __unused) {
LOG_FATAL_IF(RdLo==Rm || RdHi==Rm || RdLo==RdHi,
"SMULL(r%u,r%u,r%u,r%u)", RdLo,RdHi,Rm,Rs);
// *mPC++ = (cc<<28) | (1<<23) | (1<<22) | (s<<20) |
@@ -672,8 +671,8 @@
LOG_ALWAYS_FATAL("Condition on SMULL must be on 64-bit result\n");
}
}
-void ArmToMipsAssembler::SMUAL(int cc, int s,
- int RdLo, int RdHi, int Rm, int Rs) {
+void ArmToMipsAssembler::SMUAL(int cc __unused, int s,
+ int RdLo __unused, int RdHi, int Rm __unused, int Rs __unused) {
LOG_FATAL_IF(RdLo==Rm || RdHi==Rm || RdLo==RdHi,
"SMUAL(r%u,r%u,r%u,r%u)", RdLo,RdHi,Rm,Rs);
// *mPC++ = (cc<<28) | (1<<23) | (1<<22) | (1<<21) | (s<<20) |
@@ -727,26 +726,26 @@
}
}
-void ArmToMipsAssembler::BL(int cc, const char* label)
+void ArmToMipsAssembler::BL(int cc __unused, const char* label __unused)
{
LOG_ALWAYS_FATAL("branch-and-link not supported yet\n");
mArmPC[mInum++] = pc();
}
// no use for Branches with integer PC, but they're in the Interface class ....
-void ArmToMipsAssembler::B(int cc, uint32_t* to_pc)
+void ArmToMipsAssembler::B(int cc __unused, uint32_t* to_pc __unused)
{
LOG_ALWAYS_FATAL("branch to absolute PC not supported, use Label\n");
mArmPC[mInum++] = pc();
}
-void ArmToMipsAssembler::BL(int cc, uint32_t* to_pc)
+void ArmToMipsAssembler::BL(int cc __unused, uint32_t* to_pc __unused)
{
LOG_ALWAYS_FATAL("branch to absolute PC not supported, use Label\n");
mArmPC[mInum++] = pc();
}
-void ArmToMipsAssembler::BX(int cc, int Rn)
+void ArmToMipsAssembler::BX(int cc __unused, int Rn __unused)
{
LOG_ALWAYS_FATAL("branch to absolute PC not supported, use Label\n");
mArmPC[mInum++] = pc();
@@ -760,7 +759,7 @@
#endif
// data transfer...
-void ArmToMipsAssembler::LDR(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMipsAssembler::LDR(int cc __unused, int Rd, int Rn, uint32_t offset)
{
mArmPC[mInum++] = pc();
// work-around for ARM default address mode of immed12_pre(0)
@@ -794,7 +793,7 @@
}
}
-void ArmToMipsAssembler::LDRB(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMipsAssembler::LDRB(int cc __unused, int Rd, int Rn, uint32_t offset)
{
mArmPC[mInum++] = pc();
// work-around for ARM default address mode of immed12_pre(0)
@@ -823,7 +822,7 @@
}
-void ArmToMipsAssembler::STR(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMipsAssembler::STR(int cc __unused, int Rd, int Rn, uint32_t offset)
{
mArmPC[mInum++] = pc();
// work-around for ARM default address mode of immed12_pre(0)
@@ -859,7 +858,7 @@
}
}
-void ArmToMipsAssembler::STRB(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMipsAssembler::STRB(int cc __unused, int Rd, int Rn, uint32_t offset)
{
mArmPC[mInum++] = pc();
// work-around for ARM default address mode of immed12_pre(0)
@@ -887,7 +886,7 @@
}
}
-void ArmToMipsAssembler::LDRH(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMipsAssembler::LDRH(int cc __unused, int Rd, int Rn, uint32_t offset)
{
mArmPC[mInum++] = pc();
// work-around for ARM default address mode of immed8_pre(0)
@@ -915,21 +914,23 @@
}
}
-void ArmToMipsAssembler::LDRSB(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMipsAssembler::LDRSB(int cc __unused, int Rd __unused,
+ int Rn __unused, uint32_t offset __unused)
{
mArmPC[mInum++] = pc();
mMips->NOP2();
NOT_IMPLEMENTED();
}
-void ArmToMipsAssembler::LDRSH(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMipsAssembler::LDRSH(int cc __unused, int Rd __unused,
+ int Rn __unused, uint32_t offset __unused)
{
mArmPC[mInum++] = pc();
mMips->NOP2();
NOT_IMPLEMENTED();
}
-void ArmToMipsAssembler::STRH(int cc, int Rd, int Rn, uint32_t offset)
+void ArmToMipsAssembler::STRH(int cc __unused, int Rd, int Rn, uint32_t offset)
{
mArmPC[mInum++] = pc();
// work-around for ARM default address mode of immed8_pre(0)
@@ -965,8 +966,8 @@
#endif
// block data transfer...
-void ArmToMipsAssembler::LDM(int cc, int dir,
- int Rn, int W, uint32_t reg_list)
+void ArmToMipsAssembler::LDM(int cc __unused, int dir __unused,
+ int Rn __unused, int W __unused, uint32_t reg_list __unused)
{ // ED FD EA FA IB IA DB DA
// const uint8_t P[8] = { 1, 0, 1, 0, 1, 0, 1, 0 };
// const uint8_t U[8] = { 1, 1, 0, 0, 1, 1, 0, 0 };
@@ -977,8 +978,8 @@
NOT_IMPLEMENTED();
}
-void ArmToMipsAssembler::STM(int cc, int dir,
- int Rn, int W, uint32_t reg_list)
+void ArmToMipsAssembler::STM(int cc __unused, int dir __unused,
+ int Rn __unused, int W __unused, uint32_t reg_list __unused)
{ // FA EA FD ED IB IA DB DA
// const uint8_t P[8] = { 0, 1, 0, 1, 1, 0, 1, 0 };
// const uint8_t U[8] = { 0, 0, 1, 1, 1, 1, 0, 0 };
@@ -997,21 +998,23 @@
#endif
// special...
-void ArmToMipsAssembler::SWP(int cc, int Rn, int Rd, int Rm) {
+void ArmToMipsAssembler::SWP(int cc __unused, int Rn __unused,
+ int Rd __unused, int Rm __unused) {
// *mPC++ = (cc<<28) | (2<<23) | (Rn<<16) | (Rd << 12) | 0x90 | Rm;
mArmPC[mInum++] = pc();
mMips->NOP2();
NOT_IMPLEMENTED();
}
-void ArmToMipsAssembler::SWPB(int cc, int Rn, int Rd, int Rm) {
+void ArmToMipsAssembler::SWPB(int cc __unused, int Rn __unused,
+ int Rd __unused, int Rm __unused) {
// *mPC++ = (cc<<28) | (2<<23) | (1<<22) | (Rn<<16) | (Rd << 12) | 0x90 | Rm;
mArmPC[mInum++] = pc();
mMips->NOP2();
NOT_IMPLEMENTED();
}
-void ArmToMipsAssembler::SWI(int cc, uint32_t comment) {
+void ArmToMipsAssembler::SWI(int cc __unused, uint32_t comment __unused) {
// *mPC++ = (cc<<28) | (0xF<<24) | comment;
mArmPC[mInum++] = pc();
mMips->NOP2();
@@ -1025,7 +1028,7 @@
#endif
// DSP instructions...
-void ArmToMipsAssembler::PLD(int Rn, uint32_t offset) {
+void ArmToMipsAssembler::PLD(int Rn __unused, uint32_t offset) {
LOG_ALWAYS_FATAL_IF(!((offset&(1<<24)) && !(offset&(1<<21))),
"PLD only P=1, W=0");
// *mPC++ = 0xF550F000 | (Rn<<16) | offset;
@@ -1034,13 +1037,14 @@
NOT_IMPLEMENTED();
}
-void ArmToMipsAssembler::CLZ(int cc, int Rd, int Rm)
+void ArmToMipsAssembler::CLZ(int cc __unused, int Rd, int Rm)
{
mArmPC[mInum++] = pc();
mMips->CLZ(Rd, Rm);
}
-void ArmToMipsAssembler::QADD(int cc, int Rd, int Rm, int Rn)
+void ArmToMipsAssembler::QADD(int cc __unused, int Rd __unused,
+ int Rm __unused, int Rn __unused)
{
// *mPC++ = (cc<<28) | 0x1000050 | (Rn<<16) | (Rd<<12) | Rm;
mArmPC[mInum++] = pc();
@@ -1048,7 +1052,8 @@
NOT_IMPLEMENTED();
}
-void ArmToMipsAssembler::QDADD(int cc, int Rd, int Rm, int Rn)
+void ArmToMipsAssembler::QDADD(int cc __unused, int Rd __unused,
+ int Rm __unused, int Rn __unused)
{
// *mPC++ = (cc<<28) | 0x1400050 | (Rn<<16) | (Rd<<12) | Rm;
mArmPC[mInum++] = pc();
@@ -1056,7 +1061,8 @@
NOT_IMPLEMENTED();
}
-void ArmToMipsAssembler::QSUB(int cc, int Rd, int Rm, int Rn)
+void ArmToMipsAssembler::QSUB(int cc __unused, int Rd __unused,
+ int Rm __unused, int Rn __unused)
{
// *mPC++ = (cc<<28) | 0x1200050 | (Rn<<16) | (Rd<<12) | Rm;
mArmPC[mInum++] = pc();
@@ -1064,7 +1070,8 @@
NOT_IMPLEMENTED();
}
-void ArmToMipsAssembler::QDSUB(int cc, int Rd, int Rm, int Rn)
+void ArmToMipsAssembler::QDSUB(int cc __unused, int Rd __unused,
+ int Rm __unused, int Rn __unused)
{
// *mPC++ = (cc<<28) | 0x1600050 | (Rn<<16) | (Rd<<12) | Rm;
mArmPC[mInum++] = pc();
@@ -1073,7 +1080,7 @@
}
// 16 x 16 signed multiply (like SMLAxx without the accumulate)
-void ArmToMipsAssembler::SMUL(int cc, int xy,
+void ArmToMipsAssembler::SMUL(int cc __unused, int xy,
int Rd, int Rm, int Rs)
{
mArmPC[mInum++] = pc();
@@ -1112,7 +1119,7 @@
}
// signed 32b x 16b multiple, save top 32-bits of 48-bit result
-void ArmToMipsAssembler::SMULW(int cc, int y,
+void ArmToMipsAssembler::SMULW(int cc __unused, int y,
int Rd, int Rm, int Rs)
{
mArmPC[mInum++] = pc();
@@ -1132,7 +1139,7 @@
}
// 16 x 16 signed multiply, accumulate: Rd = Rm{16} * Rs{16} + Rn
-void ArmToMipsAssembler::SMLA(int cc, int xy,
+void ArmToMipsAssembler::SMLA(int cc __unused, int xy,
int Rd, int Rm, int Rs, int Rn)
{
mArmPC[mInum++] = pc();
@@ -1172,8 +1179,9 @@
mMips->ADDU(Rd, R_at, Rn);
}
-void ArmToMipsAssembler::SMLAL(int cc, int xy,
- int RdHi, int RdLo, int Rs, int Rm)
+void ArmToMipsAssembler::SMLAL(int cc __unused, int xy __unused,
+ int RdHi __unused, int RdLo __unused,
+ int Rs __unused, int Rm __unused)
{
// *mPC++ = (cc<<28) | 0x1400080 | (RdHi<<16) | (RdLo<<12) | (Rs<<8) | (xy<<4) | Rm;
mArmPC[mInum++] = pc();
@@ -1181,8 +1189,9 @@
NOT_IMPLEMENTED();
}
-void ArmToMipsAssembler::SMLAW(int cc, int y,
- int Rd, int Rm, int Rs, int Rn)
+void ArmToMipsAssembler::SMLAW(int cc __unused, int y __unused,
+ int Rd __unused, int Rm __unused,
+ int Rs __unused, int Rn __unused)
{
// *mPC++ = (cc<<28) | 0x1200080 | (Rd<<16) | (Rn<<12) | (Rs<<8) | (y<<4) | Rm;
mArmPC[mInum++] = pc();
@@ -1191,7 +1200,7 @@
}
// used by ARMv6 version of GGLAssembler::filter32
-void ArmToMipsAssembler::UXTB16(int cc, int Rd, int Rm, int rotate)
+void ArmToMipsAssembler::UXTB16(int cc __unused, int Rd, int Rm, int rotate)
{
mArmPC[mInum++] = pc();
@@ -1202,7 +1211,9 @@
mMips->AND(Rd, Rm, 0x00FF00FF);
}
-void ArmToMipsAssembler::UBFX(int cc, int Rd, int Rn, int lsb, int width)
+void ArmToMipsAssembler::UBFX(int cc __unused, int Rd __unused,
+ int Rn __unused, int lsb __unused,
+ int width __unused)
{
/* Placeholder for UBFX */
mArmPC[mInum++] = pc();
@@ -1339,11 +1350,6 @@
}
}
- // iArm is an index to Arm instructions 1...n for this assembly sequence
- // mArmPC[iArm] holds the value of the Mips-PC for the first MIPS
- // instruction corresponding to that Arm instruction number
-
- int iArm = 0;
size_t count = pc()-base();
uint32_t* mipsPC = base();
while (count--) {
@@ -1359,7 +1365,7 @@
::mips_disassem(mipsPC, di_buf, arm_disasm_fmt);
string_detab(di_buf);
string_pad(di_buf, 30);
- ALOGW("%08x: %08x %s", uintptr_t(mipsPC), uint32_t(*mipsPC), di_buf);
+ ALOGW("0x%p: %08x %s", mipsPC, uint32_t(*mipsPC), di_buf);
mipsPC++;
}
}
@@ -1381,7 +1387,7 @@
// empty - done in ArmToMipsAssembler
}
-void MIPSAssembler::epilog(uint32_t touched)
+void MIPSAssembler::epilog(uint32_t touched __unused)
{
// empty - done in ArmToMipsAssembler
}
@@ -1403,7 +1409,7 @@
// the instruction & data caches are flushed by CodeCache
const int64_t duration = ggl_system_time() - mDuration;
- const char * const format = "generated %s (%d ins) at [%p:%p] in %lld ns\n";
+ const char * const format = "generated %s (%d ins) at [%p:%p] in %" PRId64 " ns\n";
ALOGI(format, name, int(pc()-base()), base(), pc(), duration);
char value[PROPERTY_VALUE_MAX];
@@ -1864,7 +1870,7 @@
BEQ(Rs, R_zero, label);
}
-void MIPSAssembler::BNEZ(int Rs, const char* label)
+void MIPSAssembler::BNEZ(int Rs __unused, const char* label)
{
BNE(R_at, R_zero, label);
}
diff --git a/libpixelflinger/codeflinger/mips64_disassem.c b/libpixelflinger/codeflinger/mips64_disassem.c
index 1856e5c..8528299 100644
--- a/libpixelflinger/codeflinger/mips64_disassem.c
+++ b/libpixelflinger/codeflinger/mips64_disassem.c
@@ -45,6 +45,8 @@
#include "mips_opcode.h"
+#define __unused __attribute__((__unused__))
+
static char *sprintf_buffer;
static int sprintf_buf_len;
@@ -114,7 +116,7 @@
"t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
};
-static char ** reg_name = &mips_reg_name[0];
+static char * const * reg_name = &mips_reg_name[0];
static const char * const c0_opname[64] = {
"c0op00","tlbr", "tlbwi", "c0op03","c0op04","c0op05","tlbwr", "c0op07",
@@ -147,7 +149,7 @@
* 'loc' may in fact contain a breakpoint instruction.
*/
static db_addr_t
-db_disasm_insn(int insn, db_addr_t loc, bool altfmt)
+db_disasm_insn(int insn, db_addr_t loc, bool altfmt __unused)
{
bool bdslot = false;
InstFmt i;
diff --git a/libpixelflinger/codeflinger/mips_disassem.c b/libpixelflinger/codeflinger/mips_disassem.c
index 83a9740..1fe6806 100644
--- a/libpixelflinger/codeflinger/mips_disassem.c
+++ b/libpixelflinger/codeflinger/mips_disassem.c
@@ -57,6 +57,7 @@
// #include <ddb/db_extern.h>
// #include <ddb/db_sym.h>
+#define __unused __attribute__((__unused__))
static char *sprintf_buffer;
static int sprintf_buf_len;
@@ -183,7 +184,7 @@
* 'loc' may in fact contain a breakpoint instruction.
*/
static db_addr_t
-db_disasm_insn(int insn, db_addr_t loc, bool altfmt)
+db_disasm_insn(int insn, db_addr_t loc, bool altfmt __unused)
{
bool bdslot = false;
InstFmt i;
diff --git a/libqtaguid/Android.bp b/libqtaguid/Android.bp
new file mode 100644
index 0000000..de632ca
--- /dev/null
+++ b/libqtaguid/Android.bp
@@ -0,0 +1,56 @@
+//
+// Copyright (C) 2017 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.
+//
+
+cc_library_headers {
+ name: "libqtaguid_headers",
+ vendor_available: false,
+ host_supported: false,
+ export_include_dirs: ["include"],
+ target: {
+ linux_bionic: {
+ enabled: true,
+ },
+ },
+}
+
+cc_library {
+ name: "libqtaguid",
+ vendor_available: false,
+ host_supported: false,
+ target: {
+ android: {
+ srcs: [
+ "qtaguid.c",
+ ],
+ sanitize: {
+ misc_undefined: ["integer"],
+ },
+ },
+ },
+
+ shared_libs: ["liblog"],
+ header_libs: [
+ "libqtaguid_headers",
+ ],
+ export_header_lib_headers: ["libqtaguid_headers"],
+ local_include_dirs: ["include"],
+
+ cflags: [
+ "-Werror",
+ "-Wall",
+ "-Wextra",
+ ],
+}
diff --git a/libqtaguid/include/qtaguid/qtaguid.h b/libqtaguid/include/qtaguid/qtaguid.h
new file mode 100644
index 0000000..72285e5
--- /dev/null
+++ b/libqtaguid/include/qtaguid/qtaguid.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2011 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 __LEGACY_QTAGUID_H
+#define __LEGACY_QTAGUID_H
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Set tags (and owning UIDs) for network sockets. The socket must be untagged
+ * by calling qtaguid_untagSocket() before closing it, otherwise the qtaguid
+ * module will keep a reference to it even after close.
+ */
+extern int legacy_tagSocket(int sockfd, int tag, uid_t uid);
+
+/*
+ * Untag a network socket before closing.
+ */
+extern int legacy_untagSocket(int sockfd);
+
+/*
+ * For the given uid, switch counter sets.
+ * The kernel only keeps a limited number of sets.
+ * 2 for now.
+ */
+extern int legacy_setCounterSet(int counterSetNum, uid_t uid);
+
+/*
+ * Delete all tag info that relates to the given tag an uid.
+ * If the tag is 0, then ALL info about the uid is freeded.
+ * The delete data also affects active tagged socketd, which are
+ * then untagged.
+ * The calling process can only operate on its own tags.
+ * Unless it is part of the happy AID_NET_BW_ACCT group.
+ * In which case it can clobber everything.
+ */
+extern int legacy_deleteTagData(int tag, uid_t uid);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LEGACY_QTAGUID_H */
diff --git a/libcutils/qtaguid.c b/libqtaguid/qtaguid.c
similarity index 72%
rename from libcutils/qtaguid.c
rename to libqtaguid/qtaguid.c
index 22b8325..cd38bad 100644
--- a/libcutils/qtaguid.c
+++ b/libqtaguid/qtaguid.c
@@ -27,12 +27,10 @@
#include <unistd.h>
#include <log/log.h>
-#include <cutils/qtaguid.h>
+#include <qtaguid/qtaguid.h>
static const char* CTRL_PROCPATH = "/proc/net/xt_qtaguid/ctrl";
static const int CTRL_MAX_INPUT_LEN = 128;
-static const char *GLOBAL_PACIFIER_PARAM = "/sys/module/xt_qtaguid/parameters/passive";
-static const char *TAG_PACIFIER_PARAM = "/sys/module/xt_qtaguid/parameters/tag_tracking_passive";
/*
* One per proccess.
@@ -46,7 +44,7 @@
pthread_once_t resTrackInitDone = PTHREAD_ONCE_INIT;
/* Only call once per process. */
-void qtaguid_resTrack(void) {
+void legacy_resTrack(void) {
resTrackFd = TEMP_FAILURE_RETRY(open("/dev/xt_qtaguid", O_RDONLY | O_CLOEXEC));
}
@@ -55,7 +53,7 @@
* 0 on success.
* -errno on failure.
*/
-static int write_ctrl(const char *cmd) {
+static int write_ctrl(const char* cmd) {
int fd, res, savedErrno;
ALOGV("write_ctrl(%s)", cmd);
@@ -79,28 +77,12 @@
return -savedErrno;
}
-static int write_param(const char *param_path, const char *value) {
- int param_fd;
- int res;
-
- param_fd = TEMP_FAILURE_RETRY(open(param_path, O_WRONLY | O_CLOEXEC));
- if (param_fd < 0) {
- return -errno;
- }
- res = TEMP_FAILURE_RETRY(write(param_fd, value, strlen(value)));
- if (res < 0) {
- return -errno;
- }
- close(param_fd);
- return 0;
-}
-
-int qtaguid_tagSocket(int sockfd, int tag, uid_t uid) {
+int legacy_tagSocket(int sockfd, int tag, uid_t uid) {
char lineBuf[CTRL_MAX_INPUT_LEN];
int res;
uint64_t kTag = ((uint64_t)tag << 32);
- pthread_once(&resTrackInitDone, qtaguid_resTrack);
+ pthread_once(&resTrackInitDone, legacy_resTrack);
snprintf(lineBuf, sizeof(lineBuf), "t %d %" PRIu64 " %d", sockfd, kTag, uid);
@@ -108,14 +90,14 @@
res = write_ctrl(lineBuf);
if (res < 0) {
- ALOGI("Tagging socket %d with tag %" PRIx64 "(%d) for uid %d failed errno=%d",
- sockfd, kTag, tag, uid, res);
+ ALOGI("Tagging socket %d with tag %" PRIx64 "(%d) for uid %d failed errno=%d", sockfd, kTag,
+ tag, uid, res);
}
return res;
}
-int qtaguid_untagSocket(int sockfd) {
+int legacy_untagSocket(int sockfd) {
char lineBuf[CTRL_MAX_INPUT_LEN];
int res;
@@ -130,7 +112,7 @@
return res;
}
-int qtaguid_setCounterSet(int counterSetNum, uid_t uid) {
+int legacy_setCounterSet(int counterSetNum, uid_t uid) {
char lineBuf[CTRL_MAX_INPUT_LEN];
int res;
@@ -141,34 +123,21 @@
return res;
}
-int qtaguid_deleteTagData(int tag, uid_t uid) {
+int legacy_deleteTagData(int tag, uid_t uid) {
char lineBuf[CTRL_MAX_INPUT_LEN];
int cnt = 0, res = 0;
uint64_t kTag = (uint64_t)tag << 32;
ALOGV("Deleting tag data with tag %" PRIx64 "{%d,0} for uid %d", kTag, tag, uid);
- pthread_once(&resTrackInitDone, qtaguid_resTrack);
+ pthread_once(&resTrackInitDone, legacy_resTrack);
snprintf(lineBuf, sizeof(lineBuf), "d %" PRIu64 " %d", kTag, uid);
res = write_ctrl(lineBuf);
if (res < 0) {
ALOGI("Deleting tag data with tag %" PRIx64 "/%d for uid %d failed with cnt=%d errno=%d",
- kTag, tag, uid, cnt, errno);
+ kTag, tag, uid, cnt, errno);
}
return res;
}
-
-int qtaguid_setPacifier(int on) {
- const char *value;
-
- value = on ? "Y" : "N";
- if (write_param(GLOBAL_PACIFIER_PARAM, value) < 0) {
- return -errno;
- }
- if (write_param(TAG_PACIFIER_PARAM, value) < 0) {
- return -errno;
- }
- return 0;
-}
diff --git a/libunwindstack/Android.bp b/libunwindstack/Android.bp
index c885c3f..40364fe 100644
--- a/libunwindstack/Android.bp
+++ b/libunwindstack/Android.bp
@@ -48,8 +48,7 @@
srcs: [
"ArmExidx.cpp",
"DwarfCfa.cpp",
- "DwarfDebugFrame.cpp",
- "DwarfEhFrame.cpp",
+ "DwarfEhFrameWithHdr.cpp",
"DwarfMemory.cpp",
"DwarfOp.cpp",
"DwarfSection.cpp",
@@ -106,6 +105,7 @@
"tests/DwarfCfaTest.cpp",
"tests/DwarfDebugFrameTest.cpp",
"tests/DwarfEhFrameTest.cpp",
+ "tests/DwarfEhFrameWithHdrTest.cpp",
"tests/DwarfMemoryTest.cpp",
"tests/DwarfOpLogTest.cpp",
"tests/DwarfOpTest.cpp",
diff --git a/libunwindstack/DwarfDebugFrame.cpp b/libunwindstack/DwarfDebugFrame.cpp
deleted file mode 100644
index 5707596..0000000
--- a/libunwindstack/DwarfDebugFrame.cpp
+++ /dev/null
@@ -1,316 +0,0 @@
-/*
- * Copyright (C) 2017 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 <stdint.h>
-#include <stdlib.h>
-
-#include <algorithm>
-
-#include <unwindstack/DwarfStructs.h>
-#include <unwindstack/Memory.h>
-
-#include "DwarfDebugFrame.h"
-#include "DwarfEncoding.h"
-#include "DwarfError.h"
-
-namespace unwindstack {
-
-template <typename AddressType>
-bool DwarfDebugFrame<AddressType>::Init(uint64_t offset, uint64_t size) {
- offset_ = offset;
- end_offset_ = offset + size;
-
- memory_.clear_func_offset();
- memory_.clear_text_offset();
- memory_.set_data_offset(offset);
- memory_.set_cur_offset(offset);
-
- return CreateSortedFdeList();
-}
-
-template <typename AddressType>
-bool DwarfDebugFrame<AddressType>::GetCieInfo(uint8_t* segment_size, uint8_t* encoding) {
- uint8_t version;
- if (!memory_.ReadBytes(&version, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
- // Read the augmentation string.
- std::vector<char> aug_string;
- char aug_value;
- bool get_encoding = false;
- do {
- if (!memory_.ReadBytes(&aug_value, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
- if (aug_value == 'R') {
- get_encoding = true;
- }
- aug_string.push_back(aug_value);
- } while (aug_value != '\0');
-
- if (version == 4) {
- // Skip the Address Size field.
- memory_.set_cur_offset(memory_.cur_offset() + 1);
-
- // Read the segment size.
- if (!memory_.ReadBytes(segment_size, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
- } else {
- *segment_size = 0;
- }
-
- if (aug_string[0] != 'z' || !get_encoding) {
- // No encoding
- return true;
- }
-
- // Skip code alignment factor
- uint8_t value;
- do {
- if (!memory_.ReadBytes(&value, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
- } while (value & 0x80);
-
- // Skip data alignment factor
- do {
- if (!memory_.ReadBytes(&value, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
- } while (value & 0x80);
-
- if (version == 1) {
- // Skip return address register.
- memory_.set_cur_offset(memory_.cur_offset() + 1);
- } else {
- // Skip return address register.
- do {
- if (!memory_.ReadBytes(&value, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
- } while (value & 0x80);
- }
-
- // Skip the augmentation length.
- do {
- if (!memory_.ReadBytes(&value, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
- } while (value & 0x80);
-
- for (size_t i = 1; i < aug_string.size(); i++) {
- if (aug_string[i] == 'R') {
- if (!memory_.ReadBytes(encoding, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
- // Got the encoding, that's all we are looking for.
- return true;
- } else if (aug_string[i] == 'L') {
- memory_.set_cur_offset(memory_.cur_offset() + 1);
- } else if (aug_string[i] == 'P') {
- uint8_t encoding;
- if (!memory_.ReadBytes(&encoding, 1)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
- uint64_t value;
- if (!memory_.template ReadEncodedValue<AddressType>(encoding, &value)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
- }
- }
-
- // It should be impossible to get here.
- abort();
-}
-
-template <typename AddressType>
-bool DwarfDebugFrame<AddressType>::AddFdeInfo(uint64_t entry_offset, uint8_t segment_size,
- uint8_t encoding) {
- if (segment_size != 0) {
- memory_.set_cur_offset(memory_.cur_offset() + 1);
- }
-
- uint64_t start;
- if (!memory_.template ReadEncodedValue<AddressType>(encoding & 0xf, &start)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
-
- uint64_t length;
- if (!memory_.template ReadEncodedValue<AddressType>(encoding & 0xf, &length)) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
- if (length != 0) {
- fdes_.emplace_back(entry_offset, start, length);
- }
-
- return true;
-}
-
-template <typename AddressType>
-bool DwarfDebugFrame<AddressType>::CreateSortedFdeList() {
- memory_.set_cur_offset(offset_);
-
- // Loop through all of the entries and read just enough to create
- // a sorted list of pcs.
- // This code assumes that first comes the cie, then the fdes that
- // it applies to.
- uint64_t cie_offset = 0;
- uint8_t address_encoding;
- uint8_t segment_size;
- while (memory_.cur_offset() < end_offset_) {
- uint64_t cur_entry_offset = memory_.cur_offset();
-
- // Figure out the entry length and type.
- uint32_t value32;
- if (!memory_.ReadBytes(&value32, sizeof(value32))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
-
- uint64_t next_entry_offset;
- if (value32 == static_cast<uint32_t>(-1)) {
- uint64_t value64;
- if (!memory_.ReadBytes(&value64, sizeof(value64))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
- next_entry_offset = memory_.cur_offset() + value64;
-
- // Read the Cie Id of a Cie or the pointer of the Fde.
- if (!memory_.ReadBytes(&value64, sizeof(value64))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
-
- if (value64 == static_cast<uint64_t>(-1)) {
- // Cie 64 bit
- address_encoding = DW_EH_PE_sdata8;
- if (!GetCieInfo(&segment_size, &address_encoding)) {
- return false;
- }
- cie_offset = cur_entry_offset;
- } else {
- if (offset_ + value64 != cie_offset) {
- // This means that this Fde is not following the Cie.
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
- return false;
- }
-
- // Fde 64 bit
- if (!AddFdeInfo(cur_entry_offset, segment_size, address_encoding)) {
- return false;
- }
- }
- } else {
- next_entry_offset = memory_.cur_offset() + value32;
-
- // Read the Cie Id of a Cie or the pointer of the Fde.
- if (!memory_.ReadBytes(&value32, sizeof(value32))) {
- last_error_ = DWARF_ERROR_MEMORY_INVALID;
- return false;
- }
-
- if (value32 == static_cast<uint32_t>(-1)) {
- // Cie 32 bit
- address_encoding = DW_EH_PE_sdata4;
- if (!GetCieInfo(&segment_size, &address_encoding)) {
- return false;
- }
- cie_offset = cur_entry_offset;
- } else {
- if (offset_ + value32 != cie_offset) {
- // This means that this Fde is not following the Cie.
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
- return false;
- }
-
- // Fde 32 bit
- if (!AddFdeInfo(cur_entry_offset, segment_size, address_encoding)) {
- return false;
- }
- }
- }
-
- if (next_entry_offset < memory_.cur_offset()) {
- // This indicates some kind of corruption, or malformed section data.
- last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
- return false;
- }
- memory_.set_cur_offset(next_entry_offset);
- }
-
- // Sort the entries.
- std::sort(fdes_.begin(), fdes_.end(), [](const FdeInfo& a, const FdeInfo& b) {
- if (a.start == b.start) return a.end < b.end;
- return a.start < b.start;
- });
-
- fde_count_ = fdes_.size();
-
- return true;
-}
-
-template <typename AddressType>
-bool DwarfDebugFrame<AddressType>::GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset) {
- if (fde_count_ == 0) {
- return false;
- }
-
- size_t first = 0;
- size_t last = fde_count_;
- while (first < last) {
- size_t current = (first + last) / 2;
- const FdeInfo* info = &fdes_[current];
- if (pc >= info->start && pc <= info->end) {
- *fde_offset = info->offset;
- return true;
- }
-
- if (pc < info->start) {
- last = current;
- } else {
- first = current + 1;
- }
- }
- return false;
-}
-
-template <typename AddressType>
-const DwarfFde* DwarfDebugFrame<AddressType>::GetFdeFromIndex(size_t index) {
- if (index >= fdes_.size()) {
- return nullptr;
- }
- return this->GetFdeFromOffset(fdes_[index].offset);
-}
-
-// Explicitly instantiate DwarfDebugFrame.
-template class DwarfDebugFrame<uint32_t>;
-template class DwarfDebugFrame<uint64_t>;
-
-} // namespace unwindstack
diff --git a/libunwindstack/DwarfDebugFrame.h b/libunwindstack/DwarfDebugFrame.h
index 6a6178e..635cefd 100644
--- a/libunwindstack/DwarfDebugFrame.h
+++ b/libunwindstack/DwarfDebugFrame.h
@@ -28,51 +28,21 @@
template <typename AddressType>
class DwarfDebugFrame : public DwarfSectionImpl<AddressType> {
public:
- // Add these so that the protected members of DwarfSectionImpl
- // can be accessed without needing a this->.
- using DwarfSectionImpl<AddressType>::memory_;
- using DwarfSectionImpl<AddressType>::fde_count_;
- using DwarfSectionImpl<AddressType>::last_error_;
-
- struct FdeInfo {
- FdeInfo(uint64_t offset, uint64_t start, uint64_t length)
- : offset(offset), start(start), end(start + length) {}
-
- uint64_t offset;
- AddressType start;
- AddressType end;
- };
-
- DwarfDebugFrame(Memory* memory) : DwarfSectionImpl<AddressType>(memory) {}
+ DwarfDebugFrame(Memory* memory) : DwarfSectionImpl<AddressType>(memory) {
+ this->cie32_value_ = static_cast<uint32_t>(-1);
+ this->cie64_value_ = static_cast<uint64_t>(-1);
+ }
virtual ~DwarfDebugFrame() = default;
- bool Init(uint64_t offset, uint64_t size) override;
+ uint64_t GetCieOffsetFromFde32(uint32_t pointer) override {
+ return this->entries_offset_ + pointer;
+ }
- bool GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset) override;
-
- const DwarfFde* GetFdeFromIndex(size_t index) override;
-
- bool IsCie32(uint32_t value32) override { return value32 == static_cast<uint32_t>(-1); }
-
- bool IsCie64(uint64_t value64) override { return value64 == static_cast<uint64_t>(-1); }
-
- uint64_t GetCieOffsetFromFde32(uint32_t pointer) override { return offset_ + pointer; }
-
- uint64_t GetCieOffsetFromFde64(uint64_t pointer) override { return offset_ + pointer; }
+ uint64_t GetCieOffsetFromFde64(uint64_t pointer) override {
+ return this->entries_offset_ + pointer;
+ }
uint64_t AdjustPcFromFde(uint64_t pc) override { return pc; }
-
- bool GetCieInfo(uint8_t* segment_size, uint8_t* encoding);
-
- bool AddFdeInfo(uint64_t entry_offset, uint8_t segment_size, uint8_t encoding);
-
- bool CreateSortedFdeList();
-
- protected:
- uint64_t offset_;
- uint64_t end_offset_;
-
- std::vector<FdeInfo> fdes_;
};
} // namespace unwindstack
diff --git a/libunwindstack/DwarfEhFrame.h b/libunwindstack/DwarfEhFrame.h
index 4207b42..561d23a 100644
--- a/libunwindstack/DwarfEhFrame.h
+++ b/libunwindstack/DwarfEhFrame.h
@@ -20,74 +20,30 @@
#include <stdint.h>
#include <unwindstack/DwarfSection.h>
+#include <unwindstack/Memory.h>
namespace unwindstack {
-// Forward declarations.
-class Memory;
-
template <typename AddressType>
class DwarfEhFrame : public DwarfSectionImpl<AddressType> {
public:
- // Add these so that the protected members of DwarfSectionImpl
- // can be accessed without needing a this->.
- using DwarfSectionImpl<AddressType>::memory_;
- using DwarfSectionImpl<AddressType>::fde_count_;
- using DwarfSectionImpl<AddressType>::last_error_;
-
- struct FdeInfo {
- AddressType pc;
- uint64_t offset;
- };
-
DwarfEhFrame(Memory* memory) : DwarfSectionImpl<AddressType>(memory) {}
virtual ~DwarfEhFrame() = default;
- bool Init(uint64_t offset, uint64_t size) override;
-
- bool GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset) override;
-
- const DwarfFde* GetFdeFromIndex(size_t index) override;
-
- bool IsCie32(uint32_t value32) override { return value32 == 0; }
-
- bool IsCie64(uint64_t value64) override { return value64 == 0; }
-
uint64_t GetCieOffsetFromFde32(uint32_t pointer) override {
- return memory_.cur_offset() - pointer - 4;
+ return this->memory_.cur_offset() - pointer - 4;
}
uint64_t GetCieOffsetFromFde64(uint64_t pointer) override {
- return memory_.cur_offset() - pointer - 8;
+ return this->memory_.cur_offset() - pointer - 8;
}
uint64_t AdjustPcFromFde(uint64_t pc) override {
// The eh_frame uses relative pcs.
- return pc + memory_.cur_offset();
+ return pc + this->memory_.cur_offset();
}
-
- const FdeInfo* GetFdeInfoFromIndex(size_t index);
-
- bool GetFdeOffsetSequential(uint64_t pc, uint64_t* fde_offset);
-
- bool GetFdeOffsetBinary(uint64_t pc, uint64_t* fde_offset, uint64_t total_entries);
-
- protected:
- uint8_t version_;
- uint8_t ptr_encoding_;
- uint8_t table_encoding_;
- size_t table_entry_size_;
-
- uint64_t ptr_offset_;
-
- uint64_t entries_offset_;
- uint64_t entries_end_;
- uint64_t entries_data_offset_;
- uint64_t cur_entries_offset_ = 0;
-
- std::unordered_map<uint64_t, FdeInfo> fde_info_;
};
} // namespace unwindstack
-#endif // _LIBUNWINDSTACK_DWARF_EH_FRAME_H
+#endif // _LIBUNWINDSTACK_DWARF_EH_FRAME_WITH_HDR_H
diff --git a/libunwindstack/DwarfEhFrame.cpp b/libunwindstack/DwarfEhFrameWithHdr.cpp
similarity index 85%
rename from libunwindstack/DwarfEhFrame.cpp
rename to libunwindstack/DwarfEhFrameWithHdr.cpp
index db8f558..0337dba 100644
--- a/libunwindstack/DwarfEhFrame.cpp
+++ b/libunwindstack/DwarfEhFrameWithHdr.cpp
@@ -20,13 +20,13 @@
#include <unwindstack/Memory.h>
#include "Check.h"
-#include "DwarfEhFrame.h"
+#include "DwarfEhFrameWithHdr.h"
#include "DwarfError.h"
namespace unwindstack {
template <typename AddressType>
-bool DwarfEhFrame<AddressType>::Init(uint64_t offset, uint64_t size) {
+bool DwarfEhFrameWithHdr<AddressType>::Init(uint64_t offset, uint64_t size) {
uint8_t data[4];
memory_.clear_func_offset();
@@ -73,7 +73,7 @@
}
template <typename AddressType>
-const DwarfFde* DwarfEhFrame<AddressType>::GetFdeFromIndex(size_t index) {
+const DwarfFde* DwarfEhFrameWithHdr<AddressType>::GetFdeFromIndex(size_t index) {
const FdeInfo* info = GetFdeInfoFromIndex(index);
if (info == nullptr) {
return nullptr;
@@ -82,8 +82,8 @@
}
template <typename AddressType>
-const typename DwarfEhFrame<AddressType>::FdeInfo* DwarfEhFrame<AddressType>::GetFdeInfoFromIndex(
- size_t index) {
+const typename DwarfEhFrameWithHdr<AddressType>::FdeInfo*
+DwarfEhFrameWithHdr<AddressType>::GetFdeInfoFromIndex(size_t index) {
auto entry = fde_info_.find(index);
if (entry != fde_info_.end()) {
return &fde_info_[index];
@@ -105,8 +105,8 @@
}
template <typename AddressType>
-bool DwarfEhFrame<AddressType>::GetFdeOffsetBinary(uint64_t pc, uint64_t* fde_offset,
- uint64_t total_entries) {
+bool DwarfEhFrameWithHdr<AddressType>::GetFdeOffsetBinary(uint64_t pc, uint64_t* fde_offset,
+ uint64_t total_entries) {
CHECK(fde_count_ > 0);
CHECK(total_entries <= fde_count_);
@@ -115,6 +115,9 @@
while (first < last) {
size_t current = (first + last) / 2;
const FdeInfo* info = GetFdeInfoFromIndex(current);
+ if (info == nullptr) {
+ return false;
+ }
if (pc == info->pc) {
*fde_offset = info->offset;
return true;
@@ -127,6 +130,9 @@
}
if (last != 0) {
const FdeInfo* info = GetFdeInfoFromIndex(last - 1);
+ if (info == nullptr) {
+ return false;
+ }
*fde_offset = info->offset;
return true;
}
@@ -134,7 +140,7 @@
}
template <typename AddressType>
-bool DwarfEhFrame<AddressType>::GetFdeOffsetSequential(uint64_t pc, uint64_t* fde_offset) {
+bool DwarfEhFrameWithHdr<AddressType>::GetFdeOffsetSequential(uint64_t pc, uint64_t* fde_offset) {
CHECK(fde_count_ != 0);
last_error_ = DWARF_ERROR_NONE;
// We can do a binary search if the pc is in the range of the elements
@@ -196,7 +202,7 @@
}
template <typename AddressType>
-bool DwarfEhFrame<AddressType>::GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset) {
+bool DwarfEhFrameWithHdr<AddressType>::GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset) {
if (fde_count_ == 0) {
return false;
}
@@ -210,8 +216,8 @@
}
}
-// Explicitly instantiate DwarfEhFrame.
-template class DwarfEhFrame<uint32_t>;
-template class DwarfEhFrame<uint64_t>;
+// Explicitly instantiate DwarfEhFrameWithHdr
+template class DwarfEhFrameWithHdr<uint32_t>;
+template class DwarfEhFrameWithHdr<uint64_t>;
} // namespace unwindstack
diff --git a/libunwindstack/DwarfEhFrameWithHdr.h b/libunwindstack/DwarfEhFrameWithHdr.h
new file mode 100644
index 0000000..3571166
--- /dev/null
+++ b/libunwindstack/DwarfEhFrameWithHdr.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2016 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 _LIBUNWINDSTACK_DWARF_EH_FRAME_WITH_HDR_H
+#define _LIBUNWINDSTACK_DWARF_EH_FRAME_WITH_HDR_H
+
+#include <stdint.h>
+
+#include <unordered_map>
+
+#include "DwarfEhFrame.h"
+
+namespace unwindstack {
+
+// Forward declarations.
+class Memory;
+
+template <typename AddressType>
+class DwarfEhFrameWithHdr : public DwarfEhFrame<AddressType> {
+ public:
+ // Add these so that the protected members of DwarfSectionImpl
+ // can be accessed without needing a this->.
+ using DwarfSectionImpl<AddressType>::memory_;
+ using DwarfSectionImpl<AddressType>::fde_count_;
+ using DwarfSectionImpl<AddressType>::entries_offset_;
+ using DwarfSectionImpl<AddressType>::entries_end_;
+ using DwarfSectionImpl<AddressType>::last_error_;
+
+ struct FdeInfo {
+ AddressType pc;
+ uint64_t offset;
+ };
+
+ DwarfEhFrameWithHdr(Memory* memory) : DwarfEhFrame<AddressType>(memory) {}
+ virtual ~DwarfEhFrameWithHdr() = default;
+
+ bool Init(uint64_t offset, uint64_t size) override;
+
+ bool GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset) override;
+
+ const DwarfFde* GetFdeFromIndex(size_t index) override;
+
+ const FdeInfo* GetFdeInfoFromIndex(size_t index);
+
+ bool GetFdeOffsetSequential(uint64_t pc, uint64_t* fde_offset);
+
+ bool GetFdeOffsetBinary(uint64_t pc, uint64_t* fde_offset, uint64_t total_entries);
+
+ protected:
+ uint8_t version_;
+ uint8_t ptr_encoding_;
+ uint8_t table_encoding_;
+ size_t table_entry_size_;
+
+ uint64_t ptr_offset_;
+
+ uint64_t entries_data_offset_;
+ uint64_t cur_entries_offset_ = 0;
+
+ std::unordered_map<uint64_t, FdeInfo> fde_info_;
+};
+
+} // namespace unwindstack
+
+#endif // _LIBUNWINDSTACK_DWARF_EH_FRAME_WITH_HDR_H
diff --git a/libunwindstack/DwarfSection.cpp b/libunwindstack/DwarfSection.cpp
index 2292168..805dcd3 100644
--- a/libunwindstack/DwarfSection.cpp
+++ b/libunwindstack/DwarfSection.cpp
@@ -29,6 +29,9 @@
#include "DwarfError.h"
#include "DwarfOp.h"
+#include "DwarfDebugFrame.h"
+#include "DwarfEhFrame.h"
+
namespace unwindstack {
DwarfSection::DwarfSection(Memory* memory) : memory_(memory), last_error_(DWARF_ERROR_NONE) {}
@@ -39,6 +42,10 @@
return nullptr;
}
const DwarfFde* fde = GetFdeFromOffset(fde_offset);
+ if (fde == nullptr) {
+ return nullptr;
+ }
+
// Guaranteed pc >= pc_start, need to check pc in the fde range.
if (pc < fde->pc_end) {
return fde;
@@ -278,7 +285,7 @@
last_error_ = DWARF_ERROR_MEMORY_INVALID;
return false;
}
- if (!IsCie64(cie_id)) {
+ if (cie_id != cie64_value_) {
// This is not a Cie, something has gone horribly wrong.
last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
return false;
@@ -293,7 +300,7 @@
last_error_ = DWARF_ERROR_MEMORY_INVALID;
return false;
}
- if (!IsCie32(cie_id)) {
+ if (cie_id != cie32_value_) {
// This is not a Cie, something has gone horribly wrong.
last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
return false;
@@ -436,7 +443,7 @@
last_error_ = DWARF_ERROR_MEMORY_INVALID;
return false;
}
- if (IsCie64(value64)) {
+ if (value64 == cie64_value_) {
// This is a Cie, this means something has gone wrong.
last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
return false;
@@ -454,7 +461,7 @@
last_error_ = DWARF_ERROR_MEMORY_INVALID;
return false;
}
- if (IsCie32(value32)) {
+ if (value32 == cie32_value_) {
// This is a Cie, this means something has gone wrong.
last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
return false;
@@ -552,8 +559,301 @@
return true;
}
+template <typename AddressType>
+bool DwarfSectionImpl<AddressType>::Init(uint64_t offset, uint64_t size) {
+ entries_offset_ = offset;
+ entries_end_ = offset + size;
+
+ memory_.clear_func_offset();
+ memory_.clear_text_offset();
+ memory_.set_data_offset(offset);
+ memory_.set_cur_offset(offset);
+ memory_.set_pc_offset(offset);
+
+ return CreateSortedFdeList();
+}
+
+template <typename AddressType>
+bool DwarfSectionImpl<AddressType>::GetCieInfo(uint8_t* segment_size, uint8_t* encoding) {
+ uint8_t version;
+ if (!memory_.ReadBytes(&version, 1)) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+ // Read the augmentation string.
+ std::vector<char> aug_string;
+ char aug_value;
+ bool get_encoding = false;
+ do {
+ if (!memory_.ReadBytes(&aug_value, 1)) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+ if (aug_value == 'R') {
+ get_encoding = true;
+ }
+ aug_string.push_back(aug_value);
+ } while (aug_value != '\0');
+
+ if (version == 4) {
+ // Skip the Address Size field.
+ memory_.set_cur_offset(memory_.cur_offset() + 1);
+
+ // Read the segment size.
+ if (!memory_.ReadBytes(segment_size, 1)) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+ } else {
+ *segment_size = 0;
+ }
+
+ if (aug_string[0] != 'z' || !get_encoding) {
+ // No encoding
+ return true;
+ }
+
+ // Skip code alignment factor
+ uint8_t value;
+ do {
+ if (!memory_.ReadBytes(&value, 1)) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+ } while (value & 0x80);
+
+ // Skip data alignment factor
+ do {
+ if (!memory_.ReadBytes(&value, 1)) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+ } while (value & 0x80);
+
+ if (version == 1) {
+ // Skip return address register.
+ memory_.set_cur_offset(memory_.cur_offset() + 1);
+ } else {
+ // Skip return address register.
+ do {
+ if (!memory_.ReadBytes(&value, 1)) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+ } while (value & 0x80);
+ }
+
+ // Skip the augmentation length.
+ do {
+ if (!memory_.ReadBytes(&value, 1)) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+ } while (value & 0x80);
+
+ for (size_t i = 1; i < aug_string.size(); i++) {
+ if (aug_string[i] == 'R') {
+ if (!memory_.ReadBytes(encoding, 1)) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+ // Got the encoding, that's all we are looking for.
+ return true;
+ } else if (aug_string[i] == 'L') {
+ memory_.set_cur_offset(memory_.cur_offset() + 1);
+ } else if (aug_string[i] == 'P') {
+ uint8_t encoding;
+ if (!memory_.ReadBytes(&encoding, 1)) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+ uint64_t value;
+ if (!memory_.template ReadEncodedValue<AddressType>(encoding, &value)) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+ }
+ }
+
+ // It should be impossible to get here.
+ abort();
+}
+
+template <typename AddressType>
+bool DwarfSectionImpl<AddressType>::AddFdeInfo(uint64_t entry_offset, uint8_t segment_size,
+ uint8_t encoding) {
+ if (segment_size != 0) {
+ memory_.set_cur_offset(memory_.cur_offset() + 1);
+ }
+
+ uint64_t start;
+ if (!memory_.template ReadEncodedValue<AddressType>(encoding & 0xf, &start)) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+ start = AdjustPcFromFde(start);
+
+ uint64_t length;
+ if (!memory_.template ReadEncodedValue<AddressType>(encoding & 0xf, &length)) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+ if (length != 0) {
+ fdes_.emplace_back(entry_offset, start, length);
+ }
+
+ return true;
+}
+
+template <typename AddressType>
+bool DwarfSectionImpl<AddressType>::CreateSortedFdeList() {
+ memory_.set_cur_offset(entries_offset_);
+
+ // Loop through all of the entries and read just enough to create
+ // a sorted list of pcs.
+ // This code assumes that first comes the cie, then the fdes that
+ // it applies to.
+ uint64_t cie_offset = 0;
+ uint8_t address_encoding;
+ uint8_t segment_size;
+ while (memory_.cur_offset() < entries_end_) {
+ uint64_t cur_entry_offset = memory_.cur_offset();
+
+ // Figure out the entry length and type.
+ uint32_t value32;
+ if (!memory_.ReadBytes(&value32, sizeof(value32))) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+
+ uint64_t next_entry_offset;
+ if (value32 == static_cast<uint32_t>(-1)) {
+ uint64_t value64;
+ if (!memory_.ReadBytes(&value64, sizeof(value64))) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+ next_entry_offset = memory_.cur_offset() + value64;
+
+ // Read the Cie Id of a Cie or the pointer of the Fde.
+ if (!memory_.ReadBytes(&value64, sizeof(value64))) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+
+ if (value64 == cie64_value_) {
+ // Cie 64 bit
+ address_encoding = DW_EH_PE_sdata8;
+ if (!GetCieInfo(&segment_size, &address_encoding)) {
+ return false;
+ }
+ cie_offset = cur_entry_offset;
+ } else {
+ uint64_t last_cie_offset = GetCieOffsetFromFde64(value64);
+ if (last_cie_offset != cie_offset) {
+ // This means that this Fde is not following the Cie.
+ last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ return false;
+ }
+
+ // Fde 64 bit
+ if (!AddFdeInfo(cur_entry_offset, segment_size, address_encoding)) {
+ return false;
+ }
+ }
+ } else {
+ next_entry_offset = memory_.cur_offset() + value32;
+
+ // Read the Cie Id of a Cie or the pointer of the Fde.
+ if (!memory_.ReadBytes(&value32, sizeof(value32))) {
+ last_error_ = DWARF_ERROR_MEMORY_INVALID;
+ return false;
+ }
+
+ if (value32 == cie32_value_) {
+ // Cie 32 bit
+ address_encoding = DW_EH_PE_sdata4;
+ if (!GetCieInfo(&segment_size, &address_encoding)) {
+ return false;
+ }
+ cie_offset = cur_entry_offset;
+ } else {
+ uint64_t last_cie_offset = GetCieOffsetFromFde32(value32);
+ if (last_cie_offset != cie_offset) {
+ // This means that this Fde is not following the Cie.
+ last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ return false;
+ }
+
+ // Fde 32 bit
+ if (!AddFdeInfo(cur_entry_offset, segment_size, address_encoding)) {
+ return false;
+ }
+ }
+ }
+
+ if (next_entry_offset < memory_.cur_offset()) {
+ // This indicates some kind of corruption, or malformed section data.
+ last_error_ = DWARF_ERROR_ILLEGAL_VALUE;
+ return false;
+ }
+ memory_.set_cur_offset(next_entry_offset);
+ }
+
+ // Sort the entries.
+ std::sort(fdes_.begin(), fdes_.end(), [](const FdeInfo& a, const FdeInfo& b) {
+ if (a.start == b.start) return a.end < b.end;
+ return a.start < b.start;
+ });
+
+ fde_count_ = fdes_.size();
+
+ return true;
+}
+
+template <typename AddressType>
+bool DwarfSectionImpl<AddressType>::GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset) {
+ if (fde_count_ == 0) {
+ return false;
+ }
+
+ size_t first = 0;
+ size_t last = fde_count_;
+ while (first < last) {
+ size_t current = (first + last) / 2;
+ const FdeInfo* info = &fdes_[current];
+ if (pc >= info->start && pc <= info->end) {
+ *fde_offset = info->offset;
+ return true;
+ }
+
+ if (pc < info->start) {
+ last = current;
+ } else {
+ first = current + 1;
+ }
+ }
+ return false;
+}
+
+template <typename AddressType>
+const DwarfFde* DwarfSectionImpl<AddressType>::GetFdeFromIndex(size_t index) {
+ if (index >= fdes_.size()) {
+ return nullptr;
+ }
+ return this->GetFdeFromOffset(fdes_[index].offset);
+}
+
// Explicitly instantiate DwarfSectionImpl
template class DwarfSectionImpl<uint32_t>;
template class DwarfSectionImpl<uint64_t>;
+// Explicitly instantiate DwarfDebugFrame
+template class DwarfDebugFrame<uint32_t>;
+template class DwarfDebugFrame<uint64_t>;
+
+// Explicitly instantiate DwarfEhFrame
+template class DwarfEhFrame<uint32_t>;
+template class DwarfEhFrame<uint64_t>;
+
} // namespace unwindstack
diff --git a/libunwindstack/ElfInterface.cpp b/libunwindstack/ElfInterface.cpp
index 20cc1b0..d5d158f 100644
--- a/libunwindstack/ElfInterface.cpp
+++ b/libunwindstack/ElfInterface.cpp
@@ -32,6 +32,7 @@
#include "DwarfDebugFrame.h"
#include "DwarfEhFrame.h"
+#include "DwarfEhFrameWithHdr.h"
#include "Symbols.h"
namespace unwindstack {
@@ -98,7 +99,17 @@
template <typename AddressType>
void ElfInterface::InitHeadersWithTemplate() {
- if (eh_frame_offset_ != 0) {
+ if (eh_frame_hdr_offset_ != 0) {
+ eh_frame_.reset(new DwarfEhFrameWithHdr<AddressType>(memory_));
+ if (!eh_frame_->Init(eh_frame_hdr_offset_, eh_frame_hdr_size_)) {
+ // Even if the eh_frame_offset_ is non-zero, do not bother
+ // trying to read that since something has gone wrong.
+ eh_frame_.reset(nullptr);
+ eh_frame_hdr_offset_ = 0;
+ eh_frame_hdr_size_ = static_cast<uint64_t>(-1);
+ }
+ } else if (eh_frame_offset_ != 0) {
+ // If there is a eh_frame section without a eh_frame_hdr section.
eh_frame_.reset(new DwarfEhFrame<AddressType>(memory_));
if (!eh_frame_->Init(eh_frame_offset_, eh_frame_size_)) {
eh_frame_.reset(nullptr);
@@ -181,11 +192,12 @@
if (!memory_->ReadField(offset, &phdr, &phdr.p_offset, sizeof(phdr.p_offset))) {
return false;
}
- eh_frame_offset_ = phdr.p_offset;
+ // This is really the pointer to the .eh_frame_hdr section.
+ eh_frame_hdr_offset_ = phdr.p_offset;
if (!memory_->ReadField(offset, &phdr, &phdr.p_memsz, sizeof(phdr.p_memsz))) {
return false;
}
- eh_frame_size_ = phdr.p_memsz;
+ eh_frame_hdr_size_ = phdr.p_memsz;
break;
case PT_DYNAMIC:
@@ -271,6 +283,12 @@
} else if (name == ".gnu_debugdata") {
offset_ptr = &gnu_debugdata_offset_;
size_ptr = &gnu_debugdata_size_;
+ } else if (name == ".eh_frame") {
+ offset_ptr = &eh_frame_offset_;
+ size_ptr = &eh_frame_size_;
+ } else if (eh_frame_hdr_offset_ == 0 && name == ".eh_frame_hdr") {
+ offset_ptr = &eh_frame_hdr_offset_;
+ size_ptr = &eh_frame_hdr_size_;
}
if (offset_ptr != nullptr &&
memory_->ReadField(offset, &shdr, &shdr.sh_offset, sizeof(shdr.sh_offset)) &&
diff --git a/libunwindstack/include/unwindstack/DwarfSection.h b/libunwindstack/include/unwindstack/DwarfSection.h
index 1e843c3..10be6b4 100644
--- a/libunwindstack/include/unwindstack/DwarfSection.h
+++ b/libunwindstack/include/unwindstack/DwarfSection.h
@@ -90,10 +90,6 @@
virtual bool GetCfaLocationInfo(uint64_t pc, const DwarfFde* fde, dwarf_loc_regs_t* loc_regs) = 0;
- virtual bool IsCie32(uint32_t value32) = 0;
-
- virtual bool IsCie64(uint64_t value64) = 0;
-
virtual uint64_t GetCieOffsetFromFde32(uint32_t pointer) = 0;
virtual uint64_t GetCieOffsetFromFde64(uint64_t pointer) = 0;
@@ -106,6 +102,9 @@
DwarfMemory memory_;
DwarfError last_error_;
+ uint32_t cie32_value_ = 0;
+ uint64_t cie64_value_ = 0;
+
uint64_t fde_count_ = 0;
std::unordered_map<uint64_t, DwarfFde> fde_entries_;
std::unordered_map<uint64_t, DwarfCie> cie_entries_;
@@ -115,9 +114,24 @@
template <typename AddressType>
class DwarfSectionImpl : public DwarfSection {
public:
+ struct FdeInfo {
+ FdeInfo(uint64_t offset, uint64_t start, uint64_t length)
+ : offset(offset), start(start), end(start + length) {}
+
+ uint64_t offset;
+ AddressType start;
+ AddressType end;
+ };
+
DwarfSectionImpl(Memory* memory) : DwarfSection(memory) {}
virtual ~DwarfSectionImpl() = default;
+ bool Init(uint64_t offset, uint64_t size) override;
+
+ bool GetFdeOffsetFromPc(uint64_t pc, uint64_t* fde_offset) override;
+
+ const DwarfFde* GetFdeFromIndex(size_t index) override;
+
bool Eval(const DwarfCie* cie, Memory* regular_memory, const dwarf_loc_regs_t& loc_regs,
Regs* regs, bool* finished) override;
@@ -134,6 +148,16 @@
protected:
bool EvalExpression(const DwarfLocation& loc, uint8_t version, Memory* regular_memory,
AddressType* value);
+
+ bool GetCieInfo(uint8_t* segment_size, uint8_t* encoding);
+
+ bool AddFdeInfo(uint64_t entry_offset, uint8_t segment_size, uint8_t encoding);
+
+ bool CreateSortedFdeList();
+
+ std::vector<FdeInfo> fdes_;
+ uint64_t entries_offset_;
+ uint64_t entries_end_;
};
} // namespace unwindstack
diff --git a/libunwindstack/include/unwindstack/ElfInterface.h b/libunwindstack/include/unwindstack/ElfInterface.h
index 319623d..86e51b3 100644
--- a/libunwindstack/include/unwindstack/ElfInterface.h
+++ b/libunwindstack/include/unwindstack/ElfInterface.h
@@ -70,6 +70,8 @@
uint64_t dynamic_offset() { return dynamic_offset_; }
uint64_t dynamic_size() { return dynamic_size_; }
+ uint64_t eh_frame_hdr_offset() { return eh_frame_hdr_offset_; }
+ uint64_t eh_frame_hdr_size() { return eh_frame_hdr_size_; }
uint64_t eh_frame_offset() { return eh_frame_offset_; }
uint64_t eh_frame_size() { return eh_frame_size_; }
uint64_t debug_frame_offset() { return debug_frame_offset_; }
@@ -112,6 +114,9 @@
uint64_t dynamic_offset_ = 0;
uint64_t dynamic_size_ = 0;
+ uint64_t eh_frame_hdr_offset_ = 0;
+ uint64_t eh_frame_hdr_size_ = 0;
+
uint64_t eh_frame_offset_ = 0;
uint64_t eh_frame_size_ = 0;
diff --git a/libunwindstack/tests/DwarfDebugFrameTest.cpp b/libunwindstack/tests/DwarfDebugFrameTest.cpp
index 90baabe..07204bc 100644
--- a/libunwindstack/tests/DwarfDebugFrameTest.cpp
+++ b/libunwindstack/tests/DwarfDebugFrameTest.cpp
@@ -35,8 +35,8 @@
~MockDwarfDebugFrame() = default;
void TestSetFdeCount(uint64_t count) { this->fde_count_ = count; }
- void TestSetOffset(uint64_t offset) { this->offset_ = offset; }
- void TestSetEndOffset(uint64_t offset) { this->end_offset_ = offset; }
+ void TestSetOffset(uint64_t offset) { this->entries_offset_ = offset; }
+ void TestSetEndOffset(uint64_t offset) { this->entries_end_ = offset; }
void TestPushFdeInfo(const typename DwarfDebugFrame<TypeParam>::FdeInfo& info) {
this->fdes_.push_back(info);
}
diff --git a/libunwindstack/tests/DwarfEhFrameTest.cpp b/libunwindstack/tests/DwarfEhFrameTest.cpp
index 21114da..53ee719 100644
--- a/libunwindstack/tests/DwarfEhFrameTest.cpp
+++ b/libunwindstack/tests/DwarfEhFrameTest.cpp
@@ -34,28 +34,19 @@
MockDwarfEhFrame(Memory* memory) : DwarfEhFrame<TypeParam>(memory) {}
~MockDwarfEhFrame() = default;
- void TestSetTableEncoding(uint8_t encoding) { this->table_encoding_ = encoding; }
- void TestSetEntriesOffset(uint64_t offset) { this->entries_offset_ = offset; }
- void TestSetEntriesEnd(uint64_t end) { this->entries_end_ = end; }
- void TestSetEntriesDataOffset(uint64_t offset) { this->entries_data_offset_ = offset; }
- void TestSetCurEntriesOffset(uint64_t offset) { this->cur_entries_offset_ = offset; }
- void TestSetTableEntrySize(size_t size) { this->table_entry_size_ = size; }
-
void TestSetFdeCount(uint64_t count) { this->fde_count_ = count; }
- void TestSetFdeInfo(uint64_t index, const typename DwarfEhFrame<TypeParam>::FdeInfo& info) {
- this->fde_info_[index] = info;
+ void TestSetOffset(uint64_t offset) { this->entries_offset_ = offset; }
+ void TestSetEndOffset(uint64_t offset) { this->entries_end_ = offset; }
+ void TestPushFdeInfo(const typename DwarfEhFrame<TypeParam>::FdeInfo& info) {
+ this->fdes_.push_back(info);
}
- uint8_t TestGetVersion() { return this->version_; }
- uint8_t TestGetPtrEncoding() { return this->ptr_encoding_; }
- uint64_t TestGetPtrOffset() { return this->ptr_offset_; }
- uint8_t TestGetTableEncoding() { return this->table_encoding_; }
- uint64_t TestGetTableEntrySize() { return this->table_entry_size_; }
uint64_t TestGetFdeCount() { return this->fde_count_; }
- uint64_t TestGetEntriesOffset() { return this->entries_offset_; }
- uint64_t TestGetEntriesEnd() { return this->entries_end_; }
- uint64_t TestGetEntriesDataOffset() { return this->entries_data_offset_; }
- uint64_t TestGetCurEntriesOffset() { return this->cur_entries_offset_; }
+ uint8_t TestGetOffset() { return this->offset_; }
+ uint8_t TestGetEndOffset() { return this->end_offset_; }
+ void TestGetFdeInfo(size_t index, typename DwarfEhFrame<TypeParam>::FdeInfo* info) {
+ *info = this->fdes_[index];
+ }
};
template <typename TypeParam>
@@ -76,248 +67,304 @@
// NOTE: All test class variables need to be referenced as this->.
-TYPED_TEST_P(DwarfEhFrameTest, Init) {
- this->memory_.SetMemory(
- 0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4, DW_EH_PE_sdata4});
- this->memory_.SetData16(0x1004, 0x500);
- this->memory_.SetData32(0x1006, 126);
+TYPED_TEST_P(DwarfEhFrameTest, Init32) {
+ // CIE 32 information.
+ this->memory_.SetData32(0x5000, 0xfc);
+ this->memory_.SetData32(0x5004, 0);
+ this->memory_.SetData8(0x5008, 1);
+ this->memory_.SetData8(0x5009, '\0');
- ASSERT_TRUE(this->eh_frame_->Init(0x1000, 0x100));
- EXPECT_EQ(1U, this->eh_frame_->TestGetVersion());
- EXPECT_EQ(DW_EH_PE_udata2, this->eh_frame_->TestGetPtrEncoding());
- EXPECT_EQ(DW_EH_PE_sdata4, this->eh_frame_->TestGetTableEncoding());
- EXPECT_EQ(4U, this->eh_frame_->TestGetTableEntrySize());
- EXPECT_EQ(126U, this->eh_frame_->TestGetFdeCount());
- EXPECT_EQ(0x500U, this->eh_frame_->TestGetPtrOffset());
- EXPECT_EQ(0x100aU, this->eh_frame_->TestGetEntriesOffset());
- EXPECT_EQ(0x1100U, this->eh_frame_->TestGetEntriesEnd());
- EXPECT_EQ(0x1000U, this->eh_frame_->TestGetEntriesDataOffset());
- EXPECT_EQ(0x100aU, this->eh_frame_->TestGetCurEntriesOffset());
+ // FDE 32 information.
+ this->memory_.SetData32(0x5100, 0xfc);
+ this->memory_.SetData32(0x5104, 0x104);
+ this->memory_.SetData32(0x5108, 0x1500);
+ this->memory_.SetData32(0x510c, 0x200);
- // Verify an unexpected version will cause a fail.
- this->memory_.SetData8(0x1000, 0);
- ASSERT_FALSE(this->eh_frame_->Init(0x1000, 0x100));
- ASSERT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->eh_frame_->last_error());
- this->memory_.SetData8(0x1000, 2);
- ASSERT_FALSE(this->eh_frame_->Init(0x1000, 0x100));
- ASSERT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->eh_frame_->last_error());
+ this->memory_.SetData32(0x5200, 0xfc);
+ this->memory_.SetData32(0x5204, 0x204);
+ this->memory_.SetData32(0x5208, 0x2500);
+ this->memory_.SetData32(0x520c, 0x300);
+
+ // CIE 32 information.
+ this->memory_.SetData32(0x5300, 0xfc);
+ this->memory_.SetData32(0x5304, 0);
+ this->memory_.SetData8(0x5308, 1);
+ this->memory_.SetData8(0x5309, '\0');
+
+ // FDE 32 information.
+ this->memory_.SetData32(0x5400, 0xfc);
+ this->memory_.SetData32(0x5404, 0x104);
+ this->memory_.SetData32(0x5408, 0x3500);
+ this->memory_.SetData32(0x540c, 0x400);
+
+ this->memory_.SetData32(0x5500, 0xfc);
+ this->memory_.SetData32(0x5504, 0x204);
+ this->memory_.SetData32(0x5508, 0x4500);
+ this->memory_.SetData32(0x550c, 0x500);
+
+ ASSERT_TRUE(this->eh_frame_->Init(0x5000, 0x600));
+ ASSERT_EQ(4U, this->eh_frame_->TestGetFdeCount());
+
+ typename DwarfEhFrame<TypeParam>::FdeInfo info(0, 0, 0);
+
+ this->eh_frame_->TestGetFdeInfo(0, &info);
+ EXPECT_EQ(0x5100U, info.offset);
+ EXPECT_EQ(0x660cU, info.start);
+ EXPECT_EQ(0x680cU, info.end);
+
+ this->eh_frame_->TestGetFdeInfo(1, &info);
+ EXPECT_EQ(0x5200U, info.offset);
+ EXPECT_EQ(0x770cU, info.start);
+ EXPECT_EQ(0x7a0cU, info.end);
+
+ this->eh_frame_->TestGetFdeInfo(2, &info);
+ EXPECT_EQ(0x5400U, info.offset);
+ EXPECT_EQ(0x890cU, info.start);
+ EXPECT_EQ(0x8d0cU, info.end);
+
+ this->eh_frame_->TestGetFdeInfo(3, &info);
+ EXPECT_EQ(0x5500U, info.offset);
+ EXPECT_EQ(0x9a0cU, info.start);
+ EXPECT_EQ(0x9f0cU, info.end);
}
-TYPED_TEST_P(DwarfEhFrameTest, GetFdeInfoFromIndex_expect_cache_fail) {
- this->eh_frame_->TestSetTableEntrySize(0x10);
- this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4);
- ASSERT_TRUE(this->eh_frame_->GetFdeInfoFromIndex(0) == nullptr);
- ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->eh_frame_->last_error());
- ASSERT_TRUE(this->eh_frame_->GetFdeInfoFromIndex(0) == nullptr);
- ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->eh_frame_->last_error());
+TYPED_TEST_P(DwarfEhFrameTest, Init32_fde_not_following_cie) {
+ // CIE 32 information.
+ this->memory_.SetData32(0x5000, 0xfc);
+ this->memory_.SetData32(0x5004, 0);
+ this->memory_.SetData8(0x5008, 1);
+ this->memory_.SetData8(0x5009, '\0');
+
+ // FDE 32 information.
+ this->memory_.SetData32(0x5100, 0xfc);
+ this->memory_.SetData32(0x5104, 0x1000);
+ this->memory_.SetData32(0x5108, 0x1500);
+ this->memory_.SetData32(0x510c, 0x200);
+
+ ASSERT_FALSE(this->eh_frame_->Init(0x5000, 0x600));
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->eh_frame_->last_error());
}
-TYPED_TEST_P(DwarfEhFrameTest, GetFdeInfoFromIndex_read_pcrel) {
- this->eh_frame_->TestSetTableEncoding(DW_EH_PE_pcrel | DW_EH_PE_udata4);
- this->eh_frame_->TestSetEntriesOffset(0x1000);
- this->eh_frame_->TestSetEntriesDataOffset(0x3000);
- this->eh_frame_->TestSetTableEntrySize(0x10);
+TYPED_TEST_P(DwarfEhFrameTest, Init64) {
+ // CIE 64 information.
+ this->memory_.SetData32(0x5000, 0xffffffff);
+ this->memory_.SetData64(0x5004, 0xf4);
+ this->memory_.SetData64(0x500c, 0);
+ this->memory_.SetData8(0x5014, 1);
+ this->memory_.SetData8(0x5015, '\0');
- this->memory_.SetData32(0x1040, 0x340);
- this->memory_.SetData32(0x1044, 0x500);
+ // FDE 64 information.
+ this->memory_.SetData32(0x5100, 0xffffffff);
+ this->memory_.SetData64(0x5104, 0xf4);
+ this->memory_.SetData64(0x510c, 0x10c);
+ this->memory_.SetData64(0x5114, 0x1500);
+ this->memory_.SetData64(0x511c, 0x200);
- auto info = this->eh_frame_->GetFdeInfoFromIndex(2);
- ASSERT_TRUE(info != nullptr);
- EXPECT_EQ(0x1384U, info->pc);
- EXPECT_EQ(0x1540U, info->offset);
+ this->memory_.SetData32(0x5200, 0xffffffff);
+ this->memory_.SetData64(0x5204, 0xf4);
+ this->memory_.SetData64(0x520c, 0x20c);
+ this->memory_.SetData64(0x5214, 0x2500);
+ this->memory_.SetData64(0x521c, 0x300);
+
+ // CIE 64 information.
+ this->memory_.SetData32(0x5300, 0xffffffff);
+ this->memory_.SetData64(0x5304, 0xf4);
+ this->memory_.SetData64(0x530c, 0);
+ this->memory_.SetData8(0x5314, 1);
+ this->memory_.SetData8(0x5315, '\0');
+
+ // FDE 64 information.
+ this->memory_.SetData32(0x5400, 0xffffffff);
+ this->memory_.SetData64(0x5404, 0xf4);
+ this->memory_.SetData64(0x540c, 0x10c);
+ this->memory_.SetData64(0x5414, 0x3500);
+ this->memory_.SetData64(0x541c, 0x400);
+
+ this->memory_.SetData32(0x5500, 0xffffffff);
+ this->memory_.SetData64(0x5504, 0xf4);
+ this->memory_.SetData64(0x550c, 0x20c);
+ this->memory_.SetData64(0x5514, 0x4500);
+ this->memory_.SetData64(0x551c, 0x500);
+
+ ASSERT_TRUE(this->eh_frame_->Init(0x5000, 0x600));
+ ASSERT_EQ(4U, this->eh_frame_->TestGetFdeCount());
+
+ typename DwarfEhFrame<TypeParam>::FdeInfo info(0, 0, 0);
+
+ this->eh_frame_->TestGetFdeInfo(0, &info);
+ EXPECT_EQ(0x5100U, info.offset);
+ EXPECT_EQ(0x661cU, info.start);
+ EXPECT_EQ(0x681cU, info.end);
+
+ this->eh_frame_->TestGetFdeInfo(1, &info);
+ EXPECT_EQ(0x5200U, info.offset);
+ EXPECT_EQ(0x771cU, info.start);
+ EXPECT_EQ(0x7a1cU, info.end);
+
+ this->eh_frame_->TestGetFdeInfo(2, &info);
+ EXPECT_EQ(0x5400U, info.offset);
+ EXPECT_EQ(0x891cU, info.start);
+ EXPECT_EQ(0x8d1cU, info.end);
+
+ this->eh_frame_->TestGetFdeInfo(3, &info);
+ EXPECT_EQ(0x5500U, info.offset);
+ EXPECT_EQ(0x9a1cU, info.start);
+ EXPECT_EQ(0x9f1cU, info.end);
}
-TYPED_TEST_P(DwarfEhFrameTest, GetFdeInfoFromIndex_read_datarel) {
- this->eh_frame_->TestSetTableEncoding(DW_EH_PE_datarel | DW_EH_PE_udata4);
- this->eh_frame_->TestSetEntriesOffset(0x1000);
- this->eh_frame_->TestSetEntriesDataOffset(0x3000);
- this->eh_frame_->TestSetTableEntrySize(0x10);
+TYPED_TEST_P(DwarfEhFrameTest, Init64_fde_not_following_cie) {
+ // CIE 64 information.
+ this->memory_.SetData32(0x5000, 0xffffffff);
+ this->memory_.SetData64(0x5004, 0xf4);
+ this->memory_.SetData64(0x500c, 0);
+ this->memory_.SetData8(0x5014, 1);
+ this->memory_.SetData8(0x5015, '\0');
- this->memory_.SetData32(0x1040, 0x340);
- this->memory_.SetData32(0x1044, 0x500);
+ // FDE 64 information.
+ this->memory_.SetData32(0x5100, 0xffffffff);
+ this->memory_.SetData64(0x5104, 0xf4);
+ this->memory_.SetData64(0x510c, 0x1000);
+ this->memory_.SetData64(0x5114, 0x1500);
+ this->memory_.SetData64(0x511c, 0x200);
- auto info = this->eh_frame_->GetFdeInfoFromIndex(2);
- ASSERT_TRUE(info != nullptr);
- EXPECT_EQ(0x3344U, info->pc);
- EXPECT_EQ(0x3500U, info->offset);
+ ASSERT_FALSE(this->eh_frame_->Init(0x5000, 0x600));
+ ASSERT_EQ(DWARF_ERROR_ILLEGAL_VALUE, this->eh_frame_->last_error());
}
-TYPED_TEST_P(DwarfEhFrameTest, GetFdeInfoFromIndex_cached) {
- this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4);
- this->eh_frame_->TestSetEntriesOffset(0x1000);
- this->eh_frame_->TestSetTableEntrySize(0x10);
+TYPED_TEST_P(DwarfEhFrameTest, Init_version1) {
+ // CIE 32 information.
+ this->memory_.SetData32(0x5000, 0xfc);
+ this->memory_.SetData32(0x5004, 0);
+ this->memory_.SetData8(0x5008, 1);
+ // Augment string.
+ this->memory_.SetMemory(0x5009, std::vector<uint8_t>{'z', 'R', 'P', 'L', '\0'});
+ // Code alignment factor.
+ this->memory_.SetMemory(0x500e, std::vector<uint8_t>{0x80, 0x00});
+ // Data alignment factor.
+ this->memory_.SetMemory(0x5010, std::vector<uint8_t>{0x81, 0x80, 0x80, 0x00});
+ // Return address register
+ this->memory_.SetData8(0x5014, 0x84);
+ // Augmentation length
+ this->memory_.SetMemory(0x5015, std::vector<uint8_t>{0x84, 0x00});
+ // R data.
+ this->memory_.SetData8(0x5017, DW_EH_PE_pcrel | DW_EH_PE_udata2);
- this->memory_.SetData32(0x1040, 0x340);
- this->memory_.SetData32(0x1044, 0x500);
+ // FDE 32 information.
+ this->memory_.SetData32(0x5100, 0xfc);
+ this->memory_.SetData32(0x5104, 0x104);
+ this->memory_.SetData16(0x5108, 0x1500);
+ this->memory_.SetData16(0x510a, 0x200);
- auto info = this->eh_frame_->GetFdeInfoFromIndex(2);
- ASSERT_TRUE(info != nullptr);
- EXPECT_EQ(0x344U, info->pc);
- EXPECT_EQ(0x500U, info->offset);
+ ASSERT_TRUE(this->eh_frame_->Init(0x5000, 0x200));
+ ASSERT_EQ(1U, this->eh_frame_->TestGetFdeCount());
- // Clear the memory so that this will fail if it doesn't read cached data.
- this->memory_.Clear();
-
- info = this->eh_frame_->GetFdeInfoFromIndex(2);
- ASSERT_TRUE(info != nullptr);
- EXPECT_EQ(0x344U, info->pc);
- EXPECT_EQ(0x500U, info->offset);
+ typename DwarfEhFrame<TypeParam>::FdeInfo info(0, 0, 0);
+ this->eh_frame_->TestGetFdeInfo(0, &info);
+ EXPECT_EQ(0x5100U, info.offset);
+ EXPECT_EQ(0x660aU, info.start);
+ EXPECT_EQ(0x680aU, info.end);
}
-TYPED_TEST_P(DwarfEhFrameTest, GetFdeOffsetBinary_verify) {
- this->eh_frame_->TestSetTableEntrySize(0x10);
- this->eh_frame_->TestSetFdeCount(10);
+TYPED_TEST_P(DwarfEhFrameTest, Init_version4) {
+ // CIE 32 information.
+ this->memory_.SetData32(0x5000, 0xfc);
+ this->memory_.SetData32(0x5004, 0);
+ this->memory_.SetData8(0x5008, 4);
+ // Augment string.
+ this->memory_.SetMemory(0x5009, std::vector<uint8_t>{'z', 'L', 'P', 'R', '\0'});
+ // Address size.
+ this->memory_.SetData8(0x500e, 4);
+ // Segment size.
+ this->memory_.SetData8(0x500f, 0);
+ // Code alignment factor.
+ this->memory_.SetMemory(0x5010, std::vector<uint8_t>{0x80, 0x00});
+ // Data alignment factor.
+ this->memory_.SetMemory(0x5012, std::vector<uint8_t>{0x81, 0x80, 0x80, 0x00});
+ // Return address register
+ this->memory_.SetMemory(0x5016, std::vector<uint8_t>{0x85, 0x10});
+ // Augmentation length
+ this->memory_.SetMemory(0x5018, std::vector<uint8_t>{0x84, 0x00});
+ // L data.
+ this->memory_.SetData8(0x501a, 0x10);
+ // P data.
+ this->memory_.SetData8(0x501b, DW_EH_PE_udata4);
+ this->memory_.SetData32(0x501c, 0x100);
+ // R data.
+ this->memory_.SetData8(0x5020, DW_EH_PE_pcrel | DW_EH_PE_udata2);
- typename DwarfEhFrame<TypeParam>::FdeInfo info;
- for (size_t i = 0; i < 10; i++) {
- info.pc = 0x1000 * (i + 1);
+ // FDE 32 information.
+ this->memory_.SetData32(0x5100, 0xfc);
+ this->memory_.SetData32(0x5104, 0x104);
+ this->memory_.SetData16(0x5108, 0x1500);
+ this->memory_.SetData16(0x510a, 0x200);
+
+ ASSERT_TRUE(this->eh_frame_->Init(0x5000, 0x200));
+ ASSERT_EQ(1U, this->eh_frame_->TestGetFdeCount());
+
+ typename DwarfEhFrame<TypeParam>::FdeInfo info(0, 0, 0);
+ this->eh_frame_->TestGetFdeInfo(0, &info);
+ EXPECT_EQ(0x5100U, info.offset);
+ EXPECT_EQ(0x660aU, info.start);
+ EXPECT_EQ(0x680aU, info.end);
+}
+
+TYPED_TEST_P(DwarfEhFrameTest, GetFdeOffsetFromPc) {
+ typename DwarfEhFrame<TypeParam>::FdeInfo info(0, 0, 0);
+ for (size_t i = 0; i < 9; i++) {
+ info.start = 0x1000 * (i + 1);
+ info.end = 0x1000 * (i + 2) - 0x10;
info.offset = 0x5000 + i * 0x20;
- this->eh_frame_->TestSetFdeInfo(i, info);
+ this->eh_frame_->TestPushFdeInfo(info);
}
+ this->eh_frame_->TestSetFdeCount(0);
uint64_t fde_offset;
- EXPECT_FALSE(this->eh_frame_->GetFdeOffsetBinary(0x100, &fde_offset, 10));
- // Not an error, just not found.
+ ASSERT_FALSE(this->eh_frame_->GetFdeOffsetFromPc(0x1000, &fde_offset));
ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
- // Even number of elements.
- for (size_t i = 0; i < 10; i++) {
- TypeParam pc = 0x1000 * (i + 1);
- EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc, &fde_offset, 10)) << "Failed at index " << i;
- EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
- EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc + 1, &fde_offset, 10)) << "Failed at index "
- << i;
- EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
- EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc + 0xfff, &fde_offset, 10))
- << "Failed at index " << i;
- EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
- }
+
+ this->eh_frame_->TestSetFdeCount(9);
+ ASSERT_FALSE(this->eh_frame_->GetFdeOffsetFromPc(0x100, &fde_offset));
+ ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
// Odd number of elements.
for (size_t i = 0; i < 9; i++) {
TypeParam pc = 0x1000 * (i + 1);
- EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc, &fde_offset, 9)) << "Failed at index " << i;
+ ASSERT_TRUE(this->eh_frame_->GetFdeOffsetFromPc(pc, &fde_offset)) << "Failed at index " << i;
EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
- EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc + 1, &fde_offset, 9)) << "Failed at index "
- << i;
+ ASSERT_TRUE(this->eh_frame_->GetFdeOffsetFromPc(pc + 1, &fde_offset)) << "Failed at index " << i;
EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
- EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc + 0xfff, &fde_offset, 9))
+ ASSERT_TRUE(this->eh_frame_->GetFdeOffsetFromPc(pc + 0xeff, &fde_offset))
<< "Failed at index " << i;
EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
+ ASSERT_FALSE(this->eh_frame_->GetFdeOffsetFromPc(pc + 0xfff, &fde_offset))
+ << "Failed at index " << i;
+ ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
+ }
+
+ // Even number of elements.
+ this->eh_frame_->TestSetFdeCount(10);
+ info.start = 0xa000;
+ info.end = 0xaff0;
+ info.offset = 0x5120;
+ this->eh_frame_->TestPushFdeInfo(info);
+
+ for (size_t i = 0; i < 10; i++) {
+ TypeParam pc = 0x1000 * (i + 1);
+ ASSERT_TRUE(this->eh_frame_->GetFdeOffsetFromPc(pc, &fde_offset)) << "Failed at index " << i;
+ EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
+ ASSERT_TRUE(this->eh_frame_->GetFdeOffsetFromPc(pc + 1, &fde_offset)) << "Failed at index " << i;
+ EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
+ ASSERT_TRUE(this->eh_frame_->GetFdeOffsetFromPc(pc + 0xeff, &fde_offset))
+ << "Failed at index " << i;
+ EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
+ ASSERT_FALSE(this->eh_frame_->GetFdeOffsetFromPc(pc + 0xfff, &fde_offset))
+ << "Failed at index " << i;
+ ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
}
}
-TYPED_TEST_P(DwarfEhFrameTest, GetFdeOffsetSequential) {
- this->eh_frame_->TestSetFdeCount(10);
- this->eh_frame_->TestSetEntriesDataOffset(0x100);
- this->eh_frame_->TestSetEntriesEnd(0x2000);
- this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4);
-
- this->memory_.SetData32(0x1040, 0x340);
- this->memory_.SetData32(0x1044, 0x500);
-
- this->memory_.SetData32(0x1048, 0x440);
- this->memory_.SetData32(0x104c, 0x600);
-
- // Verify that if entries is zero, that it fails.
- uint64_t fde_offset;
- ASSERT_FALSE(this->eh_frame_->GetFdeOffsetSequential(0x344, &fde_offset));
- this->eh_frame_->TestSetCurEntriesOffset(0x1040);
-
- ASSERT_TRUE(this->eh_frame_->GetFdeOffsetSequential(0x344, &fde_offset));
- EXPECT_EQ(0x500U, fde_offset);
-
- ASSERT_TRUE(this->eh_frame_->GetFdeOffsetSequential(0x444, &fde_offset));
- EXPECT_EQ(0x600U, fde_offset);
-
- // Expect that the data is cached so no more memory reads will occur.
- this->memory_.Clear();
- ASSERT_TRUE(this->eh_frame_->GetFdeOffsetSequential(0x444, &fde_offset));
- EXPECT_EQ(0x600U, fde_offset);
-}
-
-TYPED_TEST_P(DwarfEhFrameTest, GetFdeOffsetSequential_last_element) {
- this->eh_frame_->TestSetFdeCount(2);
- this->eh_frame_->TestSetEntriesDataOffset(0x100);
- this->eh_frame_->TestSetEntriesEnd(0x2000);
- this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4);
- this->eh_frame_->TestSetCurEntriesOffset(0x1040);
-
- this->memory_.SetData32(0x1040, 0x340);
- this->memory_.SetData32(0x1044, 0x500);
-
- this->memory_.SetData32(0x1048, 0x440);
- this->memory_.SetData32(0x104c, 0x600);
-
- uint64_t fde_offset;
- ASSERT_TRUE(this->eh_frame_->GetFdeOffsetSequential(0x540, &fde_offset));
- EXPECT_EQ(0x600U, fde_offset);
-}
-
-TYPED_TEST_P(DwarfEhFrameTest, GetFdeOffsetSequential_end_check) {
- this->eh_frame_->TestSetFdeCount(2);
- this->eh_frame_->TestSetEntriesDataOffset(0x100);
- this->eh_frame_->TestSetEntriesEnd(0x1048);
- this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4);
-
- this->memory_.SetData32(0x1040, 0x340);
- this->memory_.SetData32(0x1044, 0x500);
-
- this->memory_.SetData32(0x1048, 0x440);
- this->memory_.SetData32(0x104c, 0x600);
-
- uint64_t fde_offset;
- ASSERT_FALSE(this->eh_frame_->GetFdeOffsetSequential(0x540, &fde_offset));
- ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
-}
-
-TYPED_TEST_P(DwarfEhFrameTest, GetFdeOffsetFromPc_fail_fde_count) {
- this->eh_frame_->TestSetFdeCount(0);
-
- uint64_t fde_offset;
- ASSERT_FALSE(this->eh_frame_->GetFdeOffsetFromPc(0x100, &fde_offset));
- ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
-}
-
-TYPED_TEST_P(DwarfEhFrameTest, GetFdeOffsetFromPc_binary_search) {
- this->eh_frame_->TestSetTableEntrySize(16);
- this->eh_frame_->TestSetFdeCount(10);
-
- typename DwarfEhFrame<TypeParam>::FdeInfo info;
- info.pc = 0x550;
- info.offset = 0x10500;
- this->eh_frame_->TestSetFdeInfo(5, info);
- info.pc = 0x750;
- info.offset = 0x10700;
- this->eh_frame_->TestSetFdeInfo(7, info);
- info.pc = 0x850;
- info.offset = 0x10800;
- this->eh_frame_->TestSetFdeInfo(8, info);
-
- uint64_t fde_offset;
- ASSERT_TRUE(this->eh_frame_->GetFdeOffsetFromPc(0x800, &fde_offset));
- EXPECT_EQ(0x10700U, fde_offset);
-}
-
-TYPED_TEST_P(DwarfEhFrameTest, GetFdeOffsetFromPc_sequential_search) {
- this->eh_frame_->TestSetFdeCount(10);
- this->eh_frame_->TestSetTableEntrySize(0);
-
- typename DwarfEhFrame<TypeParam>::FdeInfo info;
- info.pc = 0x50;
- info.offset = 0x10000;
- this->eh_frame_->TestSetFdeInfo(0, info);
- info.pc = 0x150;
- info.offset = 0x10100;
- this->eh_frame_->TestSetFdeInfo(1, info);
- info.pc = 0x250;
- info.offset = 0x10200;
- this->eh_frame_->TestSetFdeInfo(2, info);
-
- uint64_t fde_offset;
- ASSERT_TRUE(this->eh_frame_->GetFdeOffsetFromPc(0x200, &fde_offset));
- EXPECT_EQ(0x10100U, fde_offset);
-}
-
TYPED_TEST_P(DwarfEhFrameTest, GetCieFde32) {
+ this->eh_frame_->TestSetOffset(0x4000);
+
// CIE 32 information.
this->memory_.SetData32(0xf000, 0x100);
this->memory_.SetData32(0xf004, 0);
@@ -358,6 +405,8 @@
}
TYPED_TEST_P(DwarfEhFrameTest, GetCieFde64) {
+ this->eh_frame_->TestSetOffset(0x2000);
+
// CIE 64 information.
this->memory_.SetData32(0x6000, 0xffffffff);
this->memory_.SetData64(0x6004, 0x100);
@@ -399,13 +448,9 @@
EXPECT_EQ(0x20U, fde->cie->return_address_register);
}
-REGISTER_TYPED_TEST_CASE_P(DwarfEhFrameTest, Init, GetFdeInfoFromIndex_expect_cache_fail,
- GetFdeInfoFromIndex_read_pcrel, GetFdeInfoFromIndex_read_datarel,
- GetFdeInfoFromIndex_cached, GetFdeOffsetBinary_verify,
- GetFdeOffsetSequential, GetFdeOffsetSequential_last_element,
- GetFdeOffsetSequential_end_check, GetFdeOffsetFromPc_fail_fde_count,
- GetFdeOffsetFromPc_binary_search, GetFdeOffsetFromPc_sequential_search,
- GetCieFde32, GetCieFde64);
+REGISTER_TYPED_TEST_CASE_P(DwarfEhFrameTest, Init32, Init32_fde_not_following_cie, Init64,
+ Init64_fde_not_following_cie, Init_version1, Init_version4,
+ GetFdeOffsetFromPc, GetCieFde32, GetCieFde64);
typedef ::testing::Types<uint32_t, uint64_t> DwarfEhFrameTestTypes;
INSTANTIATE_TYPED_TEST_CASE_P(, DwarfEhFrameTest, DwarfEhFrameTestTypes);
diff --git a/libunwindstack/tests/DwarfEhFrameWithHdrTest.cpp b/libunwindstack/tests/DwarfEhFrameWithHdrTest.cpp
new file mode 100644
index 0000000..1028ab9
--- /dev/null
+++ b/libunwindstack/tests/DwarfEhFrameWithHdrTest.cpp
@@ -0,0 +1,434 @@
+/*
+ * Copyright (C) 2016 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 <stdint.h>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "DwarfEhFrameWithHdr.h"
+#include "DwarfEncoding.h"
+#include "DwarfError.h"
+
+#include "LogFake.h"
+#include "MemoryFake.h"
+
+namespace unwindstack {
+
+template <typename TypeParam>
+class MockDwarfEhFrameWithHdr : public DwarfEhFrameWithHdr<TypeParam> {
+ public:
+ MockDwarfEhFrameWithHdr(Memory* memory) : DwarfEhFrameWithHdr<TypeParam>(memory) {}
+ ~MockDwarfEhFrameWithHdr() = default;
+
+ void TestSetTableEncoding(uint8_t encoding) { this->table_encoding_ = encoding; }
+ void TestSetEntriesOffset(uint64_t offset) { this->entries_offset_ = offset; }
+ void TestSetEntriesEnd(uint64_t end) { this->entries_end_ = end; }
+ void TestSetEntriesDataOffset(uint64_t offset) { this->entries_data_offset_ = offset; }
+ void TestSetCurEntriesOffset(uint64_t offset) { this->cur_entries_offset_ = offset; }
+ void TestSetTableEntrySize(size_t size) { this->table_entry_size_ = size; }
+
+ void TestSetFdeCount(uint64_t count) { this->fde_count_ = count; }
+ void TestSetFdeInfo(uint64_t index, const typename DwarfEhFrameWithHdr<TypeParam>::FdeInfo& info) {
+ this->fde_info_[index] = info;
+ }
+
+ uint8_t TestGetVersion() { return this->version_; }
+ uint8_t TestGetPtrEncoding() { return this->ptr_encoding_; }
+ uint64_t TestGetPtrOffset() { return this->ptr_offset_; }
+ uint8_t TestGetTableEncoding() { return this->table_encoding_; }
+ uint64_t TestGetTableEntrySize() { return this->table_entry_size_; }
+ uint64_t TestGetFdeCount() { return this->fde_count_; }
+ uint64_t TestGetEntriesOffset() { return this->entries_offset_; }
+ uint64_t TestGetEntriesEnd() { return this->entries_end_; }
+ uint64_t TestGetEntriesDataOffset() { return this->entries_data_offset_; }
+ uint64_t TestGetCurEntriesOffset() { return this->cur_entries_offset_; }
+};
+
+template <typename TypeParam>
+class DwarfEhFrameWithHdrTest : public ::testing::Test {
+ protected:
+ void SetUp() override {
+ memory_.Clear();
+ eh_frame_ = new MockDwarfEhFrameWithHdr<TypeParam>(&memory_);
+ ResetLogs();
+ }
+
+ void TearDown() override { delete eh_frame_; }
+
+ MemoryFake memory_;
+ MockDwarfEhFrameWithHdr<TypeParam>* eh_frame_ = nullptr;
+};
+TYPED_TEST_CASE_P(DwarfEhFrameWithHdrTest);
+
+// NOTE: All test class variables need to be referenced as this->.
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, Init) {
+ this->memory_.SetMemory(
+ 0x1000, std::vector<uint8_t>{0x1, DW_EH_PE_udata2, DW_EH_PE_udata4, DW_EH_PE_sdata4});
+ this->memory_.SetData16(0x1004, 0x500);
+ this->memory_.SetData32(0x1006, 126);
+
+ ASSERT_TRUE(this->eh_frame_->Init(0x1000, 0x100));
+ EXPECT_EQ(1U, this->eh_frame_->TestGetVersion());
+ EXPECT_EQ(DW_EH_PE_udata2, this->eh_frame_->TestGetPtrEncoding());
+ EXPECT_EQ(DW_EH_PE_sdata4, this->eh_frame_->TestGetTableEncoding());
+ EXPECT_EQ(4U, this->eh_frame_->TestGetTableEntrySize());
+ EXPECT_EQ(126U, this->eh_frame_->TestGetFdeCount());
+ EXPECT_EQ(0x500U, this->eh_frame_->TestGetPtrOffset());
+ EXPECT_EQ(0x100aU, this->eh_frame_->TestGetEntriesOffset());
+ EXPECT_EQ(0x1100U, this->eh_frame_->TestGetEntriesEnd());
+ EXPECT_EQ(0x1000U, this->eh_frame_->TestGetEntriesDataOffset());
+ EXPECT_EQ(0x100aU, this->eh_frame_->TestGetCurEntriesOffset());
+
+ // Verify an unexpected version will cause a fail.
+ this->memory_.SetData8(0x1000, 0);
+ ASSERT_FALSE(this->eh_frame_->Init(0x1000, 0x100));
+ ASSERT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->eh_frame_->last_error());
+ this->memory_.SetData8(0x1000, 2);
+ ASSERT_FALSE(this->eh_frame_->Init(0x1000, 0x100));
+ ASSERT_EQ(DWARF_ERROR_UNSUPPORTED_VERSION, this->eh_frame_->last_error());
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_expect_cache_fail) {
+ this->eh_frame_->TestSetTableEntrySize(0x10);
+ this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4);
+ ASSERT_TRUE(this->eh_frame_->GetFdeInfoFromIndex(0) == nullptr);
+ ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->eh_frame_->last_error());
+ ASSERT_TRUE(this->eh_frame_->GetFdeInfoFromIndex(0) == nullptr);
+ ASSERT_EQ(DWARF_ERROR_MEMORY_INVALID, this->eh_frame_->last_error());
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_read_pcrel) {
+ this->eh_frame_->TestSetTableEncoding(DW_EH_PE_pcrel | DW_EH_PE_udata4);
+ this->eh_frame_->TestSetEntriesOffset(0x1000);
+ this->eh_frame_->TestSetEntriesDataOffset(0x3000);
+ this->eh_frame_->TestSetTableEntrySize(0x10);
+
+ this->memory_.SetData32(0x1040, 0x340);
+ this->memory_.SetData32(0x1044, 0x500);
+
+ auto info = this->eh_frame_->GetFdeInfoFromIndex(2);
+ ASSERT_TRUE(info != nullptr);
+ EXPECT_EQ(0x1384U, info->pc);
+ EXPECT_EQ(0x1540U, info->offset);
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_read_datarel) {
+ this->eh_frame_->TestSetTableEncoding(DW_EH_PE_datarel | DW_EH_PE_udata4);
+ this->eh_frame_->TestSetEntriesOffset(0x1000);
+ this->eh_frame_->TestSetEntriesDataOffset(0x3000);
+ this->eh_frame_->TestSetTableEntrySize(0x10);
+
+ this->memory_.SetData32(0x1040, 0x340);
+ this->memory_.SetData32(0x1044, 0x500);
+
+ auto info = this->eh_frame_->GetFdeInfoFromIndex(2);
+ ASSERT_TRUE(info != nullptr);
+ EXPECT_EQ(0x3344U, info->pc);
+ EXPECT_EQ(0x3500U, info->offset);
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeInfoFromIndex_cached) {
+ this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4);
+ this->eh_frame_->TestSetEntriesOffset(0x1000);
+ this->eh_frame_->TestSetTableEntrySize(0x10);
+
+ this->memory_.SetData32(0x1040, 0x340);
+ this->memory_.SetData32(0x1044, 0x500);
+
+ auto info = this->eh_frame_->GetFdeInfoFromIndex(2);
+ ASSERT_TRUE(info != nullptr);
+ EXPECT_EQ(0x344U, info->pc);
+ EXPECT_EQ(0x500U, info->offset);
+
+ // Clear the memory so that this will fail if it doesn't read cached data.
+ this->memory_.Clear();
+
+ info = this->eh_frame_->GetFdeInfoFromIndex(2);
+ ASSERT_TRUE(info != nullptr);
+ EXPECT_EQ(0x344U, info->pc);
+ EXPECT_EQ(0x500U, info->offset);
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetBinary_verify) {
+ this->eh_frame_->TestSetTableEntrySize(0x10);
+ this->eh_frame_->TestSetFdeCount(10);
+
+ typename DwarfEhFrameWithHdr<TypeParam>::FdeInfo info;
+ for (size_t i = 0; i < 10; i++) {
+ info.pc = 0x1000 * (i + 1);
+ info.offset = 0x5000 + i * 0x20;
+ this->eh_frame_->TestSetFdeInfo(i, info);
+ }
+
+ uint64_t fde_offset;
+ EXPECT_FALSE(this->eh_frame_->GetFdeOffsetBinary(0x100, &fde_offset, 10));
+ // Not an error, just not found.
+ ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
+ // Even number of elements.
+ for (size_t i = 0; i < 10; i++) {
+ TypeParam pc = 0x1000 * (i + 1);
+ EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc, &fde_offset, 10)) << "Failed at index " << i;
+ EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
+ EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc + 1, &fde_offset, 10))
+ << "Failed at index " << i;
+ EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
+ EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc + 0xfff, &fde_offset, 10))
+ << "Failed at index " << i;
+ EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
+ }
+ // Odd number of elements.
+ for (size_t i = 0; i < 9; i++) {
+ TypeParam pc = 0x1000 * (i + 1);
+ EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc, &fde_offset, 9)) << "Failed at index " << i;
+ EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
+ EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc + 1, &fde_offset, 9))
+ << "Failed at index " << i;
+ EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
+ EXPECT_TRUE(this->eh_frame_->GetFdeOffsetBinary(pc + 0xfff, &fde_offset, 9))
+ << "Failed at index " << i;
+ EXPECT_EQ(0x5000 + i * 0x20, fde_offset) << "Failed at index " << i;
+ }
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetBinary_index_fail) {
+ this->eh_frame_->TestSetTableEntrySize(0x10);
+ this->eh_frame_->TestSetFdeCount(10);
+
+ uint64_t fde_offset;
+ EXPECT_FALSE(this->eh_frame_->GetFdeOffsetBinary(0x1000, &fde_offset, 10));
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetSequential) {
+ this->eh_frame_->TestSetFdeCount(10);
+ this->eh_frame_->TestSetEntriesDataOffset(0x100);
+ this->eh_frame_->TestSetEntriesEnd(0x2000);
+ this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4);
+
+ this->memory_.SetData32(0x1040, 0x340);
+ this->memory_.SetData32(0x1044, 0x500);
+
+ this->memory_.SetData32(0x1048, 0x440);
+ this->memory_.SetData32(0x104c, 0x600);
+
+ // Verify that if entries is zero, that it fails.
+ uint64_t fde_offset;
+ ASSERT_FALSE(this->eh_frame_->GetFdeOffsetSequential(0x344, &fde_offset));
+ this->eh_frame_->TestSetCurEntriesOffset(0x1040);
+
+ ASSERT_TRUE(this->eh_frame_->GetFdeOffsetSequential(0x344, &fde_offset));
+ EXPECT_EQ(0x500U, fde_offset);
+
+ ASSERT_TRUE(this->eh_frame_->GetFdeOffsetSequential(0x444, &fde_offset));
+ EXPECT_EQ(0x600U, fde_offset);
+
+ // Expect that the data is cached so no more memory reads will occur.
+ this->memory_.Clear();
+ ASSERT_TRUE(this->eh_frame_->GetFdeOffsetSequential(0x444, &fde_offset));
+ EXPECT_EQ(0x600U, fde_offset);
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetSequential_last_element) {
+ this->eh_frame_->TestSetFdeCount(2);
+ this->eh_frame_->TestSetEntriesDataOffset(0x100);
+ this->eh_frame_->TestSetEntriesEnd(0x2000);
+ this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4);
+ this->eh_frame_->TestSetCurEntriesOffset(0x1040);
+
+ this->memory_.SetData32(0x1040, 0x340);
+ this->memory_.SetData32(0x1044, 0x500);
+
+ this->memory_.SetData32(0x1048, 0x440);
+ this->memory_.SetData32(0x104c, 0x600);
+
+ uint64_t fde_offset;
+ ASSERT_TRUE(this->eh_frame_->GetFdeOffsetSequential(0x540, &fde_offset));
+ EXPECT_EQ(0x600U, fde_offset);
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetSequential_end_check) {
+ this->eh_frame_->TestSetFdeCount(2);
+ this->eh_frame_->TestSetEntriesDataOffset(0x100);
+ this->eh_frame_->TestSetEntriesEnd(0x1048);
+ this->eh_frame_->TestSetTableEncoding(DW_EH_PE_udata4);
+
+ this->memory_.SetData32(0x1040, 0x340);
+ this->memory_.SetData32(0x1044, 0x500);
+
+ this->memory_.SetData32(0x1048, 0x440);
+ this->memory_.SetData32(0x104c, 0x600);
+
+ uint64_t fde_offset;
+ ASSERT_FALSE(this->eh_frame_->GetFdeOffsetSequential(0x540, &fde_offset));
+ ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetFromPc_fail_fde_count) {
+ this->eh_frame_->TestSetFdeCount(0);
+
+ uint64_t fde_offset;
+ ASSERT_FALSE(this->eh_frame_->GetFdeOffsetFromPc(0x100, &fde_offset));
+ ASSERT_EQ(DWARF_ERROR_NONE, this->eh_frame_->last_error());
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetFromPc_binary_search) {
+ this->eh_frame_->TestSetTableEntrySize(16);
+ this->eh_frame_->TestSetFdeCount(10);
+
+ typename DwarfEhFrameWithHdr<TypeParam>::FdeInfo info;
+ info.pc = 0x550;
+ info.offset = 0x10500;
+ this->eh_frame_->TestSetFdeInfo(5, info);
+ info.pc = 0x750;
+ info.offset = 0x10700;
+ this->eh_frame_->TestSetFdeInfo(7, info);
+ info.pc = 0x850;
+ info.offset = 0x10800;
+ this->eh_frame_->TestSetFdeInfo(8, info);
+
+ uint64_t fde_offset;
+ ASSERT_TRUE(this->eh_frame_->GetFdeOffsetFromPc(0x800, &fde_offset));
+ EXPECT_EQ(0x10700U, fde_offset);
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeOffsetFromPc_sequential_search) {
+ this->eh_frame_->TestSetFdeCount(10);
+ this->eh_frame_->TestSetTableEntrySize(0);
+
+ typename DwarfEhFrameWithHdr<TypeParam>::FdeInfo info;
+ info.pc = 0x50;
+ info.offset = 0x10000;
+ this->eh_frame_->TestSetFdeInfo(0, info);
+ info.pc = 0x150;
+ info.offset = 0x10100;
+ this->eh_frame_->TestSetFdeInfo(1, info);
+ info.pc = 0x250;
+ info.offset = 0x10200;
+ this->eh_frame_->TestSetFdeInfo(2, info);
+
+ uint64_t fde_offset;
+ ASSERT_TRUE(this->eh_frame_->GetFdeOffsetFromPc(0x200, &fde_offset));
+ EXPECT_EQ(0x10100U, fde_offset);
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetCieFde32) {
+ // CIE 32 information.
+ this->memory_.SetData32(0xf000, 0x100);
+ this->memory_.SetData32(0xf004, 0);
+ this->memory_.SetData8(0xf008, 0x1);
+ this->memory_.SetData8(0xf009, '\0');
+ this->memory_.SetData8(0xf00a, 4);
+ this->memory_.SetData8(0xf00b, 8);
+ this->memory_.SetData8(0xf00c, 0x20);
+
+ // FDE 32 information.
+ this->memory_.SetData32(0x14000, 0x20);
+ this->memory_.SetData32(0x14004, 0x5004);
+ this->memory_.SetData32(0x14008, 0x9000);
+ this->memory_.SetData32(0x1400c, 0x100);
+
+ const DwarfFde* fde = this->eh_frame_->GetFdeFromOffset(0x14000);
+ ASSERT_TRUE(fde != nullptr);
+ EXPECT_EQ(0x14010U, fde->cfa_instructions_offset);
+ EXPECT_EQ(0x14024U, fde->cfa_instructions_end);
+ EXPECT_EQ(0x1d00cU, fde->pc_start);
+ EXPECT_EQ(0x1d10cU, fde->pc_end);
+ EXPECT_EQ(0xf000U, fde->cie_offset);
+ EXPECT_EQ(0U, fde->lsda_address);
+
+ ASSERT_TRUE(fde->cie != nullptr);
+ EXPECT_EQ(1U, fde->cie->version);
+ EXPECT_EQ(DW_EH_PE_sdata4, fde->cie->fde_address_encoding);
+ EXPECT_EQ(DW_EH_PE_omit, fde->cie->lsda_encoding);
+ EXPECT_EQ(0U, fde->cie->segment_size);
+ EXPECT_EQ(1U, fde->cie->augmentation_string.size());
+ EXPECT_EQ('\0', fde->cie->augmentation_string[0]);
+ EXPECT_EQ(0U, fde->cie->personality_handler);
+ EXPECT_EQ(0xf00dU, fde->cie->cfa_instructions_offset);
+ EXPECT_EQ(0xf104U, fde->cie->cfa_instructions_end);
+ EXPECT_EQ(4U, fde->cie->code_alignment_factor);
+ EXPECT_EQ(8, fde->cie->data_alignment_factor);
+ EXPECT_EQ(0x20U, fde->cie->return_address_register);
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetCieFde64) {
+ // CIE 64 information.
+ this->memory_.SetData32(0x6000, 0xffffffff);
+ this->memory_.SetData64(0x6004, 0x100);
+ this->memory_.SetData64(0x600c, 0);
+ this->memory_.SetData8(0x6014, 0x1);
+ this->memory_.SetData8(0x6015, '\0');
+ this->memory_.SetData8(0x6016, 4);
+ this->memory_.SetData8(0x6017, 8);
+ this->memory_.SetData8(0x6018, 0x20);
+
+ // FDE 64 information.
+ this->memory_.SetData32(0x8000, 0xffffffff);
+ this->memory_.SetData64(0x8004, 0x200);
+ this->memory_.SetData64(0x800c, 0x200c);
+ this->memory_.SetData64(0x8014, 0x5000);
+ this->memory_.SetData64(0x801c, 0x300);
+
+ const DwarfFde* fde = this->eh_frame_->GetFdeFromOffset(0x8000);
+ ASSERT_TRUE(fde != nullptr);
+ EXPECT_EQ(0x8024U, fde->cfa_instructions_offset);
+ EXPECT_EQ(0x820cU, fde->cfa_instructions_end);
+ EXPECT_EQ(0xd01cU, fde->pc_start);
+ EXPECT_EQ(0xd31cU, fde->pc_end);
+ EXPECT_EQ(0x6000U, fde->cie_offset);
+ EXPECT_EQ(0U, fde->lsda_address);
+
+ ASSERT_TRUE(fde->cie != nullptr);
+ EXPECT_EQ(1U, fde->cie->version);
+ EXPECT_EQ(DW_EH_PE_sdata8, fde->cie->fde_address_encoding);
+ EXPECT_EQ(DW_EH_PE_omit, fde->cie->lsda_encoding);
+ EXPECT_EQ(0U, fde->cie->segment_size);
+ EXPECT_EQ(1U, fde->cie->augmentation_string.size());
+ EXPECT_EQ('\0', fde->cie->augmentation_string[0]);
+ EXPECT_EQ(0U, fde->cie->personality_handler);
+ EXPECT_EQ(0x6019U, fde->cie->cfa_instructions_offset);
+ EXPECT_EQ(0x610cU, fde->cie->cfa_instructions_end);
+ EXPECT_EQ(4U, fde->cie->code_alignment_factor);
+ EXPECT_EQ(8, fde->cie->data_alignment_factor);
+ EXPECT_EQ(0x20U, fde->cie->return_address_register);
+}
+
+TYPED_TEST_P(DwarfEhFrameWithHdrTest, GetFdeFromPc_fde_not_found) {
+ this->eh_frame_->TestSetTableEntrySize(16);
+ this->eh_frame_->TestSetFdeCount(1);
+
+ typename DwarfEhFrameWithHdr<TypeParam>::FdeInfo info;
+ info.pc = 0x550;
+ info.offset = 0x10500;
+ this->eh_frame_->TestSetFdeInfo(0, info);
+
+ ASSERT_EQ(nullptr, this->eh_frame_->GetFdeFromPc(0x800));
+}
+
+REGISTER_TYPED_TEST_CASE_P(DwarfEhFrameWithHdrTest, Init, GetFdeInfoFromIndex_expect_cache_fail,
+ GetFdeInfoFromIndex_read_pcrel, GetFdeInfoFromIndex_read_datarel,
+ GetFdeInfoFromIndex_cached, GetFdeOffsetBinary_verify,
+ GetFdeOffsetBinary_index_fail, GetFdeOffsetSequential,
+ GetFdeOffsetSequential_last_element, GetFdeOffsetSequential_end_check,
+ GetFdeOffsetFromPc_fail_fde_count, GetFdeOffsetFromPc_binary_search,
+ GetFdeOffsetFromPc_sequential_search, GetCieFde32, GetCieFde64,
+ GetFdeFromPc_fde_not_found);
+
+typedef ::testing::Types<uint32_t, uint64_t> DwarfEhFrameWithHdrTestTypes;
+INSTANTIATE_TYPED_TEST_CASE_P(, DwarfEhFrameWithHdrTest, DwarfEhFrameWithHdrTestTypes);
+
+} // namespace unwindstack
diff --git a/libunwindstack/tests/DwarfSectionImplTest.cpp b/libunwindstack/tests/DwarfSectionImplTest.cpp
index 5b9f3ee..d54b0bf 100644
--- a/libunwindstack/tests/DwarfSectionImplTest.cpp
+++ b/libunwindstack/tests/DwarfSectionImplTest.cpp
@@ -42,16 +42,16 @@
MOCK_METHOD1(GetFdeFromIndex, const DwarfFde*(size_t));
- MOCK_METHOD1(IsCie32, bool(uint32_t));
-
- MOCK_METHOD1(IsCie64, bool(uint64_t));
-
MOCK_METHOD1(GetCieOffsetFromFde32, uint64_t(uint32_t));
MOCK_METHOD1(GetCieOffsetFromFde64, uint64_t(uint64_t));
MOCK_METHOD1(AdjustPcFromFde, uint64_t(uint64_t));
+ void TestSetCie32Value(uint32_t value32) { this->cie32_value_ = value32; }
+
+ void TestSetCie64Value(uint64_t value64) { this->cie64_value_ = value64; }
+
void TestSetCachedCieEntry(uint64_t offset, const DwarfCie& cie) {
this->cie_entries_[offset] = cie;
}
@@ -77,6 +77,8 @@
memory_.Clear();
section_ = new MockDwarfSectionImpl<TypeParam>(&memory_);
ResetLogs();
+ section_->TestSetCie32Value(static_cast<uint32_t>(-1));
+ section_->TestSetCie64Value(static_cast<uint64_t>(-1));
}
void TearDown() override { delete section_; }
@@ -448,8 +450,6 @@
this->memory_.SetData8(0x500b, 8);
this->memory_.SetData8(0x500c, 0x20);
- EXPECT_CALL(*this->section_, IsCie32(0xffffffff)).WillRepeatedly(::testing::Return(true));
-
const DwarfCie* cie = this->section_->GetCie(0x5000);
ASSERT_TRUE(cie != nullptr);
EXPECT_EQ(1U, cie->version);
@@ -493,8 +493,6 @@
this->memory_.SetMemory(0x500b, std::vector<uint8_t>{0xfc, 0xff, 0xff, 0xff, 0x7f});
this->memory_.SetData8(0x5010, 0x20);
- EXPECT_CALL(*this->section_, IsCie32(0xffffffff)).WillRepeatedly(::testing::Return(true));
-
const DwarfCie* cie = this->section_->GetCie(0x5000);
ASSERT_TRUE(cie != nullptr);
EXPECT_EQ(1U, cie->version);
@@ -514,15 +512,13 @@
TYPED_TEST_P(DwarfSectionImplTest, GetCie_64_no_augment) {
this->memory_.SetData32(0x8000, 0xffffffff);
this->memory_.SetData64(0x8004, 0x200);
- this->memory_.SetData64(0x800c, 0xffffffff);
+ this->memory_.SetData64(0x800c, 0xffffffffffffffffULL);
this->memory_.SetData8(0x8014, 0x1);
this->memory_.SetData8(0x8015, '\0');
this->memory_.SetData8(0x8016, 4);
this->memory_.SetData8(0x8017, 8);
this->memory_.SetData8(0x8018, 0x20);
- EXPECT_CALL(*this->section_, IsCie64(0xffffffff)).WillRepeatedly(::testing::Return(true));
-
const DwarfCie* cie = this->section_->GetCie(0x8000);
ASSERT_TRUE(cie != nullptr);
EXPECT_EQ(1U, cie->version);
@@ -557,8 +553,6 @@
// R data.
this->memory_.SetData8(0x5018, DW_EH_PE_udata2);
- EXPECT_CALL(*this->section_, IsCie32(0xffffffff)).WillRepeatedly(::testing::Return(true));
-
const DwarfCie* cie = this->section_->GetCie(0x5000);
ASSERT_TRUE(cie != nullptr);
EXPECT_EQ(1U, cie->version);
@@ -588,8 +582,6 @@
this->memory_.SetData8(0x500b, 8);
this->memory_.SetMemory(0x500c, std::vector<uint8_t>{0x81, 0x03});
- EXPECT_CALL(*this->section_, IsCie32(0xffffffff)).WillRepeatedly(::testing::Return(true));
-
const DwarfCie* cie = this->section_->GetCie(0x5000);
ASSERT_TRUE(cie != nullptr);
EXPECT_EQ(3U, cie->version);
@@ -617,8 +609,6 @@
this->memory_.SetData8(0x500d, 8);
this->memory_.SetMemory(0x500e, std::vector<uint8_t>{0x81, 0x03});
- EXPECT_CALL(*this->section_, IsCie32(0xffffffff)).WillRepeatedly(::testing::Return(true));
-
const DwarfCie* cie = this->section_->GetCie(0x5000);
ASSERT_TRUE(cie != nullptr);
EXPECT_EQ(4U, cie->version);
@@ -649,7 +639,6 @@
this->memory_.SetData32(0x4008, 0x5000);
this->memory_.SetData32(0x400c, 0x100);
- EXPECT_CALL(*this->section_, IsCie32(0x8000)).WillOnce(::testing::Return(false));
EXPECT_CALL(*this->section_, GetCieOffsetFromFde32(0x8000)).WillOnce(::testing::Return(0x8000));
DwarfCie cie{};
cie.fde_address_encoding = DW_EH_PE_udata4;
@@ -673,7 +662,6 @@
this->memory_.SetData32(0x4018, 0x5000);
this->memory_.SetData32(0x401c, 0x100);
- EXPECT_CALL(*this->section_, IsCie32(0x8000)).WillOnce(::testing::Return(false));
EXPECT_CALL(*this->section_, GetCieOffsetFromFde32(0x8000)).WillOnce(::testing::Return(0x8000));
DwarfCie cie{};
cie.fde_address_encoding = DW_EH_PE_udata4;
@@ -700,7 +688,6 @@
this->memory_.SetMemory(0x4010, std::vector<uint8_t>{0x82, 0x01});
this->memory_.SetData16(0x4012, 0x1234);
- EXPECT_CALL(*this->section_, IsCie32(0x8000)).WillOnce(::testing::Return(false));
EXPECT_CALL(*this->section_, GetCieOffsetFromFde32(0x8000)).WillOnce(::testing::Return(0x8000));
DwarfCie cie{};
cie.fde_address_encoding = DW_EH_PE_udata4;
@@ -727,7 +714,6 @@
this->memory_.SetData32(0x4014, 0x5000);
this->memory_.SetData32(0x4018, 0x100);
- EXPECT_CALL(*this->section_, IsCie64(0x12345678)).WillOnce(::testing::Return(false));
EXPECT_CALL(*this->section_, GetCieOffsetFromFde64(0x12345678))
.WillOnce(::testing::Return(0x12345678));
DwarfCie cie{};
diff --git a/libunwindstack/tests/ElfInterfaceTest.cpp b/libunwindstack/tests/ElfInterfaceTest.cpp
index 2752e99..e138c3a 100644
--- a/libunwindstack/tests/ElfInterfaceTest.cpp
+++ b/libunwindstack/tests/ElfInterfaceTest.cpp
@@ -910,8 +910,32 @@
memory_.SetMemory(offset, &shdr, sizeof(shdr));
offset += ehdr.e_shentsize;
+ memset(&shdr, 0, sizeof(shdr));
+ shdr.sh_type = SHT_PROGBITS;
+ shdr.sh_link = 2;
+ shdr.sh_name = 0x300;
+ shdr.sh_addr = 0x7000;
+ shdr.sh_offset = 0x7000;
+ shdr.sh_entsize = 0x100;
+ shdr.sh_size = 0x800;
+ memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ offset += ehdr.e_shentsize;
+
+ memset(&shdr, 0, sizeof(shdr));
+ shdr.sh_type = SHT_PROGBITS;
+ shdr.sh_link = 2;
+ shdr.sh_name = 0x400;
+ shdr.sh_addr = 0x6000;
+ shdr.sh_offset = 0xa000;
+ shdr.sh_entsize = 0x100;
+ shdr.sh_size = 0xf00;
+ memory_.SetMemory(offset, &shdr, sizeof(shdr));
+ offset += ehdr.e_shentsize;
+
memory_.SetMemory(0xf100, ".debug_frame", sizeof(".debug_frame"));
memory_.SetMemory(0xf200, ".gnu_debugdata", sizeof(".gnu_debugdata"));
+ memory_.SetMemory(0xf300, ".eh_frame", sizeof(".eh_frame"));
+ memory_.SetMemory(0xf400, ".eh_frame_hdr", sizeof(".eh_frame_hdr"));
uint64_t load_bias = 0;
ASSERT_TRUE(elf->Init(&load_bias));
@@ -920,6 +944,10 @@
EXPECT_EQ(0x500U, elf->debug_frame_size());
EXPECT_EQ(0x5000U, elf->gnu_debugdata_offset());
EXPECT_EQ(0x800U, elf->gnu_debugdata_size());
+ EXPECT_EQ(0x7000U, elf->eh_frame_offset());
+ EXPECT_EQ(0x800U, elf->eh_frame_size());
+ EXPECT_EQ(0xa000U, elf->eh_frame_hdr_offset());
+ EXPECT_EQ(0xf00U, elf->eh_frame_hdr_size());
}
TEST_F(ElfInterfaceTest, init_section_headers_offsets32) {
diff --git a/libvndksupport/linker.c b/libvndksupport/linker.c
index 696e978..bc5620b 100644
--- a/libvndksupport/linker.c
+++ b/libvndksupport/linker.c
@@ -21,26 +21,46 @@
#define LOG_TAG "vndksupport"
#include <log/log.h>
-extern struct android_namespace_t* android_get_exported_namespace(const char*);
+__attribute__((weak)) extern struct android_namespace_t* android_get_exported_namespace(const char*);
+__attribute__((weak)) extern void* android_dlopen_ext(const char*, int, const android_dlextinfo*);
+
+static const char* namespace_name = NULL;
+
+static struct android_namespace_t* get_vendor_namespace() {
+ const char* namespace_names[] = {"sphal", "default", NULL};
+ static struct android_namespace_t* vendor_namespace = NULL;
+ if (vendor_namespace == NULL) {
+ int name_idx = 0;
+ while (namespace_names[name_idx] != NULL) {
+ if (android_get_exported_namespace != NULL) {
+ vendor_namespace = android_get_exported_namespace(namespace_names[name_idx]);
+ }
+ if (vendor_namespace != NULL) {
+ namespace_name = namespace_names[name_idx];
+ break;
+ }
+ name_idx++;
+ }
+ }
+ return vendor_namespace;
+}
void* android_load_sphal_library(const char* name, int flag) {
- struct android_namespace_t* sphal_namespace = android_get_exported_namespace("sphal");
- if (sphal_namespace != NULL) {
+ struct android_namespace_t* vendor_namespace = get_vendor_namespace();
+ if (vendor_namespace != NULL) {
const android_dlextinfo dlextinfo = {
- .flags = ANDROID_DLEXT_USE_NAMESPACE, .library_namespace = sphal_namespace,
+ .flags = ANDROID_DLEXT_USE_NAMESPACE, .library_namespace = vendor_namespace,
};
- void* handle = android_dlopen_ext(name, flag, &dlextinfo);
+ void* handle = NULL;
+ if (android_dlopen_ext != NULL) {
+ handle = android_dlopen_ext(name, flag, &dlextinfo);
+ }
if (!handle) {
- ALOGE(
- "Could not load %s from sphal namespace: %s. ",
- name, dlerror());
+ ALOGE("Could not load %s from %s namespace: %s.", name, namespace_name, dlerror());
}
return handle;
} else {
- ALOGI(
- "sphal namespace is not configured for this process. "
- "Loading %s from the current namespace instead.",
- name);
+ ALOGD("Loading %s from current namespace instead of sphal namespace.", name);
return dlopen(name, flag);
}
}
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp
index 7498325..43362fb 100644
--- a/logd/LogBuffer.cpp
+++ b/logd/LogBuffer.cpp
@@ -212,13 +212,19 @@
if (log_id != LOG_ID_SECURITY) {
int prio = ANDROID_LOG_INFO;
const char* tag = nullptr;
+ size_t tag_len = 0;
if (log_id == LOG_ID_EVENTS) {
tag = tagToName(elem->getTag());
+ if (tag) {
+ tag_len = strlen(tag);
+ }
} else {
prio = *msg;
tag = msg + 1;
+ tag_len = strnlen(tag, len - 1);
}
- if (!__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE)) {
+ if (!__android_log_is_loggable_len(prio, tag, tag_len,
+ ANDROID_LOG_VERBOSE)) {
// Log traffic received to total
wrlock();
stats.addTotal(elem);
diff --git a/logd/LogListener.cpp b/logd/LogListener.cpp
index d2df68e..fcf2cd8 100644
--- a/logd/LogListener.cpp
+++ b/logd/LogListener.cpp
@@ -43,9 +43,10 @@
name_set = true;
}
+ // + 1 to ensure null terminator if MAX_PAYLOAD buffer is received
char buffer[sizeof_log_id_t + sizeof(uint16_t) + sizeof(log_time) +
- LOGGER_ENTRY_MAX_PAYLOAD];
- struct iovec iov = { buffer, sizeof(buffer) };
+ LOGGER_ENTRY_MAX_PAYLOAD + 1];
+ struct iovec iov = { buffer, sizeof(buffer) - 1 };
alignas(4) char control[CMSG_SPACE(sizeof(struct ucred))];
struct msghdr hdr = {
@@ -55,13 +56,16 @@
int socket = cli->getSocket();
// To clear the entire buffer is secure/safe, but this contributes to 1.68%
- // overhead under logging load. We are safe because we check counts.
+ // overhead under logging load. We are safe because we check counts, but
+ // still need to clear null terminator
// memset(buffer, 0, sizeof(buffer));
ssize_t n = recvmsg(socket, &hdr, 0);
if (n <= (ssize_t)(sizeof(android_log_header_t))) {
return false;
}
+ buffer[n] = 0;
+
struct ucred* cred = NULL;
struct cmsghdr* cmsg = CMSG_FIRSTHDR(&hdr);
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 96eb6f3..ca7b991 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -430,6 +430,7 @@
mkdir /data/misc/vold 0700 root root
mkdir /data/misc/boottrace 0771 system shell
mkdir /data/misc/update_engine 0700 root root
+ mkdir /data/misc/update_engine_log 02750 root log
mkdir /data/misc/trace 0700 root root
# profile file layout
mkdir /data/misc/profiles 0771 system system