2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 /* NativeClient shared memory handle return test. */
36 #include <nacl/nacl_srpc.h>
40 #include <sys/nacl_syscalls.h>
43 * GetShmHandle creates and returns a shared memory region.
45 int GetShmHandle(NaClSrpcChannel
*channel
,
46 NaClSrpcArg
**in_args
,
47 NaClSrpcArg
**out_args
);
49 NACL_SRPC_METHOD("get_shm_handle:i:h", GetShmHandle
);
51 int GetShmHandle(NaClSrpcChannel
*channel
,
52 NaClSrpcArg
**in_args
,
53 NaClSrpcArg
**out_args
) {
55 size_t size
= in_args
[0]->u
.ival
;
56 /* Start up banner, clear errors. */
57 printf("GetShmHandle: size %d\n", size
);
58 /* Create an IMC shared memory region. */
59 desc
= imc_mem_obj_create(size
);
62 map_addr
= mmap(0, size
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, desc
, 0);
63 if (MAP_FAILED
== map_addr
) {
64 printf("GetShmHandle: mmap failed\n");
65 /* TODO: close handle */
69 printf("GetShmHandle: imc_mem_obj_create failed %d\n", desc
);
71 /* Return the shm descriptor. */
72 out_args
[0]->u
.hval
= desc
;
73 return NACL_SRPC_RESULT_OK
;
76 * GetInvalidHandle creates and returns a shared memory region.
78 int GetInvalidHandle(NaClSrpcChannel
*channel
,
79 NaClSrpcArg
**in_args
,
80 NaClSrpcArg
**out_args
);
82 NACL_SRPC_METHOD("get_invalid_handle::h", GetInvalidHandle
);
84 int GetInvalidHandle(NaClSrpcChannel
*channel
,
85 NaClSrpcArg
**in_args
,
86 NaClSrpcArg
**out_args
) {
87 /* Return an invalid shm descriptor. */
88 out_args
[0]->u
.ival
= -1;
89 return NACL_SRPC_RESULT_OK
;