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

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

Issue 8825007: Native Client side changes for debugging support: stdout/err -> postmessage. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 9 years 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/nacl_resource.h ('k') | src/trusted/service_runtime/nacl_syscall_common.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/trusted/service_runtime/nacl_resource.c
===================================================================
--- src/trusted/service_runtime/nacl_resource.c (revision 0)
+++ src/trusted/service_runtime/nacl_resource.c (revision 0)
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 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 <string.h>
+
+#include "native_client/src/trusted/service_runtime/nacl_resource.h"
+
+#include "native_client/src/include/nacl_base.h"
+#include "native_client/src/include/nacl_macros.h"
+#include "native_client/src/shared/platform/nacl_check.h"
+#include "native_client/src/shared/platform/nacl_log.h"
+#include "native_client/src/trusted/desc/nacl_desc_base.h"
+#include "native_client/src/trusted/desc/nacl_desc_io.h"
+#include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
+#include "native_client/src/trusted/service_runtime/nacl_desc_postmessage.h"
+#include "native_client/src/trusted/service_runtime/sel_ldr.h"
+
+struct NaClDesc *NaClResourceOpen(struct NaClResource *self,
+ char const *resource_locator,
+ int nacl_flags,
+ int mode) {
+ size_t ix;
+ size_t default_ix = ~(size_t) 0; /* greater than self->num_schemes */
+ size_t prefix_len;
+ int allow_debug = 0;
+
+ NaClLog(4, "NaClResourceOpen(*,\"%s\",0x%x,0x%x)\n",
+ resource_locator, nacl_flags, mode);
+ prefix_len = strlen(NACL_RESOURCE_DEBUG_WARNING);
+ if (strncmp(resource_locator, NACL_RESOURCE_DEBUG_WARNING,
+ prefix_len) == 0) {
+ allow_debug = 1;
+ resource_locator += prefix_len;
+ }
+
+ for (ix = 0; ix < self->num_schemes; ++ix) {
+ if (self->schemes[ix].default_scheme) {
+ default_ix = ix;
+ }
+ prefix_len = strlen(self->schemes[ix].scheme_prefix);
+ NaClLog(4, " prefix \"%s\"\n", self->schemes[ix].scheme_prefix);
+ if (0 == strncmp(self->schemes[ix].scheme_prefix, resource_locator,
+ prefix_len)) {
+ char const *rest = resource_locator + prefix_len;
+ NaClLog(4, " prefix match at %"NACL_PRIuS", rest \"%s\".\n", ix, rest);
+ return (*self->schemes[ix].Open)(self, rest,
+ nacl_flags, mode, allow_debug);
+ }
+ }
+ if (default_ix < self->num_schemes) {
+ NaClLog(4, " trying default scheme %"NACL_PRIuS".\n", default_ix);
+ return (*self->schemes[default_ix].Open)(self, resource_locator,
+ nacl_flags, mode, allow_debug);
+ }
+ return NULL;
+}
+
+int NaClResourceCtor(struct NaClResource *self,
+ struct NaClResourceSchemes const *scheme_tbl,
+ size_t num_schemes) {
+ self->schemes = scheme_tbl;
+ self->num_schemes = num_schemes;
+ return 1;
+}
+
+/* --------------------------------------------------------------------------
+ *
+ * Subclass of NaClResource
+ *
+ * --------------------------------------------------------------------------
+ */
+
+int NaClResourceNaClAppCtor(struct NaClResourceNaClApp *self,
+ struct NaClResourceSchemes const *scheme_tbl,
+ size_t num_schemes,
+ struct NaClApp *nap) {
+ NaClLog(4,
+ ("NaClResourceNaClAppCtor, scheme_tbl 0x%"NACL_PRIxPTR","
+ " size %"NACL_PRIuS".\n"),
+ (uintptr_t) scheme_tbl, num_schemes);
+ if (!NaClResourceCtor(&self->base, scheme_tbl, num_schemes)) {
+ return 0;
+ }
+ self->nap = nap;
+ return 1;
+}
+
+static struct NaClDesc *NaClResourceNaClAppFileOpen(
+ struct NaClResource *vself,
+ char const *resource_locator,
+ int nacl_flags,
+ int mode,
+ int allow_debug) {
+ struct NaClResourceNaClApp *self = (struct NaClResourceNaClApp *) vself;
+ struct NaClHostDesc *hd = NULL;
+ struct NaClDescIoDesc *did = NULL;
+ struct NaClDesc *rv = NULL;
+
+ /*
+ * Functionality-wise, we're startup phase-independent; we can
+ * always try to open a file; however, initialization requires that
+ * file opens occur only early, in NACl_RESOURCE_PHASE_START.
+ */
+ UNREFERENCED_PARAMETER(allow_debug);
+ if (self->nap->resource_phase != NACL_RESOURCE_PHASE_START) {
+ return NULL;
+ }
+ hd = malloc(sizeof *hd);
+ did = malloc(sizeof *did);
+ if (NULL == hd || NULL == did) {
+ goto done;
+ }
+ if (!NaClHostDescOpen(hd, resource_locator, nacl_flags, mode)) {
+ goto done;
+ }
+ if (!NaClDescIoDescCtor(did, hd)) {
+ (void) NaClHostDescClose(hd);
+ goto done;
+ }
+ hd = NULL; /* ownership passed into did */
+ rv = (struct NaClDesc *) did; /* success */
+ did = NULL;
+ done:
+ free(hd);
+ free(did);
+ return rv;
+}
+
+/*
+ * We don't bother to make it a singleton postmessage device. Thread
+ * safety is handled when the device object gets the lock to use the
+ * reverse channel.
+ */
+static struct NaClDesc *NaClResourceNaClAppDevOpen(
+ struct NaClResource *vself,
+ char const *resource_locator,
+ int nacl_flags,
+ int mode,
+ int allow_debug) {
+ struct NaClResourceNaClApp *self = (struct NaClResourceNaClApp *) vself;
+ struct NaClDescPostMessage *ndpm = NULL;
+
+ if (self->nap->resource_phase != NACL_RESOURCE_PHASE_REV_CHAN
+ || !allow_debug) {
+ return NULL;
+ }
+
+ if (0 == strcmp(resource_locator, NACL_RESOURCE_DEV_POSTMESSAGE_LOCATOR)) {
+ /* disallow O_RDONLY or O_RDWR */
+ if ((NACL_ABI_O_ACCMODE & nacl_flags) != NACL_ABI_O_WRONLY) {
+ return NULL;
+ }
+ /* allow O_CREAT, O_APPEND, and O_TRUNC */
+ UNREFERENCED_PARAMETER(mode); /* ignored; O_CREAT doesn't create. */
+
+ ndpm = malloc(sizeof *ndpm);
+ CHECK(NULL != ndpm);
+ CHECK(NaClDescPostMessageCtor(ndpm, self->nap));
+ }
+ return (struct NaClDesc *) ndpm;
+}
+
+int NaClResourceNaClAppInit(struct NaClResourceNaClApp *rp,
+ struct NaClApp *nap) {
+ static struct NaClResourceSchemes const schemes[] = {
+ {
+ NACL_RESOURCE_FILE_PREFIX,
+ 1, /* default scheme */
+ NaClResourceNaClAppFileOpen,
+ }, {
+ NACL_RESOURCE_DEV_PREFIX,
+ 0, /* not default scheme */
+ NaClResourceNaClAppDevOpen,
+ },
+ };
+
+ NaClLog(4, "NaClResourceNaClAppInit -- Ctor with default schemes\n");
+ return NaClResourceNaClAppCtor(rp, schemes, NACL_ARRAY_SIZE(schemes), nap);
+}
Property changes on: src/trusted/service_runtime/nacl_resource.c
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « src/trusted/service_runtime/nacl_resource.h ('k') | src/trusted/service_runtime/nacl_syscall_common.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698