Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include "native_client/src/untrusted/pnacl_irt_shim/shim_ppapi.h" | 7 #include "native_client/src/untrusted/pnacl_irt_shim/shim_ppapi.h" |
| 8 | 8 |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include "native_client/src/shared/ppapi_proxy/ppruntime.h" | 10 #include "native_client/src/shared/ppapi_proxy/ppruntime.h" |
| 11 #include "native_client/src/untrusted/irt/irt.h" | 11 #include "native_client/src/untrusted/irt/irt.h" |
| 12 #include "native_client/src/untrusted/irt/irt_ppapi.h" | 12 #include "native_client/src/untrusted/irt/irt_ppapi.h" |
| 13 #include "ppapi/generators/pnacl_shim.h" | |
| 13 | 14 |
| 14 TYPE_nacl_irt_query __pnacl_real_irt_interface; | 15 TYPE_nacl_irt_query __pnacl_real_irt_interface; |
| 15 | 16 |
| 16 /* | 17 /* |
| 17 * These remember the interface pointers the user registers by calling the | 18 * These remember the interface pointers the user registers by calling the |
| 18 * IRT entry point. | 19 * IRT entry point. |
| 19 */ | 20 */ |
| 20 static struct PP_StartFunctions user_start_functions; | 21 static struct PP_StartFunctions user_start_functions; |
| 21 | 22 |
| 22 /* | 23 static int32_t wrap_PPPInitializeModule(PP_Module module_id, |
| 23 * This remembers the interface pointer the IRT passes through | 24 PPB_GetInterface get_browser_intf) { |
| 24 * PPP_InitializeModule. | 25 __set_real_Pnacl_PPBGetInterface(get_browser_intf); |
| 25 */ | 26 return (*user_start_functions.PPP_InitializeModule)(module_id, |
| 26 static const void *(*user_PPBGetInterface)(const char *interface_name); | |
| 27 | |
| 28 | |
| 29 /* | 27 /* |
| 30 * Calls from user code to the PPB interfaces pass through here and may require | 28 * Calls from user code to the PPB interfaces pass through here and may require |
| 31 * shims to convert the ABI. | 29 * shims to convert the ABI. |
| 32 */ | 30 */ |
|
robertm
2011/12/01 22:55:43
moving the comment before the arg is uncommon
jvoung - send to chromium...
2011/12/01 23:35:34
Done.
| |
| 33 static const void *wrap_PPBGetInterface(const char *interface_name) { | 31 &__Pnacl_PPBGetInterface); |
| 34 /* TODO(sehr): call PPB shims here. */ | |
| 35 return (*user_PPBGetInterface)(interface_name); | |
| 36 } | |
| 37 | |
| 38 static int32_t wrap_PPPInitializeModule(PP_Module module_id, | |
| 39 PPB_GetInterface get_browser_intf) { | |
| 40 user_PPBGetInterface = get_browser_intf; | |
| 41 return (*user_start_functions.PPP_InitializeModule)(module_id, | |
| 42 wrap_PPBGetInterface); | |
| 43 } | 32 } |
| 44 | 33 |
| 45 static void wrap_PPPShutdownModule() { | 34 static void wrap_PPPShutdownModule() { |
| 46 (*user_start_functions.PPP_ShutdownModule)(); | 35 (*user_start_functions.PPP_ShutdownModule)(); |
| 47 } | 36 } |
| 48 | 37 |
| 49 /* | |
| 50 * Calls from the IRT to the user plugin pass through here and may require | |
| 51 * shims to convert the ABI. | |
| 52 */ | |
| 53 static const void *wrap_PPPGetInterface(const char *interface_name) { | |
| 54 /* TODO(sehr): call PPP shims here. */ | |
| 55 return (*user_start_functions.PPP_GetInterface)(interface_name); | |
| 56 } | |
| 57 | |
| 58 static const struct PP_StartFunctions wrapped_ppapi_methods = { | 38 static const struct PP_StartFunctions wrapped_ppapi_methods = { |
| 59 wrap_PPPInitializeModule, | 39 wrap_PPPInitializeModule, |
| 60 wrap_PPPShutdownModule, | 40 wrap_PPPShutdownModule, |
| 61 wrap_PPPGetInterface | 41 /* |
| 42 * Calls from the IRT to the user plugin pass through here and may require | |
| 43 * shims to convert the ABI. | |
| 44 */ | |
| 45 __Pnacl_PPPGetInterface | |
| 62 }; | 46 }; |
| 63 | 47 |
| 64 static struct nacl_irt_ppapihook real_irt_ppapi_hook; | 48 static struct nacl_irt_ppapihook real_irt_ppapi_hook; |
| 65 | 49 |
| 66 static int wrap_ppapi_start(const struct PP_StartFunctions *funcs) { | 50 static int wrap_ppapi_start(const struct PP_StartFunctions *funcs) { |
| 67 /* | 51 /* |
| 68 * Save the user's real bindings for the start functions. | 52 * Save the user's real bindings for the start functions. |
| 69 */ | 53 */ |
| 70 user_start_functions = *funcs; | 54 user_start_functions = *funcs; |
| 55 __set_real_Pnacl_PPPGetInterface(user_start_functions.PPP_GetInterface); | |
| 56 | |
| 71 /* | 57 /* |
| 72 * Invoke the IRT's ppapi_start interface with the wrapped interface. | 58 * Invoke the IRT's ppapi_start interface with the wrapped interface. |
| 73 */ | 59 */ |
| 74 return (*real_irt_ppapi_hook.ppapi_start)(&wrapped_ppapi_methods); | 60 return (*real_irt_ppapi_hook.ppapi_start)(&wrapped_ppapi_methods); |
| 75 } | 61 } |
| 76 | 62 |
| 77 static struct nacl_irt_ppapihook ppapi_hook = { | 63 static struct nacl_irt_ppapihook ppapi_hook = { |
| 78 wrap_ppapi_start, | 64 wrap_ppapi_start, |
| 79 NULL | 65 NULL |
| 80 }; | 66 }; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 107 real_irt_ppapi_hook.ppapi_register_thread_creator; | 93 real_irt_ppapi_hook.ppapi_register_thread_creator; |
| 108 /* | 94 /* |
| 109 * Copy the interface structure into the client. | 95 * Copy the interface structure into the client. |
| 110 */ | 96 */ |
| 111 if (sizeof ppapi_hook <= tablesize) { | 97 if (sizeof ppapi_hook <= tablesize) { |
| 112 memcpy(table, &ppapi_hook, sizeof ppapi_hook); | 98 memcpy(table, &ppapi_hook, sizeof ppapi_hook); |
| 113 return sizeof ppapi_hook; | 99 return sizeof ppapi_hook; |
| 114 } | 100 } |
| 115 return 0; | 101 return 0; |
| 116 } | 102 } |
| OLD | NEW |