OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /* | 7 /* |
8 * NaCl Service Runtime. I/O Descriptor / Handle abstraction. Memory | 8 * NaCl Service Runtime. I/O Descriptor / Handle abstraction. Memory |
9 * mapping using descriptors. | 9 * mapping using descriptors. |
10 */ | 10 */ |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 NaClLog(LOG_FATAL, | 83 NaClLog(LOG_FATAL, |
84 ("NaClDescIoDescMake:" | 84 ("NaClDescIoDescMake:" |
85 " NaClDescIoDescCtor(0x%08"NACL_PRIxPTR",0x%08"NACL_PRIxPTR | 85 " NaClDescIoDescCtor(0x%08"NACL_PRIxPTR",0x%08"NACL_PRIxPTR |
86 ") failed\n"), | 86 ") failed\n"), |
87 (uintptr_t) ndp, | 87 (uintptr_t) ndp, |
88 (uintptr_t) nhdp); | 88 (uintptr_t) nhdp); |
89 } | 89 } |
90 return ndp; | 90 return ndp; |
91 } | 91 } |
92 | 92 |
| 93 struct NaClDesc *NaClDescIoDescMakeFromHandle(NaClHandle handle) { |
| 94 int posix_d; |
| 95 struct NaClHostDesc *nhdp; |
| 96 struct NaClDescIoDesc *desc; |
| 97 |
| 98 #if NACL_WINDOWS |
| 99 posix_d = _open_osfhandle((intptr_t) handle, _O_RDWR | _O_BINARY); |
| 100 if (-1 == posix_d) |
| 101 return NULL; |
| 102 #else |
| 103 posix_d = handle; |
| 104 #endif |
| 105 nhdp = NaClHostDescPosixMake(posix_d, NACL_ABI_O_RDWR); |
| 106 if (NULL == nhdp) |
| 107 return NULL; |
| 108 desc = NaClDescIoDescMake(nhdp); |
| 109 return &desc->base; |
| 110 } |
| 111 |
93 struct NaClDescIoDesc *NaClDescIoDescOpen(char *path, | 112 struct NaClDescIoDesc *NaClDescIoDescOpen(char *path, |
94 int mode, | 113 int mode, |
95 int perms) { | 114 int perms) { |
96 struct NaClHostDesc *nhdp; | 115 struct NaClHostDesc *nhdp; |
97 | 116 |
98 nhdp = malloc(sizeof *nhdp); | 117 nhdp = malloc(sizeof *nhdp); |
99 if (NULL == nhdp) { | 118 if (NULL == nhdp) { |
100 NaClLog(LOG_FATAL, "NaClDescIoDescOpen: no memory for %s\n", path); | 119 NaClLog(LOG_FATAL, "NaClDescIoDescOpen: no memory for %s\n", path); |
101 } | 120 } |
102 if (0 != NaClHostDescOpen(nhdp, path, mode, perms)) { | 121 if (0 != NaClHostDescOpen(nhdp, path, mode, perms)) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 cleanup: | 364 cleanup: |
346 if (rv < 0) { | 365 if (rv < 0) { |
347 free(nhdp); | 366 free(nhdp); |
348 free(ndidp); | 367 free(ndidp); |
349 if (NACL_INVALID_HANDLE != h) { | 368 if (NACL_INVALID_HANDLE != h) { |
350 (void) NaClClose(h); | 369 (void) NaClClose(h); |
351 } | 370 } |
352 } | 371 } |
353 return rv; | 372 return rv; |
354 } | 373 } |
OLD | NEW |