From 1a6961650c82168864afe040dbdc05977db701df Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 1 Nov 2012 13:49:32 -0700 Subject: [PATCH] Stop defining our own PAGE_SIZE and PAGE_MASK, and test dlclose(3) too. Also remove an unnecessary #include and a now-obsolete TODO. Change-Id: I36d923721e349a286934b9534090a67ce0786e7b --- linker/linker.cpp | 2 -- linker/linker.h | 26 ++++++-------------------- tests/dlopen_test.cpp | 6 ++++++ 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/linker/linker.cpp b/linker/linker.cpp index f7f81250c..5c43cd0f4 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -72,8 +72,6 @@ * - cleaner error reporting * - after linking, set as much stuff as possible to READONLY * and NOEXEC - * - linker hardcodes PAGE_SIZE and PAGE_MASK because the kernel - * headers provide versions that are negative... */ diff --git a/linker/linker.h b/linker/linker.h index de83a8c9c..2a6c1cd82 100644 --- a/linker/linker.h +++ b/linker/linker.h @@ -36,25 +36,14 @@ #include -#undef PAGE_MASK -#undef PAGE_SIZE -#define PAGE_SIZE 4096 -#define PAGE_MASK (PAGE_SIZE-1) +// Returns the address of the page containing address 'x'. +#define PAGE_START(x) ((x) & PAGE_MASK) -/* Convenience macros to make page address/offset computations more explicit */ +// Returns the offset of address 'x' in its page. +#define PAGE_OFFSET(x) ((x) & ~PAGE_MASK) -/* Returns the address of the page starting at address 'x' */ -#define PAGE_START(x) ((x) & ~PAGE_MASK) - -/* Returns the offset of address 'x' in its memory page, i.e. this is the - * same than 'x' - PAGE_START(x) */ -#define PAGE_OFFSET(x) ((x) & PAGE_MASK) - -/* Returns the address of the next page after address 'x', unless 'x' is - * itself at the start of a page. Equivalent to: - * - * (x == PAGE_START(x)) ? x : PAGE_START(x)+PAGE_SIZE - */ +// Returns the address of the next page after address 'x', unless 'x' is +// itself at the start of a page. #define PAGE_END(x) PAGE_START((x) + (PAGE_SIZE-1)) void debugger_init(); @@ -167,9 +156,6 @@ struct soinfo { extern soinfo libdl_info; - -#include - #if defined(ANDROID_ARM_LINKER) // These aren't defined in . diff --git a/tests/dlopen_test.cpp b/tests/dlopen_test.cpp index 024df01a2..794fb970c 100644 --- a/tests/dlopen_test.cpp +++ b/tests/dlopen_test.cpp @@ -46,6 +46,8 @@ TEST(dlopen, dlsym_in_self) { gCalled = false; function(); ASSERT_TRUE(gCalled); + + ASSERT_EQ(0, dlclose(self)); } TEST(dlopen, dlopen_failure) { @@ -108,6 +110,8 @@ TEST(dlopen, dlsym_failures) { sym = dlsym(self, "ThisSymbolDoesNotExist"); ASSERT_TRUE(sym == NULL); ASSERT_SUBSTR("undefined symbol: ThisSymbolDoesNotExist", dlerror()); + + ASSERT_EQ(0, dlclose(self)); } TEST(dlopen, dladdr) { @@ -166,6 +170,8 @@ TEST(dlopen, dladdr) { // The base address should be the address we were loaded at. ASSERT_EQ(info.dli_fbase, base_address); + + ASSERT_EQ(0, dlclose(self)); } TEST(dlopen, dladdr_invalid) {