sel_ldr: Remove support for rodata segment at start of executable
[nativeclient.git] / service_runtime / nacl_desc_mutex.c
blobb1ba1f4dace059e4e0ad4d8695118d67f62a88bc
1 /*
2 * Copyright 2008, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
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
14 * distribution.
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. Mutex Descriptor / Handle abstraction.
36 #include "native_client/include/portability.h"
38 #include <stdlib.h>
40 #if NACL_WINDOWS
41 # include "io.h"
42 #endif
44 #include "native_client/service_runtime/nacl_config.h"
45 #include "native_client/service_runtime/nacl_log.h"
46 #include "native_client/service_runtime/nacl_desc_base.h"
47 #include "native_client/service_runtime/nacl_desc_mutex.h"
48 #include "native_client/service_runtime/internal_errno.h"
50 #include "native_client/service_runtime/include/sys/errno.h"
51 #include "native_client/service_runtime/include/sys/fcntl.h"
52 #include "native_client/service_runtime/include/sys/mman.h"
54 #include "native_client/intermodule_comm/nacl_imc_c.h"
57 * This file contains the implementation for the NaClDescMutex subclass
58 * of NaClDesc.
60 * NaClDescMutex is the subclass that wraps host-OS mutex abstractions
64 * Takes ownership of hd, will close in Dtor.
66 int NaClDescMutexCtor(struct NaClDescMutex *self)
68 struct NaClDesc *basep = (struct NaClDesc *) self;
70 basep->vtbl = (struct NaClDescVtbl *) NULL;
71 if (!NaClDescCtor(basep)) {
72 return 0;
74 if (!NaClIntrMutexCtor(&self->mu)) {
75 NaClDescDtor(basep);
76 return 0;
79 basep->vtbl = &kNaClDescMutexVtbl;
80 return 1;
83 void NaClDescMutexDtor(struct NaClDesc *vself)
85 struct NaClDescMutex *self = (struct NaClDescMutex *) vself;
87 NaClLog(4, "NaClDescMutexDtor(0x%08"PRIxPTR").\n",
88 (uintptr_t) vself);
89 NaClIntrMutexDtor(&self->mu);
90 vself->vtbl = (struct NaClDescVtbl *) NULL;
91 NaClDescDtor(&self->base);
94 int NaClDescMutexClose(struct NaClDesc *vself,
95 struct NaClDescEffector *effp)
97 NaClDescUnref(vself);
98 return 0;
101 int NaClDescMutexLock(struct NaClDesc *vself,
102 struct NaClDescEffector *effp)
104 struct NaClDescMutex *self = (struct NaClDescMutex *) vself;
106 NaClSyncStatus status = NaClIntrMutexLock(&self->mu);
107 return -NaClXlateNaClSyncStatus(status);
110 int NaClDescMutexTryLock(struct NaClDesc *vself,
111 struct NaClDescEffector *effp)
113 struct NaClDescMutex *self = (struct NaClDescMutex *) vself;
115 NaClSyncStatus status = NaClIntrMutexTryLock(&self->mu);
116 return -NaClXlateNaClSyncStatus(status);
119 int NaClDescMutexUnlock(struct NaClDesc *vself,
120 struct NaClDescEffector *effp)
122 struct NaClDescMutex *self = (struct NaClDescMutex *) vself;
124 NaClSyncStatus status = NaClIntrMutexUnlock(&self->mu);
125 return -NaClXlateNaClSyncStatus(status);
128 struct NaClDescVtbl const kNaClDescMutexVtbl = {
129 NaClDescMutexDtor,
130 NaClDescMapNotImplemented,
131 NaClDescUnmapUnsafeNotImplemented,
132 NaClDescUnmapNotImplemented,
133 NaClDescReadNotImplemented,
134 NaClDescWriteNotImplemented,
135 NaClDescSeekNotImplemented,
136 NaClDescIoctlNotImplemented,
137 NaClDescFstatNotImplemented,
138 NaClDescMutexClose,
139 NaClDescGetdentsNotImplemented,
140 NACL_DESC_MUTEX,
141 NaClDescExternalizeSizeNotImplemented,
142 NaClDescExternalizeNotImplemented,
143 NaClDescMutexLock,
144 NaClDescMutexTryLock,
145 NaClDescMutexUnlock,
146 NaClDescWaitNotImplemented,
147 NaClDescTimedWaitAbsNotImplemented,
148 NaClDescSignalNotImplemented,
149 NaClDescBroadcastNotImplemented,
150 NaClDescSendMsgNotImplemented,
151 NaClDescRecvMsgNotImplemented,
152 NaClDescConnectAddrNotImplemented,
153 NaClDescAcceptConnNotImplemented,
154 NaClDescPostNotImplemented,
155 NaClDescSemWaitNotImplemented,
156 NaClDescGetValueNotImplemented,
159 int NaClDescMutexInternalize(struct NaClDesc **baseptr,
160 struct NaClDescXferState *xfer)
162 NaClLog(LOG_ERROR, "NaClDescMutexInternalize: not shared yet\n");
163 return -NACL_ABI_EINVAL;