Replace NULL with nullptr

(cherry picked from commit 851135bf99)

Change-Id: Ic4997907680db7472ef38ffb0f0ca66fff37b797
This commit is contained in:
Dmitriy Ivanov 2014-08-29 12:02:36 -07:00
parent 5dfe802d0d
commit cfad7ae934
7 changed files with 168 additions and 168 deletions

View File

@ -162,12 +162,12 @@ static void log_signal_summary(int signum, const siginfo_t* info) {
thread_name[MAX_TASK_NAME_LEN] = 0;
}
// "info" will be NULL if the siginfo_t information was not available.
// "info" will be null if the siginfo_t information was not available.
// Many signals don't have an address or a code.
char code_desc[32]; // ", code -6"
char addr_desc[32]; // ", fault addr 0x1234"
addr_desc[0] = code_desc[0] = 0;
if (info != NULL) {
if (info != nullptr) {
// For a rethrown signal, this si_code will be right and the one debuggerd shows will
// always be SI_TKILL.
__libc_format_buffer(code_desc, sizeof(code_desc), ", code %d", info->si_code);
@ -198,7 +198,7 @@ static bool have_siginfo(int signum) {
}
bool result = (old_action.sa_flags & SA_SIGINFO) != 0;
if (sigaction(signum, &old_action, NULL) == -1) {
if (sigaction(signum, &old_action, nullptr) == -1) {
__libc_format_log(ANDROID_LOG_WARN, "libc", "Restore failed in test for SA_SIGINFO: %s",
strerror(errno));
}
@ -230,7 +230,7 @@ static void send_debuggerd_packet(siginfo_t* info) {
msg.action = DEBUGGER_ACTION_CRASH;
msg.tid = gettid();
msg.abort_msg_address = reinterpret_cast<uintptr_t>(g_abort_message);
msg.original_si_code = (info != NULL) ? info->si_code : 0;
msg.original_si_code = (info != nullptr) ? info->si_code : 0;
int ret = TEMP_FAILURE_RETRY(write(s, &msg, sizeof(msg)));
if (ret == sizeof(msg)) {
char debuggerd_ack;
@ -255,7 +255,7 @@ static void debuggerd_signal_handler(int signal_number, siginfo_t* info, void*)
// It's possible somebody cleared the SA_SIGINFO flag, which would mean
// our "info" arg holds an undefined value.
if (!have_siginfo(signal_number)) {
info = NULL;
info = nullptr;
}
log_signal_summary(signal_number, info);
@ -296,14 +296,14 @@ __LIBC_HIDDEN__ void debuggerd_init() {
// Use the alternate signal stack if available so we can catch stack overflows.
action.sa_flags |= SA_ONSTACK;
sigaction(SIGABRT, &action, NULL);
sigaction(SIGBUS, &action, NULL);
sigaction(SIGFPE, &action, NULL);
sigaction(SIGILL, &action, NULL);
sigaction(SIGPIPE, &action, NULL);
sigaction(SIGSEGV, &action, NULL);
sigaction(SIGABRT, &action, nullptr);
sigaction(SIGBUS, &action, nullptr);
sigaction(SIGFPE, &action, nullptr);
sigaction(SIGILL, &action, nullptr);
sigaction(SIGPIPE, &action, nullptr);
sigaction(SIGSEGV, &action, nullptr);
#if defined(SIGSTKFLT)
sigaction(SIGSTKFLT, &action, NULL);
sigaction(SIGSTKFLT, &action, nullptr);
#endif
sigaction(SIGTRAP, &action, NULL);
sigaction(SIGTRAP, &action, nullptr);
}

View File

@ -42,7 +42,7 @@ static const char* __bionic_set_dlerror(char* new_value) {
static void __bionic_format_dlerror(const char* msg, const char* detail) {
char* buffer = __get_thread()->dlerror_buffer;
strlcpy(buffer, msg, __BIONIC_DLERROR_BUFFER_SIZE);
if (detail != NULL) {
if (detail != nullptr) {
strlcat(buffer, ": ", __BIONIC_DLERROR_BUFFER_SIZE);
strlcat(buffer, detail, __BIONIC_DLERROR_BUFFER_SIZE);
}
@ -51,7 +51,7 @@ static void __bionic_format_dlerror(const char* msg, const char* detail) {
}
const char* dlerror() {
const char* old_value = __bionic_set_dlerror(NULL);
const char* old_value = __bionic_set_dlerror(nullptr);
return old_value;
}
@ -68,9 +68,9 @@ void android_update_LD_LIBRARY_PATH(const char* ld_library_path) {
static void* dlopen_ext(const char* filename, int flags, const android_dlextinfo* extinfo) {
ScopedPthreadMutexLocker locker(&g_dl_mutex);
soinfo* result = do_dlopen(filename, flags, extinfo);
if (result == NULL) {
if (result == nullptr) {
__bionic_format_dlerror("dlopen failed", linker_get_error_buffer());
return NULL;
return nullptr;
}
return result;
}
@ -80,33 +80,33 @@ void* android_dlopen_ext(const char* filename, int flags, const android_dlextinf
}
void* dlopen(const char* filename, int flags) {
return dlopen_ext(filename, flags, NULL);
return dlopen_ext(filename, flags, nullptr);
}
void* dlsym(void* handle, const char* symbol) {
ScopedPthreadMutexLocker locker(&g_dl_mutex);
#if !defined(__LP64__)
if (handle == NULL) {
__bionic_format_dlerror("dlsym library handle is null", NULL);
return NULL;
if (handle == nullptr) {
__bionic_format_dlerror("dlsym library handle is null", nullptr);
return nullptr;
}
#endif
if (symbol == NULL) {
__bionic_format_dlerror("dlsym symbol name is null", NULL);
return NULL;
if (symbol == nullptr) {
__bionic_format_dlerror("dlsym symbol name is null", nullptr);
return nullptr;
}
soinfo* found = NULL;
ElfW(Sym)* sym = NULL;
soinfo* found = nullptr;
ElfW(Sym)* sym = nullptr;
if (handle == RTLD_DEFAULT) {
sym = dlsym_linear_lookup(symbol, &found, NULL);
sym = dlsym_linear_lookup(symbol, &found, nullptr);
} else if (handle == RTLD_NEXT) {
void* caller_addr = __builtin_return_address(0);
soinfo* si = find_containing_library(caller_addr);
sym = NULL;
sym = nullptr;
if (si && si->next) {
sym = dlsym_linear_lookup(symbol, &found, si->next);
}
@ -114,7 +114,7 @@ void* dlsym(void* handle, const char* symbol) {
sym = dlsym_handle_lookup(reinterpret_cast<soinfo*>(handle), &found, symbol);
}
if (sym != NULL) {
if (sym != nullptr) {
unsigned bind = ELF_ST_BIND(sym->st_info);
if ((bind == STB_GLOBAL || bind == STB_WEAK) && sym->st_shndx != 0) {
@ -122,10 +122,10 @@ void* dlsym(void* handle, const char* symbol) {
}
__bionic_format_dlerror("symbol found but not global", symbol);
return NULL;
return nullptr;
} else {
__bionic_format_dlerror("undefined symbol", symbol);
return NULL;
return nullptr;
}
}
@ -134,7 +134,7 @@ int dladdr(const void* addr, Dl_info* info) {
// Determine if this address can be found in any library currently mapped.
soinfo* si = find_containing_library(addr);
if (si == NULL) {
if (si == nullptr) {
return 0;
}
@ -146,7 +146,7 @@ int dladdr(const void* addr, Dl_info* info) {
// Determine if any symbol in the library contains the specified address.
ElfW(Sym)* sym = dladdr_find_symbol(si, addr);
if (sym != NULL) {
if (sym != nullptr) {
info->dli_sname = si->strtab + sym->st_name;
info->dli_saddr = reinterpret_cast<void*>(si->load_bias + sym->st_value);
}
@ -164,7 +164,7 @@ int dlclose(void* handle) {
// name_offset: starting index of the name in libdl_info.strtab
#define ELF32_SYM_INITIALIZER(name_offset, value, shndx) \
{ name_offset, \
reinterpret_cast<Elf32_Addr>(reinterpret_cast<void*>(value)), \
reinterpret_cast<Elf32_Addr>(value), \
/* st_size */ 0, \
(shndx == 0) ? 0 : (STB_GLOBAL << 4), \
/* st_other */ 0, \
@ -176,7 +176,7 @@ int dlclose(void* handle) {
(shndx == 0) ? 0 : (STB_GLOBAL << 4), \
/* st_other */ 0, \
shndx, \
reinterpret_cast<Elf64_Addr>(reinterpret_cast<void*>(value)), \
reinterpret_cast<Elf64_Addr>(value), \
/* st_size */ 0, \
}
@ -199,7 +199,7 @@ static ElfW(Sym) g_libdl_symtab[] = {
// This is actually the STH_UNDEF entry. Technically, it's
// supposed to have st_name == 0, but instead, it points to an index
// in the strtab with a \0 to make iterating through the symtab easier.
ELFW(SYM_INITIALIZER)(sizeof(ANDROID_LIBDL_STRTAB) - 1, NULL, 0),
ELFW(SYM_INITIALIZER)(sizeof(ANDROID_LIBDL_STRTAB) - 1, nullptr, 0),
ELFW(SYM_INITIALIZER)( 0, &dlopen, 1),
ELFW(SYM_INITIALIZER)( 7, &dlclose, 1),
ELFW(SYM_INITIALIZER)( 15, &dlsym, 1),

View File

@ -97,7 +97,7 @@ static const char* const kDefaultLdPaths[] = {
"/vendor/lib",
"/system/lib",
#endif
NULL
nullptr
};
#define LDPATH_BUFSIZE (LDPATH_MAX*64)
@ -116,7 +116,7 @@ static soinfo* g_ld_preloads[LDPRELOAD_MAX + 1];
__LIBC_HIDDEN__ int g_ld_debug_verbosity;
__LIBC_HIDDEN__ abort_msg_t* g_abort_message = NULL; // For debuggerd.
__LIBC_HIDDEN__ abort_msg_t* g_abort_message = nullptr; // For debuggerd.
enum RelocationKind {
kRelocAbsolute = 0,
@ -189,7 +189,7 @@ size_t linker_get_error_buffer_size() {
extern "C" void __attribute__((noinline)) __attribute__((visibility("default"))) rtld_db_dlactivity();
static pthread_mutex_t g__r_debug_mutex = PTHREAD_MUTEX_INITIALIZER;
static r_debug _r_debug = {1, NULL, reinterpret_cast<uintptr_t>(&rtld_db_dlactivity), r_debug::RT_CONSISTENT, 0};
static r_debug _r_debug = {1, nullptr, reinterpret_cast<uintptr_t>(&rtld_db_dlactivity), r_debug::RT_CONSISTENT, 0};
static link_map* r_debug_tail = 0;
static void insert_soinfo_into_debug_map(soinfo* info) {
@ -288,7 +288,7 @@ static void protect_data(int protection) {
static soinfo* soinfo_alloc(const char* name, struct stat* file_stat) {
if (strlen(name) >= SOINFO_NAME_LEN) {
DL_ERR("library name \"%s\" too long", name);
return NULL;
return nullptr;
}
soinfo* si = new (g_soinfo_allocator.alloc()) soinfo(name, file_stat);
@ -301,7 +301,7 @@ static soinfo* soinfo_alloc(const char* name, struct stat* file_stat) {
}
static void soinfo_free(soinfo* si) {
if (si == NULL) {
if (si == nullptr) {
return;
}
@ -309,16 +309,16 @@ static void soinfo_free(soinfo* si) {
munmap(reinterpret_cast<void*>(si->base), si->size);
}
soinfo *prev = NULL, *trav;
soinfo *prev = nullptr, *trav;
TRACE("name %s: freeing soinfo @ %p", si->name, si);
for (trav = solist; trav != NULL; trav = trav->next) {
for (trav = solist; trav != nullptr; trav = trav->next) {
if (trav == si)
break;
prev = trav;
}
if (trav == NULL) {
if (trav == nullptr) {
/* si was not in solist */
DL_ERR("name \"%s\" is not in solist!", si->name);
return;
@ -327,7 +327,7 @@ static void soinfo_free(soinfo* si) {
// clear links to/from si
si->remove_all_links();
/* prev will never be NULL, because the first entry in solist is
/* prev will never be null, because the first entry in solist is
always the static libdl_info.
*/
prev->next = si->next;
@ -341,7 +341,7 @@ static void soinfo_free(soinfo* si) {
static void parse_path(const char* path, const char* delimiters,
const char** array, char* buf, size_t buf_size, size_t max_count) {
if (path == NULL) {
if (path == nullptr) {
return;
}
@ -358,9 +358,9 @@ static void parse_path(const char* path, const char* delimiters,
// Forget the last path if we had to truncate; this occurs if the 2nd to
// last char isn't '\0' (i.e. wasn't originally a delimiter).
if (i > 0 && len >= buf_size && buf[buf_size - 2] != '\0') {
array[i - 1] = NULL;
array[i - 1] = nullptr;
} else {
array[i] = NULL;
array[i] = nullptr;
}
}
@ -396,7 +396,7 @@ _Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
}
}
*pcount = 0;
return NULL;
return nullptr;
}
#endif
@ -405,7 +405,7 @@ _Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
* loaded libraries. gcc_eh does the rest. */
int dl_iterate_phdr(int (*cb)(dl_phdr_info* info, size_t size, void* data), void* data) {
int rv = 0;
for (soinfo* si = solist; si != NULL; si = si->next) {
for (soinfo* si = solist; si != nullptr; si = si->next) {
dl_phdr_info dl_info;
dl_info.dlpi_addr = si->link_map_head.l_addr;
dl_info.dlpi_name = si->link_map_head.l_name;
@ -454,7 +454,7 @@ static ElfW(Sym)* soinfo_elf_lookup(soinfo* si, unsigned hash, const char* name)
name, si->name, reinterpret_cast<void*>(si->base), hash, hash % si->nbucket);
return NULL;
return nullptr;
}
soinfo::soinfo(const char* name, const struct stat* file_stat) {
@ -464,7 +464,7 @@ soinfo::soinfo(const char* name, const struct stat* file_stat) {
flags = FLAG_NEW_SOINFO;
version = SOINFO_VERSION;
if (file_stat != NULL) {
if (file_stat != nullptr) {
set_st_dev(file_stat->st_dev);
set_st_ino(file_stat->st_ino);
}
@ -511,9 +511,9 @@ static unsigned elfhash(const char* _name) {
static ElfW(Sym)* soinfo_do_lookup(soinfo* si, const char* name, soinfo** lsi, soinfo* needed[]) {
unsigned elf_hash = elfhash(name);
ElfW(Sym)* s = NULL;
ElfW(Sym)* s = nullptr;
if (si != NULL && somain != NULL) {
if (si != nullptr && somain != nullptr) {
/*
* Local scope is executable scope. Just start looking into it right away
* for the shortcut.
@ -521,7 +521,7 @@ static ElfW(Sym)* soinfo_do_lookup(soinfo* si, const char* name, soinfo** lsi, s
if (si == somain) {
s = soinfo_elf_lookup(si, elf_hash, name);
if (s != NULL) {
if (s != nullptr) {
*lsi = si;
goto done;
}
@ -547,7 +547,7 @@ static ElfW(Sym)* soinfo_do_lookup(soinfo* si, const char* name, soinfo** lsi, s
DEBUG("%s: looking up %s in executable %s",
si->name, name, somain->name);
s = soinfo_elf_lookup(somain, elf_hash, name);
if (s != NULL) {
if (s != nullptr) {
*lsi = somain;
goto done;
}
@ -573,7 +573,7 @@ static ElfW(Sym)* soinfo_do_lookup(soinfo* si, const char* name, soinfo** lsi, s
* Here we return the first definition found for simplicity. */
s = soinfo_elf_lookup(si, elf_hash, name);
if (s != NULL) {
if (s != nullptr) {
*lsi = si;
goto done;
}
@ -587,7 +587,7 @@ static ElfW(Sym)* soinfo_do_lookup(soinfo* si, const char* name, soinfo** lsi, s
DEBUG("%s: looking up %s in executable %s after local scope",
si->name, name, somain->name);
s = soinfo_elf_lookup(somain, elf_hash, name);
if (s != NULL) {
if (s != nullptr) {
*lsi = somain;
goto done;
}
@ -604,18 +604,18 @@ static ElfW(Sym)* soinfo_do_lookup(soinfo* si, const char* name, soinfo** lsi, s
}
}
for (int i = 0; needed[i] != NULL; i++) {
for (int i = 0; needed[i] != nullptr; i++) {
DEBUG("%s: looking up %s in %s",
si->name, name, needed[i]->name);
s = soinfo_elf_lookup(needed[i], elf_hash, name);
if (s != NULL) {
if (s != nullptr) {
*lsi = needed[i];
goto done;
}
}
done:
if (s != NULL) {
if (s != nullptr) {
TRACE_TYPE(LOOKUP, "si %s sym %s s->st_value = %p, "
"found in %s, base = %p, load bias = %p",
si->name, name, reinterpret_cast<void*>(s->st_value),
@ -624,7 +624,7 @@ done:
return s;
}
return NULL;
return nullptr;
}
// Another soinfo list allocator to use in dlsym. We don't reuse
@ -677,20 +677,20 @@ ElfW(Sym)* dlsym_handle_lookup(soinfo* si, soinfo** found, const char* name) {
ElfW(Sym)* dlsym_linear_lookup(const char* name, soinfo** found, soinfo* start) {
unsigned elf_hash = elfhash(name);
if (start == NULL) {
if (start == nullptr) {
start = solist;
}
ElfW(Sym)* s = NULL;
for (soinfo* si = start; (s == NULL) && (si != NULL); si = si->next) {
ElfW(Sym)* s = nullptr;
for (soinfo* si = start; (s == nullptr) && (si != nullptr); si = si->next) {
s = soinfo_elf_lookup(si, elf_hash, name);
if (s != NULL) {
if (s != nullptr) {
*found = si;
break;
}
}
if (s != NULL) {
if (s != nullptr) {
TRACE_TYPE(LOOKUP, "%s s->st_value = %p, found->base = %p",
name, reinterpret_cast<void*>(s->st_value), reinterpret_cast<void*>((*found)->base));
}
@ -700,12 +700,12 @@ ElfW(Sym)* dlsym_linear_lookup(const char* name, soinfo** found, soinfo* start)
soinfo* find_containing_library(const void* p) {
ElfW(Addr) address = reinterpret_cast<ElfW(Addr)>(p);
for (soinfo* si = solist; si != NULL; si = si->next) {
for (soinfo* si = solist; si != nullptr; si = si->next) {
if (address >= si->base && address - si->base < si->size) {
return si;
}
}
return NULL;
return nullptr;
}
ElfW(Sym)* dladdr_find_symbol(soinfo* si, const void* addr) {
@ -722,12 +722,12 @@ ElfW(Sym)* dladdr_find_symbol(soinfo* si, const void* addr) {
}
}
return NULL;
return nullptr;
}
static int open_library_on_path(const char* name, const char* const paths[]) {
char buf[512];
for (size_t i = 0; paths[i] != NULL; ++i) {
for (size_t i = 0; paths[i] != nullptr; ++i) {
int n = __libc_format_buffer(buf, sizeof(buf), "%s/%s", paths[i], name);
if (n < 0 || n >= static_cast<int>(sizeof(buf))) {
PRINT("Warning: ignoring very long library path: %s/%s", paths[i], name);
@ -745,7 +745,7 @@ static int open_library(const char* name) {
TRACE("[ opening %s ]", name);
// If the name contains a slash, we should attempt to open it directly and not search the paths.
if (strchr(name, '/') != NULL) {
if (strchr(name, '/') != nullptr) {
int fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_CLOEXEC));
if (fd != -1) {
return fd;
@ -768,14 +768,14 @@ static soinfo* load_library(const char* name, int dlflags, const android_dlextin
int fd = -1;
ScopedFd file_guard(-1);
if (extinfo != NULL && (extinfo->flags & ANDROID_DLEXT_USE_LIBRARY_FD) != 0) {
if (extinfo != nullptr && (extinfo->flags & ANDROID_DLEXT_USE_LIBRARY_FD) != 0) {
fd = extinfo->library_fd;
} else {
// Open the file.
fd = open_library(name);
if (fd == -1) {
DL_ERR("library \"%s\" not found", name);
return NULL;
return nullptr;
}
file_guard.reset(fd);
@ -786,12 +786,12 @@ static soinfo* load_library(const char* name, int dlflags, const android_dlextin
struct stat file_stat;
if (TEMP_FAILURE_RETRY(fstat(fd, &file_stat)) != 0) {
DL_ERR("unable to stat file for the library %s: %s", name, strerror(errno));
return NULL;
return nullptr;
}
// Check for symlink and other situations where
// file can have different names.
for (soinfo* si = solist; si != NULL; si = si->next) {
for (soinfo* si = solist; si != nullptr; si = si->next) {
if (si->get_st_dev() != 0 &&
si->get_st_ino() != 0 &&
si->get_st_dev() == file_stat.st_dev &&
@ -802,17 +802,17 @@ static soinfo* load_library(const char* name, int dlflags, const android_dlextin
}
if ((dlflags & RTLD_NOLOAD) != 0) {
return NULL;
return nullptr;
}
// Read the ELF header and load the segments.
if (!elf_reader.Load(extinfo)) {
return NULL;
return nullptr;
}
soinfo* si = soinfo_alloc(SEARCH_NAME(name), &file_stat);
if (si == NULL) {
return NULL;
if (si == nullptr) {
return nullptr;
}
si->base = elf_reader.load_start();
si->size = elf_reader.load_size();
@ -827,7 +827,7 @@ static soinfo* load_library(const char* name, int dlflags, const android_dlextin
if (!soinfo_link_image(si, extinfo)) {
soinfo_free(si);
return NULL;
return nullptr;
}
return si;
@ -835,16 +835,16 @@ static soinfo* load_library(const char* name, int dlflags, const android_dlextin
static soinfo *find_loaded_library_by_name(const char* name) {
const char* search_name = SEARCH_NAME(name);
for (soinfo* si = solist; si != NULL; si = si->next) {
for (soinfo* si = solist; si != nullptr; si = si->next) {
if (!strcmp(search_name, si->name)) {
return si;
}
}
return NULL;
return nullptr;
}
static soinfo* find_library_internal(const char* name, int dlflags, const android_dlextinfo* extinfo) {
if (name == NULL) {
if (name == nullptr) {
return somain;
}
@ -852,14 +852,14 @@ static soinfo* find_library_internal(const char* name, int dlflags, const androi
// Library might still be loaded, the accurate detection
// of this fact is done by load_library
if (si == NULL) {
if (si == nullptr) {
TRACE("[ '%s' has not been found by name. Trying harder...]", name);
si = load_library(name, dlflags, extinfo);
}
if (si != NULL && (si->flags & FLAG_LINKED) == 0) {
if (si != nullptr && (si->flags & FLAG_LINKED) == 0) {
DL_ERR("recursive link to \"%s\"", si->name);
return NULL;
return nullptr;
}
return si;
@ -867,7 +867,7 @@ static soinfo* find_library_internal(const char* name, int dlflags, const androi
static soinfo* find_library(const char* name, int dlflags, const android_dlextinfo* extinfo) {
soinfo* si = find_library_internal(name, dlflags, extinfo);
if (si != NULL) {
if (si != nullptr) {
si->ref_count++;
}
return si;
@ -888,8 +888,8 @@ static void soinfo_unload(soinfo* si) {
if (d->d_tag == DT_NEEDED) {
const char* library_name = si->strtab + d->d_un.d_val;
TRACE("%s needs to unload %s", si->name, library_name);
soinfo* needed = find_library(library_name, RTLD_NOLOAD, NULL);
if (needed != NULL) {
soinfo* needed = find_library(library_name, RTLD_NOLOAD, nullptr);
if (needed != nullptr) {
soinfo_unload(needed);
} else {
// Not found: for example if symlink was deleted between dlopen and dlclose
@ -936,15 +936,15 @@ void do_android_update_LD_LIBRARY_PATH(const char* ld_library_path) {
soinfo* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo) {
if ((flags & ~(RTLD_NOW|RTLD_LAZY|RTLD_LOCAL|RTLD_GLOBAL|RTLD_NOLOAD)) != 0) {
DL_ERR("invalid flags to dlopen: %x", flags);
return NULL;
return nullptr;
}
if (extinfo != NULL && ((extinfo->flags & ~(ANDROID_DLEXT_VALID_FLAG_BITS)) != 0)) {
if (extinfo != nullptr && ((extinfo->flags & ~(ANDROID_DLEXT_VALID_FLAG_BITS)) != 0)) {
DL_ERR("invalid extended flags to android_dlopen_ext: %" PRIx64, extinfo->flags);
return NULL;
return nullptr;
}
protect_data(PROT_READ | PROT_WRITE);
soinfo* si = find_library(name, flags, extinfo);
if (si != NULL) {
if (si != nullptr) {
si->CallConstructors();
}
protect_data(PROT_READ);
@ -967,7 +967,7 @@ static void soinfo_ifunc_relocate(soinfo* si, ElfW(Rel)* rel, unsigned count, so
unsigned sym = ELFW(R_SYM)(rel->r_info);
ElfW(Addr) reloc = static_cast<ElfW(Addr)>(rel->r_offset + si->load_bias);
ElfW(Addr) sym_addr = 0;
const char* sym_name = NULL;
const char* sym_name = nullptr;
sym_name = reinterpret_cast<const char*>(si->strtab + si->symtab[sym].st_name);
s = soinfo_do_lookup(si, sym_name, &lsi, needed);
@ -990,7 +990,7 @@ static void soinfo_ifunc_relocate(soinfo* si, ElfW(Rela)* rela, unsigned count,
unsigned sym = ELFW(R_SYM)(rela->r_info);
ElfW(Addr) reloc = static_cast<ElfW(Addr)>(rela->r_offset + si->load_bias);
ElfW(Addr) sym_addr = 0;
const char* sym_name = NULL;
const char* sym_name = nullptr;
sym_name = reinterpret_cast<const char*>(si->strtab + si->symtab[sym].st_name);
s = soinfo_do_lookup(si, sym_name, &lsi, needed);
@ -1014,7 +1014,7 @@ static int soinfo_relocate(soinfo* si, ElfW(Rela)* rela, unsigned count, soinfo*
unsigned sym = ELFW(R_SYM)(rela->r_info);
ElfW(Addr) reloc = static_cast<ElfW(Addr)>(rela->r_offset + si->load_bias);
ElfW(Addr) sym_addr = 0;
const char* sym_name = NULL;
const char* sym_name = nullptr;
DEBUG("Processing '%s' relocation at index %zd", si->name, idx);
if (type == 0) { // R_*_NONE
@ -1023,7 +1023,7 @@ static int soinfo_relocate(soinfo* si, ElfW(Rela)* rela, unsigned count, soinfo*
if (sym != 0) {
sym_name = reinterpret_cast<const char*>(si->strtab + si->symtab[sym].st_name);
s = soinfo_do_lookup(si, sym_name, &lsi, needed);
if (s == NULL) {
if (s == nullptr) {
// We only allow an undefined symbol if this is a weak reference...
s = &si->symtab[sym];
if (ELF_ST_BIND(s->st_info) != STB_WEAK) {
@ -1079,7 +1079,7 @@ static int soinfo_relocate(soinfo* si, ElfW(Rela)* rela, unsigned count, soinfo*
}
count_relocation(kRelocSymbol);
} else {
s = NULL;
s = nullptr;
}
switch (type) {
@ -1283,7 +1283,7 @@ static int soinfo_relocate(soinfo* si, ElfW(Rel)* rel, unsigned count, soinfo* n
unsigned sym = ELFW(R_SYM)(rel->r_info);
ElfW(Addr) reloc = static_cast<ElfW(Addr)>(rel->r_offset + si->load_bias);
ElfW(Addr) sym_addr = 0;
const char* sym_name = NULL;
const char* sym_name = nullptr;
DEBUG("Processing '%s' relocation at index %zd", si->name, idx);
if (type == 0) { // R_*_NONE
@ -1292,7 +1292,7 @@ static int soinfo_relocate(soinfo* si, ElfW(Rel)* rel, unsigned count, soinfo* n
if (sym != 0) {
sym_name = reinterpret_cast<const char*>(si->strtab + si->symtab[sym].st_name);
s = soinfo_do_lookup(si, sym_name, &lsi, needed);
if (s == NULL) {
if (s == nullptr) {
// We only allow an undefined symbol if this is a weak reference...
s = &si->symtab[sym];
if (ELF_ST_BIND(s->st_info) != STB_WEAK) {
@ -1351,7 +1351,7 @@ static int soinfo_relocate(soinfo* si, ElfW(Rel)* rel, unsigned count, soinfo* n
}
count_relocation(kRelocSymbol);
} else {
s = NULL;
s = nullptr;
}
switch (type) {
@ -1476,7 +1476,7 @@ static int soinfo_relocate(soinfo* si, ElfW(Rel)* rel, unsigned count, soinfo* n
#if defined(__mips__)
static bool mips_relocate_got(soinfo* si, soinfo* needed[]) {
ElfW(Addr)** got = si->plt_got;
if (got == NULL) {
if (got == nullptr) {
return true;
}
unsigned local_gotno = si->mips_local_gotno;
@ -1508,7 +1508,7 @@ static bool mips_relocate_got(soinfo* si, soinfo* needed[]) {
const char* sym_name = si->strtab + sym->st_name;
soinfo* lsi;
ElfW(Sym)* s = soinfo_do_lookup(si, sym_name, &lsi, needed);
if (s == NULL) {
if (s == nullptr) {
// We only allow an undefined symbol if this is a weak reference.
s = &symtab[g];
if (ELF_ST_BIND(s->st_info) != STB_WEAK) {
@ -1528,7 +1528,7 @@ static bool mips_relocate_got(soinfo* si, soinfo* needed[]) {
#endif
void soinfo::CallArray(const char* array_name __unused, linker_function_t* functions, size_t count, bool reverse) {
if (functions == NULL) {
if (functions == nullptr) {
return;
}
@ -1547,7 +1547,7 @@ void soinfo::CallArray(const char* array_name __unused, linker_function_t* funct
}
void soinfo::CallFunction(const char* function_name __unused, linker_function_t function) {
if (function == NULL || reinterpret_cast<uintptr_t>(function) == static_cast<uintptr_t>(-1)) {
if (function == nullptr || reinterpret_cast<uintptr_t>(function) == static_cast<uintptr_t>(-1)) {
return;
}
@ -1583,7 +1583,7 @@ void soinfo::CallConstructors() {
// out above, the libc constructor will be called again (recursively!).
constructors_called = true;
if ((flags & FLAG_EXE) == 0 && preinit_array != NULL) {
if ((flags & FLAG_EXE) == 0 && preinit_array != nullptr) {
// The GNU dynamic linker silently ignores these, but we warn the developer.
PRINT("\"%s\": ignoring %zd-entry DT_PREINIT_ARRAY in shared library!",
name, preinit_array_count);
@ -1779,7 +1779,7 @@ static bool soinfo_link_image(soinfo* si, const android_dlextinfo* extinfo) {
ElfW(Word) dynamic_flags;
phdr_table_get_dynamic_section(phdr, phnum, base, &si->dynamic,
&dynamic_count, &dynamic_flags);
if (si->dynamic == NULL) {
if (si->dynamic == nullptr) {
if (!relocating_linker) {
DL_ERR("missing PT_DYNAMIC in \"%s\"", si->name);
}
@ -1997,9 +1997,9 @@ static bool soinfo_link_image(soinfo* si, const android_dlextinfo* extinfo) {
if (si->flags & FLAG_EXE) {
memset(g_ld_preloads, 0, sizeof(g_ld_preloads));
size_t preload_count = 0;
for (size_t i = 0; g_ld_preload_names[i] != NULL; i++) {
soinfo* lsi = find_library(g_ld_preload_names[i], 0, NULL);
if (lsi != NULL) {
for (size_t i = 0; g_ld_preload_names[i] != nullptr; i++) {
soinfo* lsi = find_library(g_ld_preload_names[i], 0, nullptr);
if (lsi != nullptr) {
g_ld_preloads[preload_count++] = lsi;
} else {
// As with glibc, failure to load an LD_PRELOAD library is just a warning.
@ -2016,8 +2016,8 @@ static bool soinfo_link_image(soinfo* si, const android_dlextinfo* extinfo) {
if (d->d_tag == DT_NEEDED) {
const char* library_name = si->strtab + d->d_un.d_val;
DEBUG("%s needs %s", si->name, library_name);
soinfo* lsi = find_library(library_name, 0, NULL);
if (lsi == NULL) {
soinfo* lsi = find_library(library_name, 0, nullptr);
if (lsi == nullptr) {
strlcpy(tmp_err_buf, linker_get_error_buffer(), sizeof(tmp_err_buf));
DL_ERR("could not load library \"%s\" needed by \"%s\"; caused by %s",
library_name, si->name, tmp_err_buf);
@ -2028,7 +2028,7 @@ static bool soinfo_link_image(soinfo* si, const android_dlextinfo* extinfo) {
*pneeded++ = lsi;
}
}
*pneeded = NULL;
*pneeded = nullptr;
#if !defined(__LP64__)
if (si->has_text_relocations) {
@ -2045,26 +2045,26 @@ static bool soinfo_link_image(soinfo* si, const android_dlextinfo* extinfo) {
#endif
#if defined(USE_RELA)
if (si->plt_rela != NULL) {
if (si->plt_rela != nullptr) {
DEBUG("[ relocating %s plt ]\n", si->name);
if (soinfo_relocate(si, si->plt_rela, si->plt_rela_count, needed)) {
return false;
}
}
if (si->rela != NULL) {
if (si->rela != nullptr) {
DEBUG("[ relocating %s ]\n", si->name);
if (soinfo_relocate(si, si->rela, si->rela_count, needed)) {
return false;
}
}
#else
if (si->plt_rel != NULL) {
if (si->plt_rel != nullptr) {
DEBUG("[ relocating %s plt ]", si->name);
if (soinfo_relocate(si, si->plt_rel, si->plt_rel_count, needed)) {
return false;
}
}
if (si->rel != NULL) {
if (si->rel != nullptr) {
DEBUG("[ relocating %s ]", si->name);
if (soinfo_relocate(si, si->rel, si->rel_count, needed)) {
return false;
@ -2140,11 +2140,11 @@ static bool soinfo_link_image(soinfo* si, const android_dlextinfo* extinfo) {
static void add_vdso(KernelArgumentBlock& args __unused) {
#if defined(AT_SYSINFO_EHDR)
ElfW(Ehdr)* ehdr_vdso = reinterpret_cast<ElfW(Ehdr)*>(args.getauxval(AT_SYSINFO_EHDR));
if (ehdr_vdso == NULL) {
if (ehdr_vdso == nullptr) {
return;
}
soinfo* si = soinfo_alloc("[vdso]", NULL);
soinfo* si = soinfo_alloc("[vdso]", nullptr);
si->phdr = reinterpret_cast<ElfW(Phdr)*>(reinterpret_cast<char*>(ehdr_vdso) + ehdr_vdso->e_phoff);
si->phnum = ehdr_vdso->e_phnum;
@ -2152,7 +2152,7 @@ static void add_vdso(KernelArgumentBlock& args __unused) {
si->size = phdr_table_get_load_size(si->phdr, si->phnum);
si->load_bias = get_elf_exec_load_bias(ehdr_vdso);
soinfo_link_image(si, NULL);
soinfo_link_image(si, nullptr);
#endif
}
@ -2185,7 +2185,7 @@ static void init_linker_info_for_gdb(ElfW(Addr) linker_base) {
ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(linker_base);
ElfW(Phdr)* phdr = reinterpret_cast<ElfW(Phdr)*>(linker_base + elf_hdr->e_phoff);
phdr_table_get_dynamic_section(phdr, elf_hdr->e_phnum, linker_base,
&linker_soinfo_for_gdb.dynamic, NULL, NULL);
&linker_soinfo_for_gdb.dynamic, nullptr, nullptr);
insert_soinfo_into_debug_map(&linker_soinfo_for_gdb);
}
@ -2213,14 +2213,14 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
// Get a few environment variables.
const char* LD_DEBUG = linker_env_get("LD_DEBUG");
if (LD_DEBUG != NULL) {
if (LD_DEBUG != nullptr) {
g_ld_debug_verbosity = atoi(LD_DEBUG);
}
// Normally, these are cleaned by linker_env_init, but the test
// doesn't cost us anything.
const char* ldpath_env = NULL;
const char* ldpreload_env = NULL;
const char* ldpath_env = nullptr;
const char* ldpreload_env = nullptr;
if (!get_AT_SECURE()) {
ldpath_env = linker_env_get("LD_LIBRARY_PATH");
ldpreload_env = linker_env_get("LD_PRELOAD");
@ -2228,8 +2228,8 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
INFO("[ android linker & debugger ]");
soinfo* si = soinfo_alloc(args.argv[0], NULL);
if (si == NULL) {
soinfo* si = soinfo_alloc(args.argv[0], nullptr);
if (si == nullptr) {
exit(EXIT_FAILURE);
}
@ -2239,8 +2239,8 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
map->l_addr = 0;
map->l_name = args.argv[0];
map->l_prev = NULL;
map->l_next = NULL;
map->l_prev = nullptr;
map->l_next = nullptr;
_r_debug.r_map = map;
r_debug_tail = map;
@ -2266,7 +2266,7 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
break;
}
}
si->dynamic = NULL;
si->dynamic = nullptr;
si->ref_count = 1;
ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(si->base);
@ -2281,7 +2281,7 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
somain = si;
if (!soinfo_link_image(si, NULL)) {
if (!soinfo_link_image(si, nullptr)) {
__libc_format_fd(2, "CANNOT LINK EXECUTABLE: %s\n", linker_get_error_buffer());
exit(EXIT_FAILURE);
}
@ -2290,7 +2290,7 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
si->CallPreInitConstructors();
for (size_t i = 0; g_ld_preloads[i] != NULL; ++i) {
for (size_t i = 0; g_ld_preloads[i] != nullptr; ++i) {
g_ld_preloads[i]->CallConstructors();
}
@ -2303,7 +2303,7 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
si->CallConstructors();
#if TIMING
gettimeofday(&t1, NULL);
gettimeofday(&t1, nullptr);
PRINT("LINKER TIME: %s: %d microseconds", args.argv[0], (int) (
(((long long)t1.tv_sec * 1000000LL) + (long long)t1.tv_usec) -
(((long long)t0.tv_sec * 1000000LL) + (long long)t0.tv_usec)));
@ -2404,12 +2404,12 @@ extern "C" ElfW(Addr) __linker_init(void* raw_args) {
linker_so.base = linker_addr;
linker_so.size = phdr_table_get_load_size(phdr, elf_hdr->e_phnum);
linker_so.load_bias = get_elf_exec_load_bias(elf_hdr);
linker_so.dynamic = NULL;
linker_so.dynamic = nullptr;
linker_so.phdr = phdr;
linker_so.phnum = elf_hdr->e_phnum;
linker_so.flags |= FLAG_LINKER;
if (!soinfo_link_image(&linker_so, NULL)) {
if (!soinfo_link_image(&linker_so, nullptr)) {
// It would be nice to print an error message, but if the linker
// can't link itself, there's no guarantee that we'll be able to
// call write() (because it involves a GOT reference). We may as

View File

@ -58,7 +58,7 @@ static void __init_AT_SECURE(KernelArgumentBlock& args) {
// Check if the environment variable definition at 'envstr'
// starts with '<name>=', and if so return the address of the
// first character after the equal sign. Otherwise return NULL.
// first character after the equal sign. Otherwise return null.
static const char* env_match(const char* envstr, const char* name) {
size_t i = 0;
@ -70,7 +70,7 @@ static const char* env_match(const char* envstr, const char* name) {
return envstr + i + 1;
}
return NULL;
return nullptr;
}
static bool __is_valid_environment_variable(const char* name) {
@ -78,7 +78,7 @@ static bool __is_valid_environment_variable(const char* name) {
// as the maximum size for an env. variable definition.
const int MAX_ENV_LEN = 32*4096;
if (name == NULL) {
if (name == nullptr) {
return false;
}
@ -136,10 +136,10 @@ static bool __is_unsafe_environment_variable(const char* name) {
"RES_OPTIONS",
"TMPDIR",
"TZDIR",
NULL
nullptr
};
for (size_t i = 0; UNSAFE_VARIABLE_NAMES[i] != NULL; ++i) {
if (env_match(name, UNSAFE_VARIABLE_NAMES[i]) != NULL) {
for (size_t i = 0; UNSAFE_VARIABLE_NAMES[i] != nullptr; ++i) {
if (env_match(name, UNSAFE_VARIABLE_NAMES[i]) != nullptr) {
return true;
}
}
@ -149,7 +149,7 @@ static bool __is_unsafe_environment_variable(const char* name) {
static void __sanitize_environment_variables() {
char** src = _envp;
char** dst = _envp;
for (; src[0] != NULL; ++src) {
for (; src[0] != nullptr; ++src) {
if (!__is_valid_environment_variable(src[0])) {
continue;
}
@ -160,11 +160,11 @@ static void __sanitize_environment_variables() {
dst[0] = src[0];
++dst;
}
dst[0] = NULL;
dst[0] = nullptr;
}
void linker_env_init(KernelArgumentBlock& args) {
// Store environment pointer - can't be NULL.
// Store environment pointer - can't be null.
_envp = args.envp;
__init_AT_SECURE(args);
@ -172,18 +172,18 @@ void linker_env_init(KernelArgumentBlock& args) {
}
const char* linker_env_get(const char* name) {
if (name == NULL || name[0] == '\0') {
return NULL;
if (name == nullptr || name[0] == '\0') {
return nullptr;
}
for (char** p = _envp; p[0] != NULL; ++p) {
for (char** p = _envp; p[0] != nullptr; ++p) {
const char* val = env_match(p[0], name);
if (val != NULL) {
if (val != nullptr) {
if (val[0] == '\0') {
return NULL; // Return NULL for empty strings.
return nullptr; // Return null for empty strings.
}
return val;
}
}
return NULL;
return nullptr;
}

View File

@ -35,7 +35,7 @@ class KernelArgumentBlock;
extern void linker_env_init(KernelArgumentBlock& args);
// Returns the value of environment variable 'name' if defined and not
// empty, or NULL otherwise.
// empty, or null otherwise.
extern const char* linker_env_get(const char* name);
// Returns the value of this program's AT_SECURE variable.

View File

@ -121,13 +121,13 @@
ElfReader::ElfReader(const char* name, int fd)
: name_(name), fd_(fd),
phdr_num_(0), phdr_mmap_(NULL), phdr_table_(NULL), phdr_size_(0),
load_start_(NULL), load_size_(0), load_bias_(0),
loaded_phdr_(NULL) {
phdr_num_(0), phdr_mmap_(nullptr), phdr_table_(nullptr), phdr_size_(0),
load_start_(nullptr), load_size_(0), load_bias_(0),
loaded_phdr_(nullptr) {
}
ElfReader::~ElfReader() {
if (phdr_mmap_ != NULL) {
if (phdr_mmap_ != nullptr) {
munmap(phdr_mmap_, phdr_size_);
}
}
@ -225,7 +225,7 @@ bool ElfReader::ReadProgramHeader() {
phdr_size_ = page_max - page_min;
void* mmap_result = mmap(NULL, phdr_size_, PROT_READ, MAP_PRIVATE, fd_, page_min);
void* mmap_result = mmap(nullptr, phdr_size_, PROT_READ, MAP_PRIVATE, fd_, page_min);
if (mmap_result == MAP_FAILED) {
DL_ERR("\"%s\" phdr mmap failed: %s", name_, strerror(errno));
return false;
@ -242,7 +242,7 @@ bool ElfReader::ReadProgramHeader() {
* process' address space. If there are no loadable segments, 0 is
* returned.
*
* If out_min_vaddr or out_max_vaddr are non-NULL, they will be
* If out_min_vaddr or out_max_vaddr are not null, they will be
* set to the minimum and maximum addresses of pages to be reserved,
* or 0 if there is nothing to load.
*/
@ -276,10 +276,10 @@ size_t phdr_table_get_load_size(const ElfW(Phdr)* phdr_table, size_t phdr_count,
min_vaddr = PAGE_START(min_vaddr);
max_vaddr = PAGE_END(max_vaddr);
if (out_min_vaddr != NULL) {
if (out_min_vaddr != nullptr) {
*out_min_vaddr = min_vaddr;
}
if (out_max_vaddr != NULL) {
if (out_max_vaddr != nullptr) {
*out_max_vaddr = max_vaddr;
}
return max_vaddr - min_vaddr;
@ -301,7 +301,7 @@ bool ElfReader::ReserveAddressSpace(const android_dlextinfo* extinfo) {
size_t reserved_size = 0;
bool reserved_hint = true;
if (extinfo != NULL) {
if (extinfo != nullptr) {
if (extinfo->flags & ANDROID_DLEXT_RESERVED_ADDRESS) {
reserved_size = extinfo->reserved_size;
reserved_hint = false;
@ -585,9 +585,9 @@ int phdr_table_map_gnu_relro(const ElfW(Phdr)* phdr_table, size_t phdr_count, El
return -1;
}
off_t file_size = file_stat.st_size;
void* temp_mapping = NULL;
void* temp_mapping = nullptr;
if (file_size > 0) {
temp_mapping = mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
temp_mapping = mmap(nullptr, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (temp_mapping == MAP_FAILED) {
return -1;
}
@ -667,7 +667,7 @@ int phdr_table_map_gnu_relro(const ElfW(Phdr)* phdr_table, size_t phdr_count, El
* phdr_count -> number of entries in tables
* load_bias -> load bias
* Output:
* arm_exidx -> address of table in memory (NULL on failure).
* arm_exidx -> address of table in memory (null on failure).
* arm_exidx_count -> number of items in table (0 on failure).
* Return:
* 0 on error, -1 on failure (_no_ error code in errno)
@ -687,21 +687,21 @@ int phdr_table_get_arm_exidx(const ElfW(Phdr)* phdr_table, size_t phdr_count,
*arm_exidx_count = (unsigned)(phdr->p_memsz / 8);
return 0;
}
*arm_exidx = NULL;
*arm_exidx = nullptr;
*arm_exidx_count = 0;
return -1;
}
#endif
/* Return the address and size of the ELF file's .dynamic section in memory,
* or NULL if missing.
* or null if missing.
*
* Input:
* phdr_table -> program header table
* phdr_count -> number of entries in tables
* load_bias -> load bias
* Output:
* dynamic -> address of table in memory (NULL on failure).
* dynamic -> address of table in memory (null on failure).
* dynamic_count -> number of items in table (0 on failure).
* dynamic_flags -> protection flags for section (unset on failure)
* Return:
@ -727,7 +727,7 @@ void phdr_table_get_dynamic_section(const ElfW(Phdr)* phdr_table, size_t phdr_co
}
return;
}
*dynamic = NULL;
*dynamic = nullptr;
if (dynamic_count) {
*dynamic_count = 0;
}

View File

@ -81,7 +81,7 @@ class ElfReader {
};
size_t phdr_table_get_load_size(const ElfW(Phdr)* phdr_table, size_t phdr_count,
ElfW(Addr)* min_vaddr = NULL, ElfW(Addr)* max_vaddr = NULL);
ElfW(Addr)* min_vaddr = nullptr, ElfW(Addr)* max_vaddr = nullptr);
int phdr_table_protect_segments(const ElfW(Phdr)* phdr_table, size_t phdr_count, ElfW(Addr) load_bias);