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

Unified Diff: components/nacl/loader/nonsfi/irt_filename.cc

Issue 130753003: Implement nacl_irt_filename 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 side-by-side diff with in-line comments
Download patch
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..8d248bb84f5de2b85d56d28a7caa7d22f69c93dd
--- /dev/null
+++ b/components/nacl/loader/nonsfi/irt_filename.cc
@@ -0,0 +1,82 @@
+// 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.
+
+#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 "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;
+}
+
+} // 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),
+};
+
+} // namespace nonsfi
+} // namespace nacl

Powered by Google App Engine
This is Rietveld 408576698