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,65 @@ |
/* |
- * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
+ * Copyright 2011 The Native Client Authors. All rights reserved. |
* Use of this source code is governed by a BSD-style license that can be |
* found in the LICENSE file. |
*/ |
+#include <stddef.h> |
Mark Seaborn
2012/08/28 16:04:51
I don't think you actually need stddef.h below, do
Robert Muth (chromium)
2012/08/28 19:11:24
irt.h depends on it.
Mark Seaborn
2012/08/28 19:38:41
But irt.h contains "#include <stddef.h>". So I do
|
#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 */ |
+static const char prefix_search[] = "nacl-irt-ppapihook"; |
+static const char prefix_replace[] = "nacl-irt-ppapihook-shimmed"; |
+ |
+/* do not make assumptions about stcmp being available */ |
Mark Seaborn
2012/08/28 16:04:51
'stcmp' -> 'strcmp'. Also capitalise the first le
Robert Muth (chromium)
2012/08/28 19:11:24
Done.
|
+static int my_strcmp(const char* s1, const char* s2) { |
Mark Seaborn
2012/08/28 16:04:51
This should use the " *" spacing style (as elsewhe
Robert Muth (chromium)
2012/08/28 19:11:24
Done.
|
+ while( *s1 != '\0' && *s2 != '\0' && *s1 == *s2) { |
Mark Seaborn
2012/08/28 16:04:51
"while( " -> "while ("
Robert Muth (chromium)
2012/08/28 19:11:24
Done.
|
+ s1++; |
+ s2++; |
+ } |
+ return *s1 - *s2; |
+} |
+ |
+/* do not make assumptions about strcpy being available */ |
+static void my_strcpy(char* s1, const char* s2) { |
+ while(*s2 != '\0') { |
+ *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)) { |
Mark Seaborn
2012/08/28 16:04:51
When is this check going to return true, if interf
Robert Muth (chromium)
2012/08/28 19:11:24
Thanks this was a bug.
As I mention in the initial
Mark Seaborn
2012/08/28 19:38:41
Why don't you combine this change into your IRT ch
|
+ /* but not if it is already "nacl-irt-ppapihook-shimmed-XXX" */ |
+ if (0 != my_strcmp(interface_ident, prefix_replace)) { |
+ my_strcpy(buffer, prefix_replace); |
+ my_strcpy(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 +79,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 |