OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 // A crazy linker test to: |
| 6 // - Load a library (libfoo.so) with the linker. |
| 7 // - Find the address of the "Foo" function in it. |
| 8 // - Call the function. |
| 9 // - Close the library. |
| 10 |
| 11 #include <stdio.h> |
| 12 #include <crazy_linker.h> |
| 13 |
| 14 #include "test_util.h" |
| 15 |
| 16 typedef void (*FunctionPtr)(); |
| 17 |
| 18 int main() { |
| 19 crazy_context_t* context = crazy_context_create(); |
| 20 crazy_library_t* library; |
| 21 |
| 22 // DEBUG |
| 23 crazy_context_set_load_address(context, 0x20000000); |
| 24 |
| 25 // Load libfoo.so |
| 26 if (!crazy_library_open(&library, "libfoo.so", context)) { |
| 27 Panic("Could not open library: %s\n", crazy_context_get_error(context)); |
| 28 } |
| 29 |
| 30 // Find the "Foo" symbol. |
| 31 FunctionPtr foo_func; |
| 32 if (!crazy_library_find_symbol( |
| 33 library, "Foo", reinterpret_cast<void**>(&foo_func))) { |
| 34 Panic("Could not find 'Foo' in libfoo.so\n"); |
| 35 } |
| 36 |
| 37 // Call it. |
| 38 (*foo_func)(); |
| 39 |
| 40 // Close the library. |
| 41 printf("Closing libfoo.so\n"); |
| 42 crazy_library_close(library); |
| 43 |
| 44 crazy_context_destroy(context); |
| 45 |
| 46 return 0; |
| 47 } |
OLD | NEW |