paul@22 | 1 | /* |
paul@22 | 2 | * Test dynamic loading. |
paul@22 | 3 | * |
paul@31 | 4 | * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk> |
paul@22 | 5 | * |
paul@22 | 6 | * This program is free software; you can redistribute it and/or |
paul@22 | 7 | * modify it under the terms of the GNU General Public License as |
paul@22 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@22 | 9 | * the License, or (at your option) any later version. |
paul@22 | 10 | * |
paul@22 | 11 | * This program is distributed in the hope that it will be useful, |
paul@22 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@22 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@22 | 14 | * GNU General Public License for more details. |
paul@22 | 15 | * |
paul@22 | 16 | * You should have received a copy of the GNU General Public License |
paul@22 | 17 | * along with this program; if not, write to the Free Software |
paul@22 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@22 | 19 | * Boston, MA 02110-1301, USA |
paul@22 | 20 | */ |
paul@22 | 21 | |
paul@22 | 22 | #include <l4/util/util.h> |
paul@22 | 23 | #include <dlfcn.h> |
paul@22 | 24 | #include <stdio.h> |
paul@22 | 25 | |
paul@22 | 26 | static const char *libname = "rom/libdl_test_data.so"; |
paul@22 | 27 | |
paul@22 | 28 | int main(void) |
paul@22 | 29 | { |
paul@22 | 30 | const char *buffer; |
paul@22 | 31 | |
paul@22 | 32 | /* Obtain the linked data. */ |
paul@22 | 33 | |
paul@22 | 34 | void *handle = dlopen(libname, RTLD_NOW); |
paul@22 | 35 | const char *(*get_data)(void); |
paul@22 | 36 | |
paul@22 | 37 | if (handle == NULL) |
paul@22 | 38 | { |
paul@22 | 39 | printf("Could not open %s\n", libname); |
paul@22 | 40 | return 1; |
paul@22 | 41 | } |
paul@22 | 42 | |
paul@22 | 43 | get_data = dlsym(handle, "get_data"); |
paul@22 | 44 | |
paul@22 | 45 | /* Load and show the data. */ |
paul@22 | 46 | |
paul@22 | 47 | buffer = get_data(); |
paul@22 | 48 | puts(buffer); |
paul@22 | 49 | |
paul@22 | 50 | l4_sleep_forever(); |
paul@22 | 51 | return 0; |
paul@22 | 52 | } |