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.
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 "components/nacl/loader/nonsfi/irt_util.h"
14 #include "native_client/src/trusted/service_runtime/include/sys/dirent.h"
15 #include "native_client/src/trusted/service_runtime/include/sys/stat.h"
16 #include "native_client/src/trusted/service_runtime/include/sys/unistd.h"
22 int IrtClose(int fd
) {
23 return CheckError(close(fd
));
26 int IrtDup(int fd
, int* newfd
) {
27 return CheckErrorWithResult(dup(fd
), newfd
);
30 int IrtDup2(int fd
, int newfd
) {
31 return CheckError(dup2(fd
, newfd
));
34 int IrtRead(int fd
, void* buf
, size_t count
, size_t* nread
) {
35 return CheckErrorWithResult(read(fd
, buf
, count
), nread
);
38 int IrtWrite(int fd
, const void* buf
, size_t count
, size_t* nwrote
) {
39 return CheckErrorWithResult(write(fd
, buf
, count
), nwrote
);
42 int IrtSeek(int fd
, nacl_abi_off_t offset
, int whence
,
43 nacl_abi_off_t
* new_offset
) {
44 return CheckErrorWithResult(lseek(fd
, offset
, whence
), new_offset
);
47 int IrtFstat(int fd
, struct nacl_abi_stat
* st
) {
49 if (fstat(fd
, &host_st
))
52 StatToNaClAbiStat(host_st
, st
);
56 int IrtGetDents(int fd
, struct nacl_abi_dirent
* buf
, size_t count
,
58 // Note: getdents() can return several directory entries in packed format.
59 // So, here, because we need to convert the abi from host's to nacl's,
60 // there is no straightforward way to ensure reading only entries which can
61 // be fit to the buf after abi conversion actually.
62 // TODO(https://code.google.com/p/nativeclient/issues/detail?id=3734):
63 // Implement this method.
69 // For seek, fstat and getdents, their argument types should be nacl_abi_X,
70 // rather than host type, such as off_t, struct stat or struct dirent.
71 // However, the definition of nacl_irt_fdio uses host types, so here we need
73 const nacl_irt_fdio kIrtFdIO
= {
79 reinterpret_cast<int(*)(int, off_t
, int, off_t
*)>(IrtSeek
),
80 reinterpret_cast<int(*)(int, struct stat
*)>(IrtFstat
),
81 reinterpret_cast<int(*)(int, struct dirent
*, size_t, size_t*)>(IrtGetDents
),