OLD | NEW |
1 // Copyright (c) 2012 The Native Client Authors. All rights reserved. | 1 // Copyright (c) 2012 The Native Client Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits> | 5 #include <limits> |
6 #include <new> | 6 #include <new> |
7 #include "native_client/src/include/portability.h" | 7 #include "native_client/src/include/portability.h" |
8 #include "native_client/src/include/portability_string.h" | 8 #include "native_client/src/include/portability_string.h" |
9 #include "native_client/src/public/imc_types.h" | 9 #include "native_client/src/public/imc_types.h" |
10 #include "native_client/src/shared/imc/nacl_imc_c.h" | 10 #include "native_client/src/shared/imc/nacl_imc_c.h" |
11 #include "native_client/src/shared/platform/nacl_check.h" | 11 #include "native_client/src/shared/platform/nacl_check.h" |
12 #include "native_client/src/shared/platform/nacl_log.h" | 12 #include "native_client/src/shared/platform/nacl_log.h" |
13 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 13 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
14 #if defined(NACL_LINUX) | |
15 #include "native_client/src/trusted/desc/linux/nacl_desc_sysv_shm.h" | |
16 #endif // defined(NACL_LINUX) | |
17 #include "native_client/src/trusted/desc/nacl_desc_base.h" | 14 #include "native_client/src/trusted/desc/nacl_desc_base.h" |
18 #include "native_client/src/trusted/desc/nacl_desc_conn_cap.h" | 15 #include "native_client/src/trusted/desc/nacl_desc_conn_cap.h" |
19 #include "native_client/src/trusted/desc/nacl_desc_imc.h" | 16 #include "native_client/src/trusted/desc/nacl_desc_imc.h" |
20 #include "native_client/src/trusted/desc/nacl_desc_imc_shm.h" | 17 #include "native_client/src/trusted/desc/nacl_desc_imc_shm.h" |
21 #include "native_client/src/trusted/desc/nacl_desc_invalid.h" | 18 #include "native_client/src/trusted/desc/nacl_desc_invalid.h" |
22 #include "native_client/src/trusted/desc/nacl_desc_io.h" | 19 #include "native_client/src/trusted/desc/nacl_desc_io.h" |
23 #include "native_client/src/trusted/desc/nacl_desc_quota.h" | 20 #include "native_client/src/trusted/desc/nacl_desc_quota.h" |
24 #include "native_client/src/trusted/desc/nacl_desc_rng.h" | 21 #include "native_client/src/trusted/desc/nacl_desc_rng.h" |
25 #include "native_client/src/trusted/desc/nacl_desc_sync_socket.h" | 22 #include "native_client/src/trusted/desc/nacl_desc_sync_socket.h" |
26 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 23 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } | 203 } |
207 | 204 |
208 DescWrapper* DescWrapperFactory::ImportSyncSocketHandle(NaClHandle handle) { | 205 DescWrapper* DescWrapperFactory::ImportSyncSocketHandle(NaClHandle handle) { |
209 struct NaClDesc *desc = NaClDescSyncSocketMake(handle); | 206 struct NaClDesc *desc = NaClDescSyncSocketMake(handle); |
210 if (desc == NULL) { | 207 if (desc == NULL) { |
211 return NULL; | 208 return NULL; |
212 } | 209 } |
213 return MakeGenericCleanup(desc); | 210 return MakeGenericCleanup(desc); |
214 } | 211 } |
215 | 212 |
216 #if NACL_LINUX && !NACL_ANDROID | |
217 DescWrapper* DescWrapperFactory::ImportSysvShm(int key, size_t size) { | |
218 if (NACL_ABI_SIZE_T_MAX - NACL_PAGESIZE + 1 <= size) { | |
219 // Avoid overflow when rounding to the nearest 4K and casting to | |
220 // nacl_off64_t by preventing negative size. | |
221 return NULL; | |
222 } | |
223 // HACK: there's an inlining issue with using NaClRoundPage. (See above.) | |
224 // rounded_size = NaClRoundPage(size); | |
225 size_t rounded_size = | |
226 (size + NACL_PAGESIZE - 1) & ~static_cast<size_t>(NACL_PAGESIZE - 1); | |
227 struct NaClDescSysvShm* desc = | |
228 reinterpret_cast<NaClDescSysvShm*>(calloc(1, sizeof *desc)); | |
229 if (NULL == desc) { | |
230 return NULL; | |
231 } | |
232 | |
233 if (!NaClDescSysvShmImportCtor(desc, | |
234 key, | |
235 static_cast<nacl_off64_t>(rounded_size))) { | |
236 // If rounded_size is negative due to overflow from rounding, it will be | |
237 // rejected here by NaClDescSysvShmImportCtor. | |
238 free(desc); | |
239 return NULL; | |
240 } | |
241 | |
242 return | |
243 MakeGenericCleanup(reinterpret_cast<struct NaClDesc*>(desc)); | |
244 } | |
245 #endif // NACL_LINUX | |
246 | |
247 DescWrapper* DescWrapperFactory::MakeGeneric(struct NaClDesc* desc) { | 213 DescWrapper* DescWrapperFactory::MakeGeneric(struct NaClDesc* desc) { |
248 CHECK(common_data_->is_initialized()); | 214 CHECK(common_data_->is_initialized()); |
249 return new(std::nothrow) DescWrapper(common_data_, desc); | 215 return new(std::nothrow) DescWrapper(common_data_, desc); |
250 } | 216 } |
251 | 217 |
252 | 218 |
253 DescWrapper* DescWrapperFactory::MakeGenericCleanup(struct NaClDesc* desc) { | 219 DescWrapper* DescWrapperFactory::MakeGenericCleanup(struct NaClDesc* desc) { |
254 CHECK(common_data_->is_initialized()); | 220 CHECK(common_data_->is_initialized()); |
255 DescWrapper* wrapper = new(std::nothrow) DescWrapper(common_data_, desc); | 221 DescWrapper* wrapper = new(std::nothrow) DescWrapper(common_data_, desc); |
256 if (NULL != wrapper) { | 222 if (NULL != wrapper) { |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 return reinterpret_cast<struct NaClDescVtbl const *>(desc_->base.vtbl)-> | 580 return reinterpret_cast<struct NaClDescVtbl const *>(desc_->base.vtbl)-> |
615 SemWait(desc_); | 581 SemWait(desc_); |
616 } | 582 } |
617 | 583 |
618 int DescWrapper::GetValue() { | 584 int DescWrapper::GetValue() { |
619 return reinterpret_cast<struct NaClDescVtbl const *>(desc_->base.vtbl)-> | 585 return reinterpret_cast<struct NaClDescVtbl const *>(desc_->base.vtbl)-> |
620 GetValue(desc_); | 586 GetValue(desc_); |
621 } | 587 } |
622 | 588 |
623 } // namespace nacl | 589 } // namespace nacl |
OLD | NEW |