OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <dlfcn.h> | 5 #include <dlfcn.h> |
6 #include <pthread.h> | 6 #include <pthread.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
11 #include <ppapi/cpp/completion_callback.h> | 11 #include <ppapi/cpp/completion_callback.h> |
12 #include <ppapi/cpp/instance.h> | 12 #include <ppapi/cpp/instance.h> |
13 #include <ppapi/cpp/module.h> | 13 #include <ppapi/cpp/module.h> |
14 #include <ppapi/cpp/var.h> | 14 #include <ppapi/cpp/var.h> |
15 | 15 |
16 #include "eightball.h" | 16 #include "eightball.h" |
17 #include "nacl_io/nacl_io.h" | 17 #include "nacl_io/nacl_io.h" |
18 #include "reverse.h" | 18 #include "reverse.h" |
19 | 19 |
20 #if defined(NACL_SDK_DEBUG) | 20 #if defined(NACL_SDK_DEBUG) |
21 #define CONFIG_NAME "Debug" | 21 #define CONFIG_NAME "Debug" |
22 #else | 22 #else |
23 #define CONFIG_NAME "Release" | 23 #define CONFIG_NAME "Release" |
24 #endif | 24 #endif |
25 | 25 |
26 #define XSTRINGIFY(x) STRINGIFY(x) | 26 #if defined __arm__ |
27 #define STRINGIFY(x) #x | 27 #define NACL_ARCH "arm" |
28 #define NACL_ARCH_STRING XSTRINGIFY(NACL_ARCH) | 28 #elif defined __i686__ |
| 29 #define NACL_ARCH "x86_32" |
| 30 #elif defined __x86_64__ |
| 31 #define NACL_ARCH "x86_64" |
| 32 #else |
| 33 #error "Unknown arch" |
| 34 #endif |
29 | 35 |
30 class DlOpenInstance : public pp::Instance { | 36 class DlOpenInstance : public pp::Instance { |
31 public: | 37 public: |
32 explicit DlOpenInstance(PP_Instance instance) | 38 explicit DlOpenInstance(PP_Instance instance) |
33 : pp::Instance(instance), | 39 : pp::Instance(instance), |
34 eightball_so_(NULL), | 40 eightball_so_(NULL), |
35 reverse_so_(NULL), | 41 reverse_so_(NULL), |
36 eightball_(NULL), | 42 eightball_(NULL), |
37 reverse_(NULL), | 43 reverse_(NULL), |
38 tid_(NULL) {} | 44 tid_(NULL) {} |
(...skipping 20 matching lines...) Expand all Loading... |
59 return false; | 65 return false; |
60 } | 66 } |
61 return true; | 67 return true; |
62 } | 68 } |
63 | 69 |
64 // This function is called on a worker thread, and will call dlopen to load | 70 // This function is called on a worker thread, and will call dlopen to load |
65 // the shared object. In addition, note that this function does NOT call | 71 // the shared object. In addition, note that this function does NOT call |
66 // dlclose, which would close the shared object and unload it from memory. | 72 // dlclose, which would close the shared object and unload it from memory. |
67 void LoadLibrary() { | 73 void LoadLibrary() { |
68 const char reverse_so_path[] = | 74 const char reverse_so_path[] = |
69 "/http/glibc/" CONFIG_NAME "/libreverse_" NACL_ARCH_STRING ".so"; | 75 "/http/glibc/" CONFIG_NAME "/libreverse_" NACL_ARCH ".so"; |
70 const int32_t IMMEDIATELY = 0; | 76 const int32_t IMMEDIATELY = 0; |
71 eightball_so_ = dlopen("libeightball.so", RTLD_LAZY); | 77 eightball_so_ = dlopen("libeightball.so", RTLD_LAZY); |
72 reverse_so_ = dlopen(reverse_so_path, RTLD_LAZY); | 78 reverse_so_ = dlopen(reverse_so_path, RTLD_LAZY); |
73 pp::CompletionCallback cc(LoadDoneCB, this); | 79 pp::CompletionCallback cc(LoadDoneCB, this); |
74 pp::Module::Get()->core()->CallOnMainThread(IMMEDIATELY, cc, 0); | 80 pp::Module::Get()->core()->CallOnMainThread(IMMEDIATELY, cc, 0); |
75 } | 81 } |
76 | 82 |
77 // This function will run on the main thread and use the handle it stored by | 83 // This function will run on the main thread and use the handle it stored by |
78 // the worker thread, assuming it successfully loaded, to get a pointer to the | 84 // the worker thread, assuming it successfully loaded, to get a pointer to the |
79 // message function in the shared object. | 85 // message function in the shared object. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 184 |
179 // Create and return a DlOpenInstance object. | 185 // Create and return a DlOpenInstance object. |
180 virtual pp::Instance* CreateInstance(PP_Instance instance) { | 186 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
181 return new DlOpenInstance(instance); | 187 return new DlOpenInstance(instance); |
182 } | 188 } |
183 }; | 189 }; |
184 | 190 |
185 namespace pp { | 191 namespace pp { |
186 Module* CreateModule() { return new DlOpenModule(); } | 192 Module* CreateModule() { return new DlOpenModule(); } |
187 } // namespace pp | 193 } // namespace pp |
OLD | NEW |