Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / components / nacl / loader / nonsfi / irt_interfaces.cc
blob41582d6b1b0f0b1afd906319448435a6bc26330e
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.
5 #include "components/nacl/loader/nonsfi/irt_interfaces.h"
7 #include <cstring>
9 namespace nacl {
10 namespace nonsfi {
12 namespace {
14 // This table keeps a pair of IRT entry (such as nacl_irt_basic, nacl_irt_fdio
15 // etc.) and its registered name with its version (such as NACL_IRT_BASIC_v0_1,
16 // NACL_IRT_DEV_FDIO_v0_1, etc.).
17 struct NaClInterfaceTable {
18 const char* name;
19 const void* table;
20 size_t size;
23 #define NACL_INTERFACE_TABLE(name, value) { name, &value, sizeof(value) }
24 const NaClInterfaceTable kIrtInterfaces[] = {
25 NACL_INTERFACE_TABLE(NACL_IRT_BASIC_v0_1, kIrtBasic),
26 NACL_INTERFACE_TABLE(NACL_IRT_FDIO_v0_1, kIrtFdIO),
27 NACL_INTERFACE_TABLE(NACL_IRT_MEMORY_v0_3, kIrtMemory),
28 NACL_INTERFACE_TABLE(NACL_IRT_THREAD_v0_1, kIrtThread),
29 NACL_INTERFACE_TABLE(NACL_IRT_FUTEX_v0_1, kIrtFutex),
30 NACL_INTERFACE_TABLE(NACL_IRT_TLS_v0_1, kIrtTls),
31 NACL_INTERFACE_TABLE(NACL_IRT_CLOCK_v0_1, kIrtClock),
32 NACL_INTERFACE_TABLE(NACL_IRT_PPAPIHOOK_v0_1, kIrtPpapiHook),
33 NACL_INTERFACE_TABLE(NACL_IRT_RESOURCE_OPEN_v0_1, kIrtResourceOpen),
34 NACL_INTERFACE_TABLE(NACL_IRT_RANDOM_v0_1, kIrtRandom),
35 NACL_INTERFACE_TABLE(NACL_IRT_EXCEPTION_HANDLING_v0_1, kIrtExceptionHandling),
36 #if defined(__arm__)
37 NACL_INTERFACE_TABLE(NACL_IRT_ICACHE_v0_1, kIrtIcache),
38 #endif
40 #undef NACL_INTERFACE_TABLE
42 } // namespace
44 size_t NaClIrtInterface(const char* interface_ident,
45 void* table, size_t tablesize) {
46 for (size_t i = 0; i < arraysize(kIrtInterfaces); ++i) {
47 if (std::strcmp(interface_ident, kIrtInterfaces[i].name) == 0) {
48 const size_t size = kIrtInterfaces[i].size;
49 if (size <= tablesize) {
50 std::memcpy(table, kIrtInterfaces[i].table, size);
51 return size;
53 break;
56 return 0;
59 } // namespace nonsfi
60 } // namespace nacl