am 416695a7
: Merge "Improve personality initialization"
* commit '416695a75c3892dd709a80ea8a640da07082594e': Improve personality initialization
This commit is contained in:
commit
7830dcf1b5
4 changed files with 19 additions and 9 deletions
|
@ -37,6 +37,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/auxv.h>
|
||||
#include <sys/personality.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -44,6 +45,7 @@
|
|||
#include "private/bionic_ssp.h"
|
||||
#include "private/bionic_tls.h"
|
||||
#include "private/KernelArgumentBlock.h"
|
||||
#include "private/libc_logging.h"
|
||||
#include "pthread_internal.h"
|
||||
|
||||
extern "C" abort_msg_t** __abort_message_ptr;
|
||||
|
@ -289,6 +291,19 @@ static void __sanitize_environment_variables(char** env) {
|
|||
dst[0] = nullptr;
|
||||
}
|
||||
|
||||
static void __initialize_personality() {
|
||||
#if !defined(__LP64__)
|
||||
int old_value = personality(0xffffffff);
|
||||
if (old_value == -1) {
|
||||
__libc_fatal("error getting old personality value: %s", strerror(errno));
|
||||
}
|
||||
|
||||
if (personality((static_cast<unsigned int>(old_value) & ~PER_MASK) | PER_LINUX32) == -1) {
|
||||
__libc_fatal("error setting PER_LINUX32 personality: %s", strerror(errno));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void __libc_init_AT_SECURE(KernelArgumentBlock& args) {
|
||||
__libc_auxv = args.auxv;
|
||||
|
||||
|
@ -312,6 +327,8 @@ void __libc_init_AT_SECURE(KernelArgumentBlock& args) {
|
|||
|
||||
// Now the environment has been sanitized, make it available.
|
||||
environ = args.envp;
|
||||
|
||||
__initialize_personality();
|
||||
}
|
||||
|
||||
/* This function will be called during normal program termination
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
__BEGIN_DECLS
|
||||
|
||||
extern int personality (unsigned long persona);
|
||||
extern int personality (unsigned int persona);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/personality.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <new>
|
||||
|
@ -3181,12 +3180,6 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
|
|||
ldpreload_env = getenv("LD_PRELOAD");
|
||||
}
|
||||
|
||||
#if !defined(__LP64__)
|
||||
if (personality(PER_LINUX32) == -1) {
|
||||
__libc_fatal("error setting PER_LINUX32 personality: %s", strerror(errno));
|
||||
}
|
||||
#endif
|
||||
|
||||
INFO("[ android linker & debugger ]");
|
||||
|
||||
soinfo* si = soinfo_alloc(args.argv[0], nullptr, 0, RTLD_GLOBAL);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <sys/personality.h>
|
||||
|
||||
TEST(sys_personality, current_persona) {
|
||||
int persona = personality(0xffffffff);
|
||||
int persona = personality(0xffffffff) & PER_MASK;
|
||||
#if defined(__BIONIC__)
|
||||
#if defined(__LP64__)
|
||||
ASSERT_EQ(PER_LINUX, persona);
|
||||
|
|
Loading…
Reference in a new issue