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 /*
8  * NaCl service runtime.  NaClDescIoDesc subclass of NaClDesc.
9  */
10 #ifndef NATIVE_CLIENT_SRC_TRUSTED_DESC_NACL_DESC_IO_H_
11 #define NATIVE_CLIENT_SRC_TRUSTED_DESC_NACL_DESC_IO_H_
12 
13 #include "native_client/src/include/nacl_base.h"
14 #include "native_client/src/include/portability.h"
15 
16 #include "native_client/src/public/nacl_desc.h"
17 #include "native_client/src/trusted/desc/nacl_desc_base.h"
18 
19 EXTERN_C_BEGIN
20 
21 struct NaClDescEffector;
22 struct NaClDescXferState;
23 struct NaClHostDesc;
24 struct NaClMessageHeader;
25 
26 /*
27  * I/O descriptors
28  */
29 
30 struct NaClDescIoDesc {
31   struct NaClDesc           base NACL_IS_REFCOUNT_SUBCLASS;
32   /*
33    * No locks are needed for accessing class members; NaClHostDesc
34    * should ensure thread safety, and uses are read-only.
35    *
36    * If we later added state that needs locking, beware lock order.
37    */
38   struct NaClHostDesc       *hd;
39 };
40 
41 int NaClDescIoInternalize(struct NaClDesc               **baseptr,
42                           struct NaClDescXferState      *xfer)
43     NACL_WUR;
44 
45 int NaClDescIoDescCtor(struct NaClDescIoDesc  *self,
46                        struct NaClHostDesc    *hd) NACL_WUR;
47 
48 struct NaClDescIoDesc *NaClDescIoDescMake(struct NaClHostDesc *nhdp);
49 
50 /*
51  * NaClDescIoDescFromDescAllocCtor is essentially the same as
52  * NaClDescIoMakeFromHandle, except that instead of NaClHandle (which is
53  * HANDLE on Windows), we always use a Posix I/O descriptor.
54  */
55 struct NaClDesc *NaClDescIoDescFromDescAllocCtor(int desc,
56                                                  int flags) NACL_WUR;
57 
58 /* a simple factory */
59 struct NaClDescIoDesc *NaClDescIoDescOpen(char const *path,
60                                           int mode,
61                                           int perms) NACL_WUR;
62 
63 uintptr_t NaClDescIoDescMapAnon(struct NaClDescEffector *effp,
64                                 void                    *start_addr,
65                                 size_t                  len,
66                                 int                     prot,
67                                 int                     flags,
68                                 nacl_off64_t            offset);
69 
70 EXTERN_C_END
71 
72 #endif  // NATIVE_CLIENT_SRC_TRUSTED_DESC_NACL_DESC_IO_H_
73