Landfall

pkg/landfall-examples/dl_test/dl_test.c

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