summaryrefslogtreecommitdiffstats
path: root/native_client_sdk
diff options
context:
space:
mode:
authornoelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-01 17:05:40 +0000
committernoelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-01 17:05:40 +0000
commit25fb061d76fc07bc85b98b0545d2475d8fecedf9 (patch)
treec1db049174f30e39fccc5a0b99907920558e55ca /native_client_sdk
parent9b2ae820e6648eda4217ffc68c1561c7b1b5d843 (diff)
downloadchromium_src-25fb061d76fc07bc85b98b0545d2475d8fecedf9.zip
chromium_src-25fb061d76fc07bc85b98b0545d2475d8fecedf9.tar.gz
chromium_src-25fb061d76fc07bc85b98b0545d2475d8fecedf9.tar.bz2
[NaCl SDK} Add ppapi_stub for bionic
Bionic uses a different loader which requires a different ppapi_stub. This implementaion is for the experimental bionic build only. BUG=none R=binji@chromium.org See related issue to re-merge with GYP/GN https://code.google.com/p/chromium/issues/detail?id=368779 Review URL: https://codereview.chromium.org/268493004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267549 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
-rw-r--r--native_client_sdk/src/libraries/ppapi_stub/library.dsc19
-rw-r--r--native_client_sdk/src/libraries/ppapi_stub/main.c17
-rw-r--r--native_client_sdk/src/libraries/ppapi_stub/ppapi_main.c110
3 files changed, 146 insertions, 0 deletions
diff --git a/native_client_sdk/src/libraries/ppapi_stub/library.dsc b/native_client_sdk/src/libraries/ppapi_stub/library.dsc
new file mode 100644
index 0000000..fcb15cf
--- /dev/null
+++ b/native_client_sdk/src/libraries/ppapi_stub/library.dsc
@@ -0,0 +1,19 @@
+{
+ 'TOOLS': ['bionic'],
+ 'SEARCH': [
+ '.',
+ ],
+ 'TARGETS': [
+ {
+ 'NAME' : 'ppapi_stub',
+ 'TYPE' : 'lib',
+ 'SOURCES' : [
+ 'main.c',
+ 'ppapi_main.c',
+ ],
+ }
+ ],
+ 'DEST': 'src',
+ 'NAME': 'ppapi_stub',
+}
+
diff --git a/native_client_sdk/src/libraries/ppapi_stub/main.c b/native_client_sdk/src/libraries/ppapi_stub/main.c
new file mode 100644
index 0000000..c1428bc
--- /dev/null
+++ b/native_client_sdk/src/libraries/ppapi_stub/main.c
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2014 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/*
+ * An application that doesn't define its own main but links in -lppapi
+ * gets this one. A plugin may instead have its own main that calls
+ * PpapiPluginMain (or PpapiPluginStart) after doing some other setup.
+ */
+
+int PpapiPluginMain();
+
+int main(void) {
+ return PpapiPluginMain();
+}
diff --git a/native_client_sdk/src/libraries/ppapi_stub/ppapi_main.c b/native_client_sdk/src/libraries/ppapi_stub/ppapi_main.c
new file mode 100644
index 0000000..be540b6
--- /dev/null
+++ b/native_client_sdk/src/libraries/ppapi_stub/ppapi_main.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2014 The Chromium 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 <pthread.h>
+
+#include "irt_syscalls.h"
+#include "ppapi/c/pp_module.h"
+#include "ppapi/c/ppp.h"
+
+struct PP_StartFunctions {
+ int32_t (*PPP_InitializeModule)(PP_Module module_id,
+ PPB_GetInterface get_browser_interface);
+ void (*PPP_ShutdownModule)();
+ const void* (*PPP_GetInterface)(const char* interface_name);
+};
+
+struct PP_ThreadFunctions {
+ /*
+ * This is a cut-down version of pthread_create()/pthread_join().
+ * We omit thread creation attributes and the thread's return value.
+ *
+ * We use uintptr_t as the thread ID type because pthread_t is not
+ * part of the stable ABI; a user thread library might choose an
+ * arbitrary size for its own pthread_t.
+ */
+ int (*thread_create)(uintptr_t* tid,
+ void (*func)(void* thread_argument),
+ void* thread_argument);
+ int (*thread_join)(uintptr_t tid);
+};
+
+#define NACL_IRT_PPAPIHOOK_v0_1 "nacl-irt-ppapihook-0.1"
+struct nacl_irt_ppapihook {
+ int (*ppapi_start)(const struct PP_StartFunctions*);
+ void (*ppapi_register_thread_creator)(const struct PP_ThreadFunctions*);
+};
+
+
+static int thread_create(uintptr_t *tid,
+ void (*func)(void *thread_argument),
+ void *thread_argument) {
+ /*
+ * We know that newlib and glibc use a small pthread_t type, so we
+ * do not need to wrap pthread_t values.
+ */
+ return pthread_create((pthread_t *) tid, NULL,
+ (void *(*)(void *thread_argument)) func,
+ thread_argument);
+}
+
+static int thread_join(uintptr_t tid) {
+ return pthread_join((pthread_t) tid, NULL);
+}
+
+/*
+ * These are dangling references to functions that the application must define.
+ */
+static const struct PP_StartFunctions ppapi_app_start_callbacks = {
+ PPP_InitializeModule,
+ PPP_ShutdownModule,
+ PPP_GetInterface
+};
+
+const static struct PP_ThreadFunctions thread_funcs = {
+ thread_create,
+ thread_join
+};
+
+static void fatal_error(const char *message) {
+ write(2, message, strlen(message));
+ _exit(127);
+}
+
+/*
+ * We cannot tell at link time whether the application uses PPB_Audio,
+ * because of the way that PPAPI is defined via runtime interface
+ * query rather than a set of static functions. This means that we
+ * register the audio thread functions unconditionally. This adds the
+ * small overhead of pulling in pthread_create() even if the
+ * application does not use PPB_Audio or libpthread.
+ *
+ * If an application developer wants to avoid that cost, they can
+ * override this function with an empty definition.
+ */
+void __nacl_register_thread_creator(const struct nacl_irt_ppapihook *hooks) {
+ hooks->ppapi_register_thread_creator(&thread_funcs);
+}
+
+int PpapiPluginStart(const struct PP_StartFunctions *funcs) {
+ struct nacl_irt_ppapihook hooks;
+ if (sizeof(hooks) != __nacl_irt_query(NACL_IRT_PPAPIHOOK_v0_1,
+ &hooks, sizeof(hooks))) {
+ fatal_error("PpapiPluginStart: PPAPI hooks not found\n");
+ }
+
+ __nacl_register_thread_creator(&hooks);
+ return hooks.ppapi_start(funcs);
+}
+
+
+/*
+ * The application's main (or the one supplied in this library) calls this
+ * to start the PPAPI world.
+ */
+int PpapiPluginMain(void) {
+ return PpapiPluginStart(&ppapi_app_start_callbacks);
+}