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

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: win 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;
21 error = (*NACL_VTBL(NaClDesc, desc)->
Mark Seaborn 2014/05/15 00:36:10 Nit: Combine with "int error"
jvoung (off chromium) 2014/05/16 18:02:05 Done.
22 SetMetadata)(desc,
23 NACL_DESC_METADATA_FILE_TOKEN_TYPE,
24 sizeof *token, (uint8_t const *) token);
25 if (0 != error) {
26 NaClLog(4, "NaClDescSetFileToken: failed, errno %d\n", -error);
27 return 0;
28 }
29 return 1;
30 }
31
32 int NaClDescGetFileToken(struct NaClDesc *desc,
33 struct NaClFileToken *out_token) {
34 int32_t metadata_type;
35 uint32_t metadata_bytes;
36
37 metadata_bytes = (uint32_t) sizeof *out_token;
38 metadata_type = (*NACL_VTBL(NaClDesc, desc)->
39 GetMetadata)(desc, &metadata_bytes,
40 (uint8_t *) out_token);
41 if (NACL_DESC_METADATA_NONE_TYPE == metadata_type) {
42 NaClLog(4, "NaClDescGetFileToken: no meta data, cannot map\n");
43 return 0;
44 } else if (NACL_DESC_METADATA_FILE_TOKEN_TYPE != metadata_type) {
45 return 0;
46 } else if (metadata_bytes != (uint32_t) sizeof *out_token) {
47 /* there is supposed to be a file token, but wrong size? */
48 NaClLog(LOG_WARNING,
49 "NaClDescGetFileToken: purported file token present,"
50 " but token size is incorrect.\n");
51 return 0;
52 }
53 NaClLog(4,
54 "NaClDescGetFileToken: got token 0x%"NACL_PRIx64":%"NACL_PRIx64"\n",
55 out_token->hi, out_token->lo);
56 return 1;
57 }
58
59 struct NaClDesc *NaClDescIoFromFileInfo(struct NaClFileInfo info,
60 int mode) {
61 struct NaClDesc* desc = NaClDescIoDescFromHandleAllocCtor(
Mark Seaborn 2014/05/15 00:36:10 Nit: use " *" spacing
jvoung (off chromium) 2014/05/16 18:02:05 Done.
62 (NaClHandle)info.desc, mode);
63 if (NULL == desc) {
64 return NULL;
65 }
66 if (NaClFileTokenIsValid(&info.file_token)) {
67 if (!NaClDescSetFileToken(desc, &info.file_token)) {
68 NaClDescSafeUnref(desc);
69 return NULL;
70 }
71 }
72 return desc;
73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698