Caricamento del resto di questo confronto.

Untitled diff

Creato Il diff non scade mai
45 rimozioni
741 linee
168 aggiunte
873 linee
/*
/*
* Copyright (C) 2008, 2009 The Android Open Source Project
* Copyright (C) 2008, 2009 The Android Open Source Project
* All rights reserved.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
* are met:
* are met:
* * Redistributions of source code must retain the above copyright
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* the documentation and/or other materials provided with the
* distribution.
* distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* SUCH DAMAGE.
*/
*/

#include <linux/auxvec.h>
#include <linux/auxvec.h>

#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
#include <fcntl.h>
#include <fcntl.h>
#include <errno.h>
#include <errno.h>
#include <dlfcn.h>
#include <dlfcn.h>
#include <sys/stat.h>
#include <sys/stat.h>

#include <pthread.h>
#include <pthread.h>

#include <sys/mman.h>
#include <sys/mman.h>
#include <sys/atomics.h>

/* special private C library header - see Android.mk */
/* special private C library header - see Android.mk */
#include <bionic_tls.h>
//#include "bionic_tls.h"

#include "linker.h"
#include "linker.h"
#include "linker_debug.h"
#include "linker_debug.h"
#include "linker_environ.h"
#include "linker_environ.h"
#include "linker_format.h"
#include "linker_format.h"

#define ALLOW_SYMBOLS_FROM_MAIN 1
#define ALLOW_SYMBOLS_FROM_MAIN 1
#define SO_MAX 128
#define SO_MAX 128

/* Assume average path length of 64 and max 8 paths */
/* Assume average path length of 64 and max 8 paths */
#define LDPATH_BUFSIZE 512
#define LDPATH_BUFSIZE 512
#define LDPATH_MAX 8
#define LDPATH_MAX 8

#define LDPRELOAD_BUFSIZE 512
#define LDPRELOAD_BUFSIZE 512
#define LDPRELOAD_MAX 8
#define LDPRELOAD_MAX 8

/* >>> IMPORTANT NOTE - READ ME BEFORE MODIFYING <<<
/* >>> IMPORTANT NOTE - READ ME BEFORE MODIFYING <<<
*
*
* Do NOT use malloc() and friends or pthread_*() code here.
* Do NOT use malloc() and friends or pthread_*() code here.
* Don't use printf() either; it's caused mysterious memory
* Don't use printf() either; it's caused mysterious memory
* corruption in the past.
* corruption in the past.
* The linker runs before we bring up libc and it's easiest
* The linker runs before we bring up libc and it's easiest
* to make sure it does not depend on any complex libc features
* to make sure it does not depend on any complex libc features
*
*
* open issues / todo:
* open issues / todo:
*
*
* - are we doing everything we should for ARM_COPY relocations?
* - are we doing everything we should for ARM_COPY relocations?
* - cleaner error reporting
* - cleaner error reporting
* - after linking, set as much stuff as possible to READONLY
* - after linking, set as much stuff as possible to READONLY
* and NOEXEC
* and NOEXEC
* - linker hardcodes PAGE_SIZE and PAGE_MASK because the kernel
* - linker hardcodes PAGE_SIZE and PAGE_MASK because the kernel
* headers provide versions that are negative...
* headers provide versions that are negative...
* - allocate space for soinfo structs dynamically instead of
* - allocate space for soinfo structs dynamically instead of
* having a hard limit (64)
* having a hard limit (64)
*/
*/


static int link_image(soinfo *si, unsigned wr_offset);
static int link_image(soinfo *si, unsigned wr_offset);

static int socount = 0;
static int socount = 0;
static soinfo sopool[SO_MAX];
static soinfo sopool[SO_MAX];
static soinfo *freelist = NULL;
static soinfo *freelist = NULL;
static soinfo *solist = &libdl_info;
static soinfo *solist = &libdl_info;
static soinfo *sonext = &libdl_info;
static soinfo *sonext = &libdl_info;
#if ALLOW_SYMBOLS_FROM_MAIN
#if ALLOW_SYMBOLS_FROM_MAIN
static soinfo *somain; /* main process, always the one after libdl_info */
static soinfo *somain; /* main process, always the one after libdl_info */
#endif
#endif


static inline int validate_soinfo(soinfo *si)
static inline int validate_soinfo(soinfo *si)
{
{
return (si >= sopool && si < sopool + SO_MAX) ||
return (si >= sopool && si < sopool + SO_MAX) ||
si == &libdl_info;
si == &libdl_info;
}
}