OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "components/nacl/loader/nonsfi/irt_interfaces.h" |
| 6 |
| 7 #include <cstring> |
| 8 |
| 9 namespace nacl { |
| 10 namespace nonsfi { |
| 11 |
| 12 namespace { |
| 13 |
| 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_FDIO_v0_1, etc.). |
| 17 struct NaClInterfaceTable { |
| 18 const char* name; |
| 19 const void* table; |
| 20 size_t size; |
| 21 }; |
| 22 |
| 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 }; |
| 27 #undef NACL_INTERFACE_TABLE |
| 28 |
| 29 } // namespace |
| 30 |
| 31 size_t NaClIrtInterface(const char* interface_ident, |
| 32 void* table, size_t tablesize) { |
| 33 for (size_t i = 0; i < arraysize(kIrtInterfaces); ++i) { |
| 34 if (std::strcmp(interface_ident, kIrtInterfaces[i].name) == 0) { |
| 35 const size_t size = kIrtInterfaces[i].size; |
| 36 if (size <= tablesize) { |
| 37 std::memcpy(table, kIrtInterfaces[i].table, size); |
| 38 return size; |
| 39 } |
| 40 break; |
| 41 } |
| 42 } |
| 43 return 0; |
| 44 } |
| 45 |
| 46 } // namespace nonsfi |
| 47 } // namespace nacl |
OLD | NEW |