2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
7 #ifndef NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_NACL_RESOURCE_H_
8 #define NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_NACL_RESOURCE_H_
10 #include "native_client/src/include/nacl_base.h"
15 * Pseudo device name for NACL_EXE_STD{OUT,ERR}.
17 #define NACL_RESOURCE_DEBUG_WARNING "DEBUG_ONLY:"
18 #define NACL_RESOURCE_FILE_PREFIX "file:"
19 #define NACL_RESOURCE_DEV_PREFIX "dev:"
20 #define NACL_RESOURCE_DEV_POSTMESSAGE_LOCATOR "//postmessage"
21 #define NACL_RESOURCE_DEV_POSTMESSAGE \
22 NACL_RESOURCE_DEV_PREFIX NACL_RESOURCE_DEV_POSTMESSAGE_LOCATOR
23 #define NACL_RESOURCE_FILE_DEV_NULL "/dev/null"
27 struct NaClResourceSchemes {
28 char const *scheme_prefix;
31 * |default_scheme| is a bool. If no scheme prefixes match, try
32 * Open with this. There should be only one default scheme per
37 * The reason to separate out these functions is to make resource
38 * namespace separation clearer. Files, which require --no-sandbox
39 * to disable the outer sandbox, allow arbitrary paths for logging
40 * untrusted code output; pseudo-devices (for postmessage) is
41 * (currently) a namespace of one entry.
43 * |nacl_flags| should be NACL_ABI_ versions of |flags| and should
44 * be consistent. This is typically determined at compile time, but
45 * the utility NaClHostDescMapOpenFlags can be used to convert
46 * nacl_flags values to flags values.
48 * |mode| should be file access mode (if file, if O_CREAT, if appropriate).
50 struct NaClDesc *(*Open)(struct NaClResource *resource,
51 char const *resource_specifier_rest,
53 int mode /* 0777 etc */,
54 int allow_debug /* bool */);
60 * no vtbl with virtual dtor, since (for now) only object creator
61 * should dtor/delete, and there are no other virtual functions
64 struct NaClResourceSchemes const *schemes;
69 * NaClResourceOpen handles NACL_RESOURCE_DEBUG_WARNING_PREFIX checks
70 * (and stripping), NACL_RESOURCE_{FILE,DEV}_PREFIX dispatch.
72 * This function does not take a descriptor number to directly modify
73 * the descriptor array and require the caller to invoke
74 * NaClAppSetDesc(), since the API allows other uses of the returned
75 * NaClDesc object than just for redirection.
77 struct NaClDesc *NaClResourceOpen(struct NaClResource *self,
78 char const *resource_locator,
83 * Subclasses can expand on the NaClResource base class, e.g., add
84 * startup phase information so that the Open functions can get the
85 * NaClApp pointer, etc. The sole base class member function,
86 * NaClResourceOpen, is unaware of startup phases and relies on the
87 * scheme table's Open function to do the right thing.
89 struct NaClResourceNaClApp {
90 struct NaClResource base;
94 int NaClResourceNaClAppCtor(struct NaClResourceNaClApp *self,
95 struct NaClResourceSchemes const *scheme_tbl,
100 * Invoke Ctor with standard resource schemes.
102 int NaClResourceNaClAppInit(struct NaClResourceNaClApp *self,
103 struct NaClApp *nap);