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

Side by Side Diff: components/nacl/loader/nonsfi/irt_fdio.cc

Issue 131133002: Implement nacl_irt_fdio for non-sfi mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <errno.h>
6 #include <unistd.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9
10 #include "base/logging.h"
11 #include "components/nacl/loader/nonsfi/abi_conversion.h"
12 #include "components/nacl/loader/nonsfi/irt_interfaces.h"
13 #include "native_client/src/trusted/service_runtime/include/sys/dirent.h"
14 #include "native_client/src/trusted/service_runtime/include/sys/stat.h"
15 #include "native_client/src/trusted/service_runtime/include/sys/unistd.h"
16
17 namespace nacl {
18 namespace nonsfi {
19 namespace {
20
21 int IrtClose(int fd) {
22 if (::close(fd) < 0)
Mark Seaborn 2014/01/10 13:11:20 Same comment about "::" prefix as previous change.
hidehiko 2014/01/15 03:50:44 Done. Also aligned to "if (func(...))" style if ap
23 return errno;
24 return 0;
25 }
26
27 int IrtDup(int fd, int* newfd) {
28 int result = ::dup(fd);
29 if (result < 0)
30 return errno;
31
Mark Seaborn 2014/01/10 13:11:20 Nit: be consistent about whether you have an empty
hidehiko 2014/01/15 03:50:44 Done.
32 *newfd = result;
33 return 0;
34 }
35
36 int IrtDup2(int fd, int newfd) {
37 if (::dup2(fd, newfd) < 0)
38 return errno;
39 return 0;
40 }
41
42 int IrtRead(int fd, void* buf, size_t count, size_t* nread) {
43 ssize_t result = ::read(fd, buf, count);
44 if (result < 0)
45 return errno;
46
47 *nread = result;
48 return 0;
49 }
50
51 int IrtWrite(int fd, const void* buf, size_t count, size_t* nwrote) {
52 ssize_t result = ::write(fd, buf, count);
53 if (result < 0)
54 return errno;
55
56 *nwrote = result;
57 return 0;
58 }
59
60 int IrtSeek(int fd, nacl_abi_off_t offset, int whence,
61 nacl_abi_off_t* new_offset) {
62 off_t result = ::lseek(fd, offset, whence);
63 if (result < 0)
64 return errno;
65 *new_offset = result;
66 return 0;
67 }
68
69 int IrtFstat(int fd, struct nacl_abi_stat* st) {
70 struct stat host_st;
71 if (::fstat(fd, &host_st) < 0)
72 return errno;
73
74 StatToNaClAbiStat(host_st, st);
75 return 0;
76 }
77
78 int IrtGetDents(int fd, struct nacl_abi_dirent* buf, size_t count,
79 size_t* nread) {
80 // Note: getdents() can return several directory entries in packed format.
81 // So, here, because we need to convert the abi from host's to nacl's,
82 // there is no straightforward way to ensure reading only entries which can
83 // be fit to the buf after abi conversion actually.
84 // TODO(https://code.google.com/p/nativeclient/issues/detail?id=3734):
85 // Implement this method.
86 return ENOSYS;
87 }
88
89 } // namespace
90
91 // for seek, fstat and getdents, their argument types should be nacl_abi_X,
Mark Seaborn 2014/01/10 13:11:20 Nit: capitalise as "For"
hidehiko 2014/01/15 03:50:44 Done.
92 // rather than host type, such as off_t, struct stat or struct dirent.
93 // However, the definition of nacl_irt_fdio uses host types, so here we need
94 // to cast them.
95 const nacl_irt_fdio kIrtFdIO = {
96 IrtClose,
97 IrtDup,
98 IrtDup2,
99 IrtRead,
100 IrtWrite,
101 reinterpret_cast<int(*)(int, off_t, int, off_t*)>(IrtSeek),
102 reinterpret_cast<int(*)(int, struct stat*)>(IrtFstat),
103 reinterpret_cast<int(*)(int, struct dirent*, size_t, size_t*)>(IrtGetDents),
104 };
105
106 } // namespace nonsfi
107 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698