2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-01-24 11:56:40 +03:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <elf.h>
|
|
|
|
|
|
|
|
/* The Android NDK headers define those */
|
|
|
|
#undef Elf_Ehdr
|
|
|
|
#undef Elf_Addr
|
|
|
|
|
2013-10-10 17:31:29 +04:00
|
|
|
#if defined(__LP64__)
|
2011-01-24 11:56:40 +03:00
|
|
|
#define Elf_Ehdr Elf64_Ehdr
|
|
|
|
#define Elf_Addr Elf64_Addr
|
2013-10-10 17:31:29 +04:00
|
|
|
#else
|
|
|
|
#define Elf_Ehdr Elf32_Ehdr
|
|
|
|
#define Elf_Addr Elf32_Addr
|
2011-01-24 11:56:40 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
extern __attribute__((visibility("hidden"))) void original_init(int argc, char **argv, char **env);
|
|
|
|
|
|
|
|
extern __attribute__((visibility("hidden"))) Elf32_Rel relhack[];
|
|
|
|
extern __attribute__((visibility("hidden"))) Elf_Ehdr elf_header;
|
|
|
|
|
2013-07-30 03:57:28 +04:00
|
|
|
int init(int argc, char **argv, char **env)
|
2011-01-24 11:56:40 +03:00
|
|
|
{
|
|
|
|
Elf32_Rel *rel;
|
|
|
|
Elf_Addr *ptr, *start;
|
|
|
|
for (rel = relhack; rel->r_offset; rel++) {
|
|
|
|
start = (Elf_Addr *)((intptr_t)&elf_header + rel->r_offset);
|
|
|
|
for (ptr = start; ptr < &start[rel->r_info]; ptr++)
|
|
|
|
*ptr += (intptr_t)&elf_header;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NOINIT
|
|
|
|
original_init(argc, argv, env);
|
|
|
|
#endif
|
2013-07-30 03:57:28 +04:00
|
|
|
// Ensure there is no tail-call optimization, avoiding the use of the
|
|
|
|
// B.W instruction in Thumb for the call above.
|
|
|
|
return 0;
|
2011-01-24 11:56:40 +03:00
|
|
|
}
|