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 * NaCl Service Runtime. I/O Descriptor / Handle abstraction. Memory
34 * mapping using descriptors.
37 #include "native_client/include/portability.h"
39 #include "native_client/service_runtime/nacl_host_desc.h"
40 #include "native_client/service_runtime/nacl_log.h"
42 #include "native_client/service_runtime/include/sys/errno.h"
45 * If you are using this as a kernel-style return, remember that you
46 * should negate its return value.
48 int NaClXlateErrno(int errnum
)
52 * Unfortunately a macro cannot expand to contain #ifdef....
54 * TODO: All host-OS conditional errnos should map into a
57 #define MAP(E) case E: do { return NACL_ABI_ ## E; } while (0)
100 MAP(EL3HLT
); /* not in osx */
103 MAP(EL3RST
); /* not in osx */
106 MAP(ELNRNG
); /* not in osx */
137 #if defined(EDEADLOCK) && EDEADLK != EDEADLOCK
183 MAP(ELBIN
); /* newlib only? */
192 MAP(EFTYPE
); /* osx has it; linux doesn't */
219 MAP(ENMFILE
); /* newlib only? */
285 #ifdef EPROTONOSUPPORT
286 MAP(EPROTONOSUPPORT
);
288 #ifdef ESOCKTNOSUPPORT
289 MAP(ESOCKTNOSUPPORT
);
307 MAP(EPROCLIM
); /* osx has this; linux does not */
309 * if we allow fork, we will need to map EAGAIN from fork to EPROCLIM,
310 * so NaClXlateErrno would not be stateless.
319 #if ENOTSUP != EOPNOTSUPP
326 MAP(ENOSHARE
); /* newlib only? */
329 MAP(ECASECLASH
); /* newlib only? */
349 return NACL_ABI_EINVAL
; /* catch all */
353 * If you are using this as a kernel-style return, remember that you
354 * should negate its return value.
356 int NaClXlateNaClSyncStatus(NaClSyncStatus status
)
359 #define MAP(S, E) case S: do { return E; } while (0)
360 MAP(NACL_SYNC_OK
, 0);
361 MAP(NACL_SYNC_INTERNAL_ERROR
, NACL_ABI_EINVAL
); /* generic error */
362 MAP(NACL_SYNC_BUSY
, NACL_ABI_EBUSY
);
363 MAP(NACL_SYNC_MUTEX_INVALID
, NACL_ABI_EBADF
);
364 MAP(NACL_SYNC_MUTEX_DEADLOCK
, NACL_ABI_EINVAL
);
365 MAP(NACL_SYNC_MUTEX_PERMISSION
, NACL_ABI_EPERM
);
366 MAP(NACL_SYNC_MUTEX_INTERRUPTED
, NACL_ABI_EINTR
);
367 /* TODO: should it be NACL_ABI_ETIMEDOUT? */
368 MAP(NACL_SYNC_CONDVAR_TIMEDOUT
, NACL_ABI_ETIME
);
369 MAP(NACL_SYNC_CONDVAR_INTR
, NACL_ABI_EINTR
);
370 MAP(NACL_SYNC_SEM_INTERRUPTED
, NACL_ABI_EINTR
);
371 MAP(NACL_SYNC_SEM_RANGE_ERROR
, NACL_ABI_ERANGE
);
374 return NACL_ABI_EINVAL
; /* catch all */
378 struct NaClHostDesc
*NaClHostDescPosixMake(int posix_d
,
381 struct NaClHostDesc
*nhdp
;
383 nhdp
= malloc(sizeof *nhdp
);
385 NaClLog(LOG_FATAL
, "NaClHostDescPosixMake(%d,0x%x): malloc failed\n",
388 if (!NaClHostDescPosixTake(nhdp
, posix_d
, mode
)) {
389 NaClLog(LOG_FATAL
, "NaClHostDescPosixMake(%d,0x%x): Take failed\n",