Chromium Code Reviews| 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); | |
|
Mark Seaborn
2013/03/22 18:40:05
You should check for an error here:
if (posix_d ==
hamaji
2013/03/22 18:45:08
Done.
| |
| 100 #else | |
| 101 posix_d = handle; | |
| 102 #endif | |
| 103 nhdp = NaClHostDescPosixMake(posix_d, NACL_ABI_O_RDWR); | |
|
Mark Seaborn
2013/03/22 18:40:05
You should check for an error here too:
if (nhdp =
hamaji
2013/03/22 18:45:08
Done.
| |
| 104 desc = NaClDescIoDescMake(nhdp); | |
| 105 return &desc->base; | |
| 106 } | |
| 107 | |
| 93 struct NaClDescIoDesc *NaClDescIoDescOpen(char *path, | 108 struct NaClDescIoDesc *NaClDescIoDescOpen(char *path, |
| 94 int mode, | 109 int mode, |
| 95 int perms) { | 110 int perms) { |
| 96 struct NaClHostDesc *nhdp; | 111 struct NaClHostDesc *nhdp; |
| 97 | 112 |
| 98 nhdp = malloc(sizeof *nhdp); | 113 nhdp = malloc(sizeof *nhdp); |
| 99 if (NULL == nhdp) { | 114 if (NULL == nhdp) { |
| 100 NaClLog(LOG_FATAL, "NaClDescIoDescOpen: no memory for %s\n", path); | 115 NaClLog(LOG_FATAL, "NaClDescIoDescOpen: no memory for %s\n", path); |
| 101 } | 116 } |
| 102 if (0 != NaClHostDescOpen(nhdp, path, mode, perms)) { | 117 if (0 != NaClHostDescOpen(nhdp, path, mode, perms)) { |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 cleanup: | 360 cleanup: |
| 346 if (rv < 0) { | 361 if (rv < 0) { |
| 347 free(nhdp); | 362 free(nhdp); |
| 348 free(ndidp); | 363 free(ndidp); |
| 349 if (NACL_INVALID_HANDLE != h) { | 364 if (NACL_INVALID_HANDLE != h) { |
| 350 (void) NaClClose(h); | 365 (void) NaClClose(h); |
| 351 } | 366 } |
| 352 } | 367 } |
| 353 return rv; | 368 return rv; |
| 354 } | 369 } |
| OLD | NEW |