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

Side by Side Diff: src/trusted/desc/nacl_desc_file_info.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
(Empty)
1 /*
2 * Copyright (c) 2014 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 #include "native_client/src/trusted/desc/nacl_desc_file_info.h"
8
9 #include "native_client/src/include/portability.h"
10 #include "native_client/src/public/desc_metadata_types.h"
11 #include "native_client/src/public/nacl_file_info.h"
12 #include "native_client/src/shared/platform/nacl_log.h"
13 #include "native_client/src/trusted/desc/nacl_desc_base.h"
14 #include "native_client/src/trusted/desc/nacl_desc_io.h"
15 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
16
17
18 int NaClDescSetFileToken(struct NaClDesc *desc,
19 struct NaClFileToken const *token) {
20 int error = (*NACL_VTBL(NaClDesc, desc)->
21 SetMetadata)(desc,
22 NACL_DESC_METADATA_FILE_TOKEN_TYPE,
23 sizeof *token, (uint8_t const *) token);
24 if (0 != error) {
25 NaClLog(4, "NaClDescSetFileToken: failed, errno %d\n", -error);
26 return 0;
27 }
28 return 1;
29 }
30
31 int NaClDescGetFileToken(struct NaClDesc *desc,
32 struct NaClFileToken *out_token) {
33 int32_t metadata_type;
34 uint32_t metadata_bytes;
35
36 metadata_bytes = (uint32_t) sizeof *out_token;
37 metadata_type = (*NACL_VTBL(NaClDesc, desc)->
38 GetMetadata)(desc, &metadata_bytes,
39 (uint8_t *) out_token);
40 if (NACL_DESC_METADATA_NONE_TYPE == metadata_type) {
41 NaClLog(4, "NaClDescGetFileToken: no meta data, cannot map\n");
42 return 0;
43 } else if (NACL_DESC_METADATA_FILE_TOKEN_TYPE != metadata_type) {
44 return 0;
45 } else if (metadata_bytes != (uint32_t) sizeof *out_token) {
46 /* there is supposed to be a file token, but wrong size? */
47 NaClLog(LOG_WARNING,
48 "NaClDescGetFileToken: purported file token present,"
49 " but token size is incorrect.\n");
50 return 0;
51 }
52 NaClLog(4,
53 "NaClDescGetFileToken: got token 0x%"NACL_PRIx64":%"NACL_PRIx64"\n",
54 out_token->hi, out_token->lo);
55 return 1;
56 }
57
58 struct NaClDesc *NaClDescIoFromFileInfo(struct NaClFileInfo info,
59 int mode) {
60 struct NaClDesc *desc = NaClDescIoDescFromDescAllocCtor(
61 info.desc, mode);
62 if (NULL == desc) {
63 return NULL;
64 }
65 if (NaClFileTokenIsValid(&info.file_token)) {
66 if (!NaClDescSetFileToken(desc, &info.file_token)) {
67 NaClDescSafeUnref(desc);
68 return NULL;
69 }
70 }
71 return desc;
72 }
OLDNEW
« no previous file with comments | « src/trusted/desc/nacl_desc_file_info.h ('k') | src/trusted/desc_cacheability/desc_cacheability.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698