| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "native_client/src/include/nacl_macros.h" | 9 #include "native_client/src/include/nacl_macros.h" |
| 10 #include "native_client/src/untrusted/irt/irt_dev.h" | 10 #include "native_client/src/untrusted/irt/irt_dev.h" |
| 11 #include "native_client/src/untrusted/irt/irt_extension.h" | 11 #include "native_client/src/untrusted/irt/irt_extension.h" |
| 12 #include "native_client/src/untrusted/nacl/nacl_irt.h" | 12 #include "native_client/src/untrusted/nacl/nacl_irt.h" |
| 13 | 13 |
| 14 static size_t ext_struct_memcpy_init(void *dest_table, const void *src_table, | |
| 15 size_t tablesize) { | |
| 16 memcpy(dest_table, src_table, tablesize); | |
| 17 return tablesize; | |
| 18 } | |
| 19 | |
| 20 struct nacl_irt_ext_struct { | 14 struct nacl_irt_ext_struct { |
| 21 const char *interface_ident; | 15 const char *interface_ident; |
| 22 void *table; | 16 void *table; |
| 23 size_t tablesize; | 17 size_t tablesize; |
| 24 }; | 18 }; |
| 25 | 19 |
| 26 static const struct nacl_irt_ext_struct nacl_irt_ext_structs[] = { | 20 static const struct nacl_irt_ext_struct nacl_irt_ext_structs[] = { |
| 27 { | 21 { |
| 28 .interface_ident = NACL_IRT_DEV_FDIO_v0_3, | 22 .interface_ident = NACL_IRT_DEV_FDIO_v0_3, |
| 29 .table = &__libnacl_irt_dev_fdio, | 23 .table = &__libnacl_irt_dev_fdio, |
| 30 .tablesize = sizeof(__libnacl_irt_dev_fdio) | 24 .tablesize = sizeof(__libnacl_irt_dev_fdio), |
| 31 }, { | |
| 32 .interface_ident = NACL_IRT_DEV_FDIO_v0_2, | |
| 33 .table = &__libnacl_irt_dev_fdio, | |
| 34 .tablesize = sizeof(struct nacl_irt_dev_fdio_v0_2) | |
| 35 }, { | |
| 36 .interface_ident = NACL_IRT_FDIO_v0_1, | |
| 37 .table = &__libnacl_irt_fdio, | |
| 38 .tablesize = sizeof(__libnacl_irt_fdio) | |
| 39 }, { | 25 }, { |
| 40 .interface_ident = NACL_IRT_DEV_FILENAME_v0_3, | 26 .interface_ident = NACL_IRT_DEV_FILENAME_v0_3, |
| 41 .table = &__libnacl_irt_dev_filename, | 27 .table = &__libnacl_irt_dev_filename, |
| 42 .tablesize = sizeof(__libnacl_irt_dev_filename) | 28 .tablesize = sizeof(__libnacl_irt_dev_filename), |
| 43 }, { | 29 }, { |
| 44 .interface_ident = NACL_IRT_DEV_FILENAME_v0_2, | 30 .interface_ident = NACL_IRT_MEMORY_v0_3, |
| 45 .table = &__libnacl_irt_dev_filename, | 31 .table = &__libnacl_irt_memory, |
| 46 .tablesize = sizeof(struct nacl_irt_dev_filename_v0_2) | 32 .tablesize = sizeof(struct nacl_irt_memory), |
| 47 }, { | |
| 48 .interface_ident = NACL_IRT_FILENAME_v0_1, | |
| 49 .table = &__libnacl_irt_dev_filename, | |
| 50 .tablesize = sizeof(struct nacl_irt_filename) | |
| 51 }, | 33 }, |
| 52 }; | 34 }; |
| 53 | 35 |
| 54 size_t nacl_interface_ext_supply(const char *interface_ident, | 36 size_t nacl_interface_ext_supply(const char *interface_ident, |
| 55 const void *table, size_t tablesize) { | 37 const void *table, size_t tablesize) { |
| 56 for (int i = 0; i < NACL_ARRAY_SIZE(nacl_irt_ext_structs); i++) { | 38 for (int i = 0; i < NACL_ARRAY_SIZE(nacl_irt_ext_structs); i++) { |
| 57 if (nacl_irt_ext_structs[i].tablesize == tablesize && | 39 if (nacl_irt_ext_structs[i].tablesize == tablesize && |
| 58 strcmp(nacl_irt_ext_structs[i].interface_ident, interface_ident) == 0) { | 40 strcmp(nacl_irt_ext_structs[i].interface_ident, interface_ident) == 0) { |
| 59 return ext_struct_memcpy_init(nacl_irt_ext_structs[i].table, | 41 memcpy(nacl_irt_ext_structs[i].table, table, tablesize); |
| 60 table, | 42 return tablesize; |
| 61 tablesize); | |
| 62 } | 43 } |
| 63 } | 44 } |
| 64 | 45 |
| 65 return 0; | 46 return 0; |
| 66 } | 47 } |
| OLD | NEW |