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

Unified Diff: src/trusted/service_runtime/sel_main_chrome.c

Issue 135853021: NaCl: Expose NaClApp to embedding layer. (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Build fixes applied Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/trusted/service_runtime/sel_main_chrome.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/trusted/service_runtime/sel_main_chrome.c
diff --git a/src/trusted/service_runtime/sel_main_chrome.c b/src/trusted/service_runtime/sel_main_chrome.c
index 89e7f3054dfd8633ee286574fa99ab0aee09c9d2..1a214371d7f33667505089afedced3a064bde183 100644
--- a/src/trusted/service_runtime/sel_main_chrome.c
+++ b/src/trusted/service_runtime/sel_main_chrome.c
@@ -43,6 +43,8 @@
#include "native_client/src/trusted/service_runtime/win/exception_patch/ntdll_patch.h"
#include "native_client/src/trusted/validator/validation_metadata.h"
+static void NaClCleanupAndExit(struct NaClApp *nap, NaClErrorCode errcode);
+
struct NaClChromeMainArgs *NaClChromeMainArgsCreate(void) {
struct NaClChromeMainArgs *args = malloc(sizeof(*args));
if (args == NULL)
@@ -124,27 +126,11 @@ static void NaClLoadIrt(struct NaClApp *nap, int irt_fd) {
NaClDescUnref(nd);
}
-void NaClChromeMainStart(struct NaClChromeMainArgs *args) {
- char *av[1];
- int ac = 1;
- const char **envp;
- struct NaClApp state;
- struct NaClApp *nap = &state;
+struct NaClApp *NaClChromeMainCreateApp(struct NaClChromeMainArgs *args) {
+ struct NaClApp *nap = (struct NaClApp *)malloc(sizeof(struct NaClApp));
NaClErrorCode errcode = LOAD_INTERNAL;
- int ret_code = 1;
- struct NaClEnvCleanser env_cleanser;
int skip_qualification;
-#if NACL_OSX
- /* Mac dynamic libraries cannot access the environ variable directly. */
- envp = (const char **) *_NSGetEnviron();
-#else
- /* Overzealous code style check is overzealous. */
- /* @IGNORE_LINES_FOR_CODE_HYGIENE[1] */
- extern char **environ;
- envp = (const char **) environ;
-#endif
-
#if NACL_LINUX || NACL_OSX
/* This needs to happen before NaClAllModulesInit(). */
if (args->urandom_fd != -1)
@@ -155,17 +141,16 @@ void NaClChromeMainStart(struct NaClChromeMainArgs *args) {
* Clear state so that NaClBootstrapChannelErrorReporter will be
* able to know if the bootstrap channel is available or not.
*/
- memset(&state, 0, sizeof state);
+ memset(nap, 0, sizeof(struct NaClApp));
NaClAllModulesInit();
NaClBootstrapChannelErrorReporterInit();
- NaClErrorLogHookInit(NaClBootstrapChannelErrorReporter, &state);
-
- /* to be passed to NaClMain, eventually... */
- av[0] = "NaClMain";
+ NaClErrorLogHookInit(NaClBootstrapChannelErrorReporter, nap);
- if (NACL_FI_ERROR_COND("AppCtor", !NaClAppCtor(&state))) {
+ if (NACL_FI_ERROR_COND("AppCtor", !NaClAppCtor(nap))) {
NaClLog(LOG_FATAL, "Error while constructing app state\n");
- goto done;
+ NaClCleanupAndExit(nap, errcode);
+ free(nap);
+ return NULL;
}
errcode = LOAD_OK;
@@ -269,7 +254,7 @@ void NaClChromeMainStart(struct NaClChromeMainArgs *args) {
#endif
/* Give debuggers a well known point at which xlate_base is known. */
- NaClGdbHook(&state);
+ NaClGdbHook(nap);
NaClCreateServiceSocket(nap);
/*
@@ -298,6 +283,42 @@ void NaClChromeMainStart(struct NaClChromeMainArgs *args) {
NaClLog(4, "secure service = %"NACL_PRIxPTR"\n",
(uintptr_t) nap->secure_service);
+
+ if (args->enable_debug_stub) {
+#if NACL_LINUX || NACL_OSX
+ if (args->debug_stub_server_bound_socket_fd != NACL_INVALID_SOCKET) {
+ NaClDebugSetBoundSocket(args->debug_stub_server_bound_socket_fd);
+ }
+#endif
+ if (!NaClDebugInit(nap)) {
+ NaClCleanupAndExit(nap, errcode);
+ free(nap);
+ return NULL;
+ }
+ }
+
+ free(args);
+ return nap;
+}
+
+void NaClChromeMainLoadAndRunNexe(struct NaClApp *nap, int irt_fd) {
+ char *av[1];
+ int ac = 1;
+ int ret_code = 1;
+ NaClErrorCode errcode = LOAD_OK;
+ struct NaClEnvCleanser env_cleanser;
+ const char **envp;
+
+#if NACL_OSX
+ /* Mac dynamic libraries cannot access the environ variable directly. */
+ envp = (const char **) *_NSGetEnviron();
+#else
+ /* Overzealous code style check is overzealous. */
+ /* @IGNORE_LINES_FOR_CODE_HYGIENE[1] */
+ extern char **environ;
+ envp = (const char **) environ;
+#endif
+
NACL_FI_FATAL("BeforeWaitForStartModule");
if (NULL != nap->secure_service) {
@@ -306,9 +327,7 @@ void NaClChromeMainStart(struct NaClChromeMainArgs *args) {
* wait for start_module RPC call on secure channel thread.
*/
start_result = NaClWaitForStartModuleCommand(nap);
- if (LOAD_OK == errcode) {
- errcode = start_result;
- }
+ errcode = start_result;
}
NACL_FI_FATAL("BeforeLoadIrt");
@@ -317,14 +336,15 @@ void NaClChromeMainStart(struct NaClChromeMainArgs *args) {
* error reporting done; can quit now if there was an error earlier.
*/
if (LOAD_OK != errcode) {
- goto done;
+ NaClCleanupAndExit(nap, errcode);
+ return;
}
/*
* Load the integrated runtime (IRT) library.
*/
- if (args->irt_fd != -1 && !nap->irt_loaded) {
- NaClLoadIrt(nap, args->irt_fd);
+ if (irt_fd != -1 && !nap->irt_loaded) {
+ NaClLoadIrt(nap, irt_fd);
nap->irt_loaded = 1;
}
@@ -340,19 +360,8 @@ void NaClChromeMainStart(struct NaClChromeMainArgs *args) {
NaClLog(LOG_FATAL, "Launch service threads failed\n");
}
- if (args->enable_debug_stub) {
-#if NACL_LINUX || NACL_OSX
- if (args->debug_stub_server_bound_socket_fd != NACL_INVALID_SOCKET) {
- NaClDebugSetBoundSocket(args->debug_stub_server_bound_socket_fd);
- }
-#endif
- if (!NaClDebugInit(nap)) {
- goto done;
- }
- }
-
- free(args);
- args = NULL;
+ /* to be passed to NaClMain, eventually... */
+ av[0] = "NaClMain";
if (NACL_FI_ERROR_COND(
"CreateMainThread",
@@ -386,8 +395,9 @@ void NaClChromeMainStart(struct NaClChromeMainArgs *args) {
* before we clean up the address space.
*/
NaClExit(ret_code);
+}
- done:
+static void NaClCleanupAndExit(struct NaClApp *nap, NaClErrorCode errcode) {
fflush(stdout);
/*
@@ -404,5 +414,13 @@ void NaClChromeMainStart(struct NaClChromeMainArgs *args) {
NaClAllModulesFini();
- NaClExit(ret_code);
+ NaClExit(1);
+}
+
+void NaClChromeMainStart(struct NaClChromeMainArgs *args) {
+ int irt_fd = args->irt_fd;
+ struct NaClApp *nap = NaClChromeMainCreateApp(args);
+ if (NULL != nap) {
+ NaClChromeMainLoadAndRunNexe(nap, irt_fd);
+ }
}
« no previous file with comments | « src/trusted/service_runtime/sel_main_chrome.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698