diff options
author | noelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-08 22:44:58 +0000 |
---|---|---|
committer | noelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-08 22:44:58 +0000 |
commit | 52aca5896478c4d407a554a04fce50d8a4549c7e (patch) | |
tree | de8d254ea825c24caf19a79c75700ca2c61209aa /native_client_sdk | |
parent | b59013c239afecc97ad90ca2ee2ef5867aefc645 (diff) | |
download | chromium_src-52aca5896478c4d407a554a04fce50d8a4549c7e.zip chromium_src-52aca5896478c4d407a554a04fce50d8a4549c7e.tar.gz chromium_src-52aca5896478c4d407a554a04fce50d8a4549c7e.tar.bz2 |
[NaCl SDK] Postpone fetching pointers.
Pointers to the irt functions may not be available at link time, they can
be assigned during C library initailization. This changes forces nacl_io
to wait unitl first use, which must happen after the C library has been
initialized.
NOTRY=true
BUG=269756
R=binji@chromium.org
Review URL: https://chromiumcodereview.appspot.com/22407008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216468 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
-rw-r--r-- | native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc | 15 | ||||
-rw-r--r-- | native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc | 19 |
2 files changed, 28 insertions, 6 deletions
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc index 7c52f4d..acc3c58 100644 --- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc +++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc @@ -11,6 +11,7 @@ #include "nacl_io/kernel_wrap.h" #include <alloca.h> +#include <assert.h> #include <dirent.h> #include <errno.h> #include <irt.h> @@ -103,9 +104,14 @@ EXTERN_C_BEGIN // Macro to get the WRAP function #define WRAP(name) __nacl_irt_##name##_wrap -// Declare REAL function pointer and assign it the REAL function. +// Declare REAL function pointer. #define DECLARE_REAL_PTR(name) \ - typeof(__nacl_irt_##name) REAL(name) = __nacl_irt_##name; + typeof(__nacl_irt_##name) REAL(name); + +// Assign the REAL function pointer. +#define ASSIGN_REAL_PTR(name) \ + assert(__nacl_irt_##name != NULL); \ + REAL(name) = __nacl_irt_##name; // Switch IRT's pointer to the REAL pointer #define USE_REAL(name) \ @@ -454,8 +460,13 @@ uint64_t usec_since_epoch() { } static bool s_wrapped = false; +static bool s_assigned = false; void kernel_wrap_init() { if (!s_wrapped) { + if (!s_assigned) { + EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) + s_assigned = true; + } EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) s_wrapped = true; } diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc index e218301..bf2c530 100644 --- a/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc +++ b/native_client_sdk/src/libraries/nacl_io/kernel_wrap_newlib.cc @@ -9,6 +9,7 @@ #if defined(__native_client__) && !defined(__GLIBC__) #include "nacl_io/kernel_wrap.h" +#include <assert.h> #include <dirent.h> #include <errno.h> #include <irt.h> @@ -25,9 +26,14 @@ EXTERN_C_BEGIN // Macro to get the WRAP function #define WRAP(name) __nacl_irt_##name##_wrap -// Declare REAL function pointer and assign it the REAL function. +// Declare REAL function pointer. #define DECLARE_REAL_PTR(group, name) \ - typeof(__libnacl_irt_##group.name) REAL(name) = __libnacl_irt_##group.name; + typeof(__libnacl_irt_##group.name) REAL(name); + +// Assign the REAL function pointer. +#define ASSIGN_REAL_PTR(group, name) \ + assert(__libnacl_irt_##group.name != NULL); \ + REAL(name) = __libnacl_irt_##group.name; // Switch IRT's pointer to the REAL pointer #define USE_REAL(group, name) \ @@ -273,16 +279,21 @@ uint64_t usec_since_epoch() { } static bool s_wrapped = false; +static bool s_assigned = false; void kernel_wrap_init() { if (!s_wrapped) { - EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP); + if (!s_assigned) { + EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) + s_assigned = true; + } + EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) s_wrapped = true; } } void kernel_wrap_uninit() { if (s_wrapped) { - EXPAND_SYMBOL_LIST_OPERATION(USE_REAL); + EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) s_wrapped = false; } } |