Index: components/nacl/loader/nonsfi/irt/irt_interfaces.cc |
diff --git a/components/nacl/loader/nonsfi/irt/irt_interfaces.cc b/components/nacl/loader/nonsfi/irt/irt_interfaces.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7e7629a1040e72c689295432d0011891a1dd9306 |
--- /dev/null |
+++ b/components/nacl/loader/nonsfi/irt/irt_interfaces.cc |
@@ -0,0 +1,52 @@ |
+// 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 "components/nacl/loader/nonsfi/irt/irt_interfaces.h" |
+ |
+#include <cstring> |
+ |
+namespace nacl { |
+namespace nonsfi { |
+ |
+extern const struct nacl_irt_basic kIrtBasic; |
Mark Seaborn
2014/01/07 09:45:06
This is already declared in the header
hidehiko
2014/01/07 11:52:29
Oops. I misoperated...
|
+ |
+namespace { |
+ |
+// This table keeps a pair of IRT entry (such as nacl_irt_basic, nacl_irt_fdio |
+// etc.) and its registered name with its version (such as NACL_IRT_BASIC_v0_1, |
+// NACL_IRT_FDIO_v0_1, etc.). |
+struct NaClInterfaceTable { |
+ const char* name; |
+ const void* table; |
+ size_t size; |
+ |
+ template<typename T> |
+ NaClInterfaceTable(const char* name, const T& value) |
Mark Seaborn
2014/01/07 09:45:06
I'm pretty sure using a constructor like this make
hidehiko
2014/01/07 11:52:29
I see, done.
|
+ : name(name), table(&value), size(sizeof(value)) { |
+ } |
+}; |
+ |
+const NaClInterfaceTable kIrtInterfaces[] = { |
+ NaClInterfaceTable(NACL_IRT_BASIC_v0_1, kIrtBasic), |
+}; |
+ |
+} // namespace |
+ |
+size_t NaClIrtInterface(const char* interface_ident, |
+ void* table, size_t tablesize) { |
+ for (size_t i = 0; i < arraysize(kIrtInterfaces); ++i) { |
+ if (std::strcmp(interface_ident, kIrtInterfaces[i].name) == 0) { |
+ const size_t size = kIrtInterfaces[i].size; |
+ if (size <= tablesize) { |
+ std::memcpy(table, kIrtInterfaces[i].table, size); |
+ return size; |
+ } |
+ break; |
+ } |
+ } |
+ return 0; |
+} |
+ |
+} // namespace nonsfi |
+} // namespace nacl |