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

Side by Side Diff: src/trusted/desc_cacheability/desc_cacheability.c

Issue 261683002: Make a NaClDesc ctor for creating descs from NaClFileInfo. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: make it posix file descriptor Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2013 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 #include "native_client/src/trusted/desc_cacheability/desc_cacheability.h" 7 #include "native_client/src/trusted/desc_cacheability/desc_cacheability.h"
8 8
9 #include "native_client/src/include/portability.h" 9 #include "native_client/src/include/portability.h"
10 #include "native_client/src/public/desc_metadata_types.h" 10 #include "native_client/src/public/desc_metadata_types.h"
11 #include "native_client/src/public/nacl_file_info.h"
11 #include "native_client/src/shared/platform/nacl_log.h" 12 #include "native_client/src/shared/platform/nacl_log.h"
12 #include "native_client/src/trusted/desc/nacl_desc_base.h" 13 #include "native_client/src/trusted/desc/nacl_desc_base.h"
14 #include "native_client/src/trusted/desc/nacl_desc_file_info.h"
13 #include "native_client/src/trusted/desc/nacl_desc_io.h" 15 #include "native_client/src/trusted/desc/nacl_desc_io.h"
14 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" 16 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
15 #include "native_client/src/trusted/validator/nacl_file_info.h"
16 #include "native_client/src/trusted/validator/rich_file_info.h" 17 #include "native_client/src/trusted/validator/rich_file_info.h"
17 #include "native_client/src/trusted/validator/validation_cache.h" 18 #include "native_client/src/trusted/validator/validation_cache.h"
18 19
19 int NaClDescSetFileToken(struct NaClDesc *desc,
20 struct NaClFileToken const *token) {
21 int error;
22 error = (*NACL_VTBL(NaClDesc, desc)->
23 SetMetadata)(desc,
24 NACL_DESC_METADATA_FILE_TOKEN_TYPE,
25 sizeof *token, (uint8_t const *) token);
26 if (0 != error) {
27 NaClLog(4, "NaClDescSetFileToken: failed, errno %d\n", -error);
28 return 0;
29 }
30 return 1;
31 }
32
33 int NaClDescGetFileToken(struct NaClDesc *desc,
34 struct NaClFileToken *out_token) {
35 int32_t metadata_type;
36 uint32_t metadata_bytes;
37
38 metadata_bytes = (uint32_t) sizeof *out_token;
39 metadata_type = (*NACL_VTBL(NaClDesc, desc)->
40 GetMetadata)(desc, &metadata_bytes,
41 (uint8_t *) out_token);
42 if (NACL_DESC_METADATA_NONE_TYPE == metadata_type) {
43 NaClLog(4, "NaClDescGetFileToken: no meta data, cannot map\n");
44 return 0;
45 } else if (NACL_DESC_METADATA_FILE_TOKEN_TYPE != metadata_type) {
46 return 0;
47 } else if (metadata_bytes != (uint32_t) sizeof *out_token) {
48 /* there is supposed to be a file token, but wrong size? */
49 NaClLog(LOG_WARNING,
50 "NaClDescGetFileToken: purported file token present,"
51 " but token size is incorrect.\n");
52 return 0;
53 }
54 NaClLog(4,
55 "NaClDescGetFileToken: got token 0x%"NACL_PRIx64":%"NACL_PRIx64"\n",
56 out_token->hi, out_token->lo);
57 return 1;
58 }
59
60 struct NaClDesc *NaClExchangeFileTokenForMappableDesc( 20 struct NaClDesc *NaClExchangeFileTokenForMappableDesc(
61 struct NaClFileToken *file_token, 21 struct NaClFileToken *file_token,
62 struct NaClValidationCache *validation_cache) { 22 struct NaClValidationCache *validation_cache) {
63 int32_t new_fd; 23 int32_t new_fd;
64 char *file_path; 24 char *file_path;
65 uint32_t file_path_length; 25 uint32_t file_path_length;
66 struct NaClDesc *desc = NULL; 26 struct NaClDesc *desc = NULL;
67 27
68 /* 28 /*
69 * Not all file loading paths will produce a valid token. Zero is 29 * Not all file loading paths will produce a valid token. Zero is
70 * an invalid token value that indicates there is nothing to 30 * an invalid token value that indicates there is nothing to
71 * resolve. In this case, assume nothing about the providence of 31 * resolve. In this case, assume nothing about the providence of
72 * the file. 32 * the file.
73 */ 33 */
74 if (!(file_token->lo == 0 && file_token->hi == 0) && 34 if (NaClFileTokenIsValid(file_token) &&
75 validation_cache->ResolveFileToken != NULL && 35 validation_cache->ResolveFileToken != NULL &&
76 validation_cache->ResolveFileToken(validation_cache->handle, 36 validation_cache->ResolveFileToken(validation_cache->handle,
77 file_token, 37 file_token,
78 &new_fd, 38 &new_fd,
79 &file_path, 39 &file_path,
80 &file_path_length)) { 40 &file_path_length)) {
81 struct NaClRichFileInfo info; 41 struct NaClRichFileInfo info;
82 42
83 desc = NaClDescIoDescFromHandleAllocCtor((NaClHandle) new_fd, 43 desc = NaClDescIoDescFromHandleAllocCtor((NaClHandle) new_fd,
84 NACL_ABI_O_RDONLY); 44 NACL_ABI_O_RDONLY);
(...skipping 25 matching lines...) Expand all
110 " file token\n"); 70 " file token\n");
111 } else { 71 } else {
112 replacement = NaClExchangeFileTokenForMappableDesc(&file_token, 72 replacement = NaClExchangeFileTokenForMappableDesc(&file_token,
113 validation_cache); 73 validation_cache);
114 if (NULL != replacement) { 74 if (NULL != replacement) {
115 NaClDescUnref(desc); 75 NaClDescUnref(desc);
116 *desc_in_out = replacement; 76 *desc_in_out = replacement;
117 } 77 }
118 } 78 }
119 } 79 }
OLDNEW
« no previous file with comments | « src/trusted/desc_cacheability/desc_cacheability.h ('k') | src/trusted/manifest_name_service_proxy/manifest_proxy.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698