Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / native_client / src / public / imc_types.h
1 /*
2  * Copyright (c) 2008 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.  IMC API.
9  */
10
11 #ifndef _NATIVE_CLIENT_SRC_PUBLIC_IMC_TYPES_H_
12 #define _NATIVE_CLIENT_SRC_PUBLIC_IMC_TYPES_H_
13
14 /*
15  * This file defines the C API for NativeClient applications.  The
16  * ABI is implicitly defined.
17  */
18
19 #include "native_client/src/trusted/service_runtime/nacl_size_t.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 /* TODO(sehr): there should be one instance to avoid conflicting definitions.
26  */
27 #ifndef __nacl_handle_defined
28 #define __nacl_handle_defined
29 #if NACL_WINDOWS
30 typedef HANDLE NaClHandle;
31 #else
32 typedef int NaClHandle;
33 #endif
34 #endif
35
36 struct NaClAbiNaClImcMsgIoVec {
37 #ifdef __native_client__
38   void            *base;
39 #else
40   uint32_t        base;
41 #endif
42   nacl_abi_size_t length;
43 };
44
45 struct NaClAbiNaClImcMsgHdr {
46 #ifdef __native_client__
47   struct NaClAbiNaClImcMsgIoVec  *iov;
48 #else
49   uint32_t                iov;
50 #endif
51   nacl_abi_size_t         iov_length;
52 #ifdef __native_client__
53   int                     *descv;
54 #else
55   uint32_t                descv;
56 #endif
57   nacl_abi_size_t         desc_length;
58   int                     flags;
59 };
60
61 #ifndef __native_client__
62 struct NaClImcMsgIoVec {
63   void    *base;
64   size_t  length;
65 };
66
67 struct NaClImcMsgHdr {
68   struct NaClImcMsgIoVec  *iov;
69   nacl_abi_size_t         iov_length;
70   int                     *descv;
71   nacl_abi_size_t         desc_length;
72   int                     flags;
73 };
74 #endif
75
76 /*
77  * NACL_ABI_IMC_IOVEC_MAX: How many struct NaClIOVec are permitted?
78  * These are copied to kernel space in order to translate/validate
79  * addresses, and are on the thread stack when processing
80  * NaClSysSendmsg and NaClSysRecvmsg syscalls.  Each object takes 8
81  * bytes, so beware running into NACL_KERN_STACK_SIZE above.
82  */
83 #define NACL_ABI_IMC_IOVEC_MAX      256
84
85 /*
86  * NAC_ABI_IMC_DESC_MAX: How many descriptors are permitted?  Each
87  * object is 4 bytes.  An array of ints are on the kernel stack.
88  *
89  * TODO(bsy): coordinate w/ NACL_HANDLE_COUNT_MAX in nacl_imc_c.h.
90  * Current IMC-imposed limit seems way too small.
91  */
92 #define NACL_ABI_IMC_USER_DESC_MAX  8
93 #define NACL_ABI_IMC_DESC_MAX       8
94
95 /*
96  * NACL_ABI_IMC_USER_BYTES_MAX: read must go into a kernel buffer first
97  * before a variable-length header describing the number and types of
98  * NaClHandles encoded is parsed, with the rest of the data not yet
99  * consumed turning into user data.
100  */
101 #define NACL_ABI_IMC_USER_BYTES_MAX    (128 << 10)
102 #define NACL_ABI_IMC_BYTES_MAX                   \
103   (NACL_ABI_IMC_USER_BYTES_MAX                   \
104    + (1 + NACL_PATH_MAX) * NACL_ABI_IMC_USER_DESC_MAX + 16)
105 /*
106  * 4096 + (1 + 28) * 256 = 11520, so the read buffer must be malloc'd
107  * or be part of the NaClAppThread structure; the kernel thread stack
108  * is too small for it.
109  *
110  * NB: the header has an end tag and the size is rounded up to the
111  * next 16 bytes.
112  */
113
114 /* these values must match src/shared/imc/nacl_imc{,_c}.h */
115 #define NACL_ABI_RECVMSG_DATA_TRUNCATED 0x1
116 #define NACL_ABI_RECVMSG_DESC_TRUNCATED 0x2
117
118 #define NACL_ABI_IMC_NONBLOCK           0x1
119
120 #ifdef __cplusplus
121 }
122 #endif
123
124 #endif