Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / native_client / src / trusted / service_runtime / load_file.c
1 /*
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
4  * found in the LICENSE file.
5  */
6
7 #include "native_client/src/trusted/service_runtime/load_file.h"
8
9 #include "native_client/src/trusted/desc/nacl_desc_base.h"
10 #include "native_client/src/trusted/desc/nacl_desc_io.h"
11 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
12 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h"
13 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
14
15
16 NaClErrorCode NaClAppLoadFileFromFilename(struct NaClApp *nap,
17                                           const char *filename) {
18   struct NaClDesc *nd;
19   NaClErrorCode err;
20
21   NaClFileNameForValgrind(filename);
22
23   nd = (struct NaClDesc *) NaClDescIoDescOpen(filename, NACL_ABI_O_RDONLY,
24                                               0666);
25   if (NULL == nd) {
26     return LOAD_OPEN_ERROR;
27   }
28
29   NaClAppLoadModule(nap, nd, NULL, NULL);
30   err = NaClWaitForLoadModuleStatus(nap);
31   NaClDescUnref(nd);
32   nd = NULL;
33
34   if (err != LOAD_OK) {
35     return err;
36   }
37
38   return err;
39 }