Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: src/trusted/desc/nacl_desc_io.c

Issue 12929033: Add NaClDescIoDescMakeFromHandle (Closed) Base URL: http://git.chromium.org/native_client/src/native_client.git@master
Patch Set: add error checks Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/trusted/desc/nacl_desc_io.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « src/trusted/desc/nacl_desc_io.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698