Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / native_client / src / trusted / service_runtime / nacl_resource.h
1 /*
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.
5  */
6
7 #ifndef NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_NACL_RESOURCE_H_
8 #define NATIVE_CLIENT_SRC_TRUSTED_SERVICE_RUNTIME_NACL_RESOURCE_H_
9
10 #include "native_client/src/include/nacl_base.h"
11
12 EXTERN_C_BEGIN
13
14 /*
15  * Pseudo device name for NACL_EXE_STD{OUT,ERR}.
16  */
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"
24
25 struct NaClResource;
26
27 struct NaClResourceSchemes {
28   char const      *scheme_prefix;
29   int             default_scheme;
30   /*
31    * |default_scheme| is a bool.  If no scheme prefixes match, try
32    * Open with this.  There should be only one default scheme per
33    * scheme_table.
34    */
35
36   /*
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.
42    *
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.
47    *
48    * |mode| should be file access mode (if file, if O_CREAT, if appropriate).
49    */
50   struct NaClDesc *(*Open)(struct NaClResource  *resource,
51                            char const           *resource_specifier_rest,
52                            int                  nacl_flags,
53                            int                  mode /* 0777 etc */,
54                            int                  allow_debug /* bool */);
55 };
56
57
58 struct NaClResource {
59   /*
60    * no vtbl with virtual dtor, since (for now) only object creator
61    * should dtor/delete, and there are no other virtual functions
62    * needed.
63    */
64   struct NaClResourceSchemes const  *schemes;
65   size_t                            num_schemes;
66 };
67
68 /*
69  * NaClResourceOpen handles NACL_RESOURCE_DEBUG_WARNING_PREFIX checks
70  * (and stripping), NACL_RESOURCE_{FILE,DEV}_PREFIX dispatch.
71  *
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.
76  */
77 struct NaClDesc *NaClResourceOpen(struct NaClResource *self,
78                                   char const          *resource_locator,
79                                   int                 nacl_flags,
80                                   int                 mode);
81
82 /*
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.
88  */
89 struct NaClResourceNaClApp {
90   struct NaClResource base;
91   struct NaClApp      *nap;
92 };
93
94 int NaClResourceNaClAppCtor(struct NaClResourceNaClApp        *self,
95                             struct NaClResourceSchemes const  *scheme_tbl,
96                             size_t                            num_schemes,
97                             struct NaClApp                    *nap);
98
99 /*
100  * Invoke Ctor with standard resource schemes.
101  */
102 int NaClResourceNaClAppInit(struct NaClResourceNaClApp        *self,
103                             struct NaClApp                    *nap);
104
105 EXTERN_C_END
106
107 #endif