Chromium Code Reviews| Index: src/untrusted/pnacl_irt_shim/shim_entry.c |
| =================================================================== |
| --- src/untrusted/pnacl_irt_shim/shim_entry.c (revision 9574) |
| +++ src/untrusted/pnacl_irt_shim/shim_entry.c (working copy) |
| @@ -1,16 +1,63 @@ |
| /* |
| - * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| + * Copyright 2011 The Native Client Authors. All rights reserved. |
|
jvoung (off chromium)
2012/08/27 21:57:39
Is the new copyright header not supposed to have a
Robert Muth (chromium)
2012/08/27 22:38:18
yes, "(c)" is meaningless I was told
|
| * Use of this source code is governed by a BSD-style license that can be |
| * found in the LICENSE file. |
| */ |
| +#include <stddef.h> |
| #include "native_client/src/include/elf32.h" |
| #include "native_client/src/include/elf_auxv.h" |
| #include "native_client/src/include/nacl_macros.h" |
| -#include "native_client/src/untrusted/pnacl_irt_shim/shim_ppapi.h" |
| +#include "native_client/src/untrusted/irt/irt.h" |
| #include "native_client/src/untrusted/nacl/nacl_startup.h" |
| +/* |
| + * For more information about this hack cf. |
| + * src/untrusted/irt/irt_ppapi.c |
| + */ |
| +static TYPE_nacl_irt_query real_irt_interface; |
| + |
| +/* cf. src/untrusted/irt/irt.h NACL_IRT_PPAPIHOOK_(SHIMMED_)v0_1 */ |
| +char prefix_search[] = "nacl-irt-ppapihook"; |
|
jvoung (off chromium)
2012/08/27 21:57:39
static const ?
Robert Muth (chromium)
2012/08/27 22:38:18
Done.
|
| +char prefix_replace[] = "nacl-irt-ppapihook-shimmed"; |
| + |
| +int my_strcmp(const char* s1, const char* s2) { |
|
jvoung (off chromium)
2012/08/27 21:57:39
Comments about why we provide a custom strcmp, str
Robert Muth (chromium)
2012/08/27 22:38:18
Done.
|
| + while( *s1 != '\0' && *s2 != '\0' && *s1 == *s2) { |
| + s1++; |
| + s2++; |
| + } |
| + return *s1 - *s2; |
| +} |
| + |
| +void my_strpy(char* s1, const char* s2) { |
|
jvoung (off chromium)
2012/08/27 21:57:39
my_strcpy
Robert Muth (chromium)
2012/08/27 22:38:18
Done.
|
| + while( *s2 != '\0') { |
|
jvoung (off chromium)
2012/08/27 21:57:39
"strcpy"
extra space in front of *s2.
Robert Muth (chromium)
2012/08/27 22:38:18
Done.
|
| + *s1 = *s2; |
| + s1++; |
| + s2++; |
| + } |
| + *s1 = '\0'; |
| +} |
| + |
| +static size_t pnacl_irt_interface_interceptor(const char *interface_ident, |
| + void *table, size_t tablesize) { |
| + /* make this big enough to hold prefix_replace + version suffix */ |
| + char buffer[2 * sizeof(prefix_replace)]; |
| + |
| + const char* ident = interface_ident; |
| + /* rewrite: "nacl-irt-ppapihook-XXX" -> "nacl-irt-ppapihook-shimmed-XXX" */ |
| + if (0 == my_strcmp(interface_ident, prefix_search)) { |
| + /* but not if it is already "nacl-irt-ppapihook-shimmed-XXX" */ |
|
jvoung (off chromium)
2012/08/27 21:57:39
extra space "but not"
Robert Muth (chromium)
2012/08/27 22:38:18
Done.
|
| + if (0 != my_strcmp(interface_ident, prefix_replace)) { |
| + my_strpy(buffer, prefix_replace); |
| + my_strpy(buffer + sizeof(prefix_replace) - 1, |
| + interface_ident + sizeof(prefix_search) - 1); |
| + ident = buffer; |
| + } |
| + } |
| + return real_irt_interface(ident, table, tablesize); |
| +} |
| + |
| /* |
| * This is the true entry point for untrusted code. |
| * See nacl_startup.h for the layout at the argument pointer. |
| @@ -30,13 +77,13 @@ |
| /* |
| * Save the real irt interface. |
| */ |
| - __pnacl_real_irt_interface = (TYPE_nacl_irt_query) entry->a_un.a_val; |
| + real_irt_interface = (TYPE_nacl_irt_query) entry->a_un.a_val; |
| /* |
| * Overwrite the auxv slot with the pnacl IRT shim query function. |
| */ |
| entry->a_type = AT_SYSINFO; |
| - entry->a_un.a_val = (uintptr_t) __pnacl_irt_interface_wrapper; |
| + entry->a_un.a_val = (uintptr_t) pnacl_irt_interface_interceptor; |
| } |
| /* If entry is NULL still allow startup to continue. It may be the case |