Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: src/untrusted/pnacl_irt_shim/shim_entry.c

Issue 10870109: Change the pnacl shim from doing real shimming to just intercepting (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/untrusted/pnacl_irt_shim/nacl.scons ('k') | src/untrusted/pnacl_irt_shim/shim_ppapi.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. 2 * Copyright 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 <stddef.h>
7 #include "native_client/src/include/elf32.h" 8 #include "native_client/src/include/elf32.h"
8 #include "native_client/src/include/elf_auxv.h" 9 #include "native_client/src/include/elf_auxv.h"
9 #include "native_client/src/include/nacl_macros.h" 10 #include "native_client/src/include/nacl_macros.h"
10 #include "native_client/src/untrusted/pnacl_irt_shim/shim_ppapi.h" 11 #include "native_client/src/untrusted/irt/irt.h"
11 #include "native_client/src/untrusted/nacl/nacl_startup.h" 12 #include "native_client/src/untrusted/nacl/nacl_startup.h"
12 13
14 /*
15 * For more information about this hack cf.
16 * src/untrusted/irt/irt_ppapi.c
17 */
18
19 static TYPE_nacl_irt_query real_irt_interface;
20
21 /* cf. src/untrusted/irt/irt.h NACL_IRT_PPAPIHOOK_(SHIMMED_)v0_1 */
22 static const char prefix_search[] = "nacl-irt-ppapihook";
Mark Seaborn 2012/08/28 19:38:41 This variable is not used. Please remove it. Sam
23 static const char prefix_replace[] = "nacl-irt-ppapihook-shimmed";
24
25 /* Do not make assumptions about strcmp being available. */
26 static int my_strcmp(const char* s1, const char* s2) {
27 while (*s1 != '\0' && *s2 != '\0' && *s1 == *s2) {
28 s1++;
29 s2++;
30 }
31 return *s1 - *s2;
32 }
33
34 static size_t pnacl_irt_interface_interceptor(const char *interface_ident,
35 void *table, size_t tablesize) {
36 if (0 == my_strcmp(interface_ident, NACL_IRT_PPAPIHOOK_v0_1)) {
37 return real_irt_interface(NACL_IRT_PPAPIHOOK_SHIMMED_v0_1, table, tablesize) ;
Mark Seaborn 2012/08/28 19:38:41 This line is >80 chars
38 }
39 return real_irt_interface(ident, table, tablesize);
Mark Seaborn 2012/08/28 19:38:41 'ident' is not defined, so I don't think this comp
40 }
13 41
14 /* 42 /*
15 * This is the true entry point for untrusted code. 43 * This is the true entry point for untrusted code.
16 * See nacl_startup.h for the layout at the argument pointer. 44 * See nacl_startup.h for the layout at the argument pointer.
17 */ 45 */
18 void _pnacl_wrapper_start(uint32_t *info) { 46 void _pnacl_wrapper_start(uint32_t *info) {
19 Elf32_auxv_t *auxv = nacl_startup_auxv(info); 47 Elf32_auxv_t *auxv = nacl_startup_auxv(info);
20 48
21 Elf32_auxv_t *entry = NULL; 49 Elf32_auxv_t *entry = NULL;
22 for (Elf32_auxv_t *av = auxv; av->a_type != AT_NULL; ++av) { 50 for (Elf32_auxv_t *av = auxv; av->a_type != AT_NULL; ++av) {
23 if (av->a_type == AT_SYSINFO) { 51 if (av->a_type == AT_SYSINFO) {
24 entry = av; 52 entry = av;
25 break; 53 break;
26 } 54 }
27 } 55 }
28 56
29 if (entry != NULL) { 57 if (entry != NULL) {
30 /* 58 /*
31 * Save the real irt interface. 59 * Save the real irt interface.
32 */ 60 */
33 __pnacl_real_irt_interface = (TYPE_nacl_irt_query) entry->a_un.a_val; 61 real_irt_interface = (TYPE_nacl_irt_query) entry->a_un.a_val;
34 62
35 /* 63 /*
36 * Overwrite the auxv slot with the pnacl IRT shim query function. 64 * Overwrite the auxv slot with the pnacl IRT shim query function.
37 */ 65 */
38 entry->a_type = AT_SYSINFO; 66 entry->a_type = AT_SYSINFO;
39 entry->a_un.a_val = (uintptr_t) __pnacl_irt_interface_wrapper; 67 entry->a_un.a_val = (uintptr_t) pnacl_irt_interface_interceptor;
40 } 68 }
41 69
42 /* If entry is NULL still allow startup to continue. It may be the case 70 /* If entry is NULL still allow startup to continue. It may be the case
43 * that the IRT was not actually used (e.g., for some commandline tests). 71 * that the IRT was not actually used (e.g., for some commandline tests).
44 * For newlib, we can tell that the IRT isn't used when libnacl_sys_private.a 72 * For newlib, we can tell that the IRT isn't used when libnacl_sys_private.a
45 * is in the bitcode link line. However, glibc does not use 73 * is in the bitcode link line. However, glibc does not use
46 * libnacl_sys_private, so that would not work. We could look for -lppapi 74 * libnacl_sys_private, so that would not work. We could look for -lppapi
47 * in the bitcode link line, but looking at the bitcode link line 75 * in the bitcode link line, but looking at the bitcode link line
48 * seems brittle (what if the bitcode link was separated from translation). 76 * seems brittle (what if the bitcode link was separated from translation).
49 * Thus we always wrap _start, even if there is no IRT auxv entry. 77 * Thus we always wrap _start, even if there is no IRT auxv entry.
50 */ 78 */
51 79
52 /* 80 /*
53 * Call the user entry point function. It should not return. 81 * Call the user entry point function. It should not return.
54 * TODO(sehr): Find a way to ensure this is invoked via a tail call. 82 * TODO(sehr): Find a way to ensure this is invoked via a tail call.
55 */ 83 */
56 _start(info); 84 _start(info);
57 } 85 }
OLDNEW
« no previous file with comments | « src/untrusted/pnacl_irt_shim/nacl.scons ('k') | src/untrusted/pnacl_irt_shim/shim_ppapi.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698