Chromium Code Reviews| Index: components/nacl/loader/nonsfi/irt_filename.cc |
| diff --git a/components/nacl/loader/nonsfi/irt_filename.cc b/components/nacl/loader/nonsfi/irt_filename.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bb9724c49ea8045c3d4a9c5595f7673e62529124 |
| --- /dev/null |
| +++ b/components/nacl/loader/nonsfi/irt_filename.cc |
| @@ -0,0 +1,123 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
|
Mark Seaborn
2014/02/07 22:53:43
Can you leave out the implementation of irt_filena
|
| +#include <errno.h> |
| +#include <sys/types.h> |
| +#include <sys/stat.h> |
| +#include <fcntl.h> |
| + |
| +#include "base/logging.h" |
| +#include "components/nacl/loader/nonsfi/abi_conversion.h" |
| +#include "components/nacl/loader/nonsfi/irt_interfaces.h" |
| +#include "components/nacl/loader/nonsfi/irt_util.h" |
| +#include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" |
| +#include "native_client/src/trusted/service_runtime/include/sys/stat.h" |
| + |
| +namespace nacl { |
| +namespace nonsfi { |
| +namespace { |
| + |
| +int IrtOpen( |
| + const char* pathname, int oflag, nacl_abi_mode_t cmode, int* new_fd) { |
| + // Some flags are ignored. Please see also NaClSysOpen |
| + // native_client/src/trusted/service_runtime/sys_filename.c. |
| + int flags; |
| + switch(oflag & NACL_ABI_O_ACCMODE) { |
| + case NACL_ABI_O_RDONLY: |
| + flags = O_RDONLY; |
| + break; |
| + case NACL_ABI_O_WRONLY: |
| + flags = O_WRONLY; |
| + break; |
| + case NACL_ABI_O_RDWR: |
| + flags = O_RDWR; |
| + break; |
| + default: |
| + LOG(WARNING) << "Unknown accmode: " << (oflag & NACL_ABI_O_ACCMODE); |
| + flags = O_RDONLY; |
| + } |
| + if (oflag & NACL_ABI_O_CREAT) |
| + flags |= O_CREAT; |
| + if (oflag & NACL_ABI_O_TRUNC) |
| + flags |= O_TRUNC; |
| + if (oflag & NACL_ABI_O_APPEND) |
| + flags |= O_APPEND; |
| + |
| + mode_t mode = 0; |
| + if (cmode & NACL_ABI_S_IRUSR) |
| + mode |= S_IRUSR; |
| + if (cmode & NACL_ABI_S_IWUSR) |
| + mode |= S_IWUSR; |
| + if (cmode & NACL_ABI_S_IXUSR) |
| + mode |= S_IXUSR; |
| + |
| + int fd = ::open(pathname, flags, mode); |
| + if (fd < 0) |
| + return errno; |
| + |
| + *new_fd = fd; |
| + return 0; |
| +} |
| + |
| +int IrtStat(const char* pathname, struct nacl_abi_stat* st) { |
| + struct stat host_st; |
| + if (::stat(pathname, &host_st) < 0) |
| + return errno; |
| + |
| + StatToNaClAbiStat(host_st, st); |
| + return 0; |
| +} |
| + |
| +#if 1 |
| +int IrtGetCwd(char* pathname, size_t len) { |
| + if (getcwd(pathname, len) == NULL) |
| + return errno; |
| + return 0; |
| +} |
| + |
| +int IrtUnlink(const char* pathname) { |
| + return CheckError(unlink(pathname)); |
| +} |
| + |
| +// TODO |
| +int IrtOpenResource(const char* name, int* fd) { |
| + return ENOSYS; |
| +} |
| + |
| +#endif |
| +} // namespace |
| + |
| +// Both open and stat should use nacl_abi_X for their argument types, rather |
| +// than host type, such as struct stat or mode_t. However, the definition |
| +// of nacl_irt_filename uses host types, so here we need to cast them. |
| +const nacl_irt_filename kIrtFileName = { |
| + reinterpret_cast<int(*)(const char*, int, mode_t, int*)>(IrtOpen), |
| + reinterpret_cast<int(*)(const char*, struct stat*)>(IrtStat), |
| +}; |
| + |
| +const nacl_irt_dev_filename kIrtDevFileName = { |
| + reinterpret_cast<int(*)(const char*, int, mode_t, int*)>(IrtOpen), |
| + reinterpret_cast<int(*)(const char*, struct stat*)>(IrtStat), |
| + NULL, // mkdir |
| + NULL, // rmdir |
| + NULL, // chdir |
| + IrtGetCwd, |
| + IrtUnlink, |
| + NULL, // truncate |
| + NULL, // lstat |
| + NULL, // link |
| + NULL, // rename |
| + NULL, // symlink |
| + NULL, // chmod |
| + NULL, // access |
| + NULL, // readlink |
| + NULL, // utimes |
| +}; |
| + |
| +const nacl_irt_resource_open kIrtResourceOpen = { |
| + IrtOpenResource, |
| +}; |
| + |
| +} // namespace nonsfi |
| +} // namespace nacl |