Back to index

glibc  2.9
tst-dlinfo.c
Go to the documentation of this file.
00001 /* Test for dlinfo.
00002    Copyright (C) 2003 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <dlfcn.h>
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <error.h>
00024 
00025 #define TEST_FUNCTION do_test ()
00026 
00027 static int
00028 do_test (void)
00029 {
00030   int status = 0;
00031 
00032   void *handle = dlopen ("glreflib3.so", RTLD_NOW);
00033   if (handle == NULL)
00034     error (EXIT_FAILURE, 0, "cannot load: glreflib1.so: %s", dlerror ());
00035 
00036 #define TRY(req, arg)                                                       \
00037   if (dlinfo (handle, req, arg) != 0)                                       \
00038     {                                                                \
00039       printf ("dlinfo failed for %s: %s\n", #req, dlerror ());              \
00040       status = 1;                                                    \
00041     }                                                                \
00042   else
00043 
00044   struct link_map *l;
00045   TRY (RTLD_DI_LINKMAP, &l)
00046     {
00047       if (l != handle)
00048        {
00049          printf ("bogus link_map? %p != %p\n", l, handle);
00050          status = 1;
00051        }
00052     }
00053 
00054   char origin[8192];        /* >= PATH_MAX, in theory */
00055   TRY (RTLD_DI_ORIGIN, origin)
00056     {
00057       printf ("origin: %s\n", origin);
00058     }
00059 
00060   Dl_serinfo counts;
00061   TRY (RTLD_DI_SERINFOSIZE, &counts)
00062     {
00063       Dl_serinfo *buf = alloca (counts.dls_size);
00064       buf->dls_cnt = counts.dls_cnt;
00065       buf->dls_size = counts.dls_size;
00066       printf ("%u library directories\n", buf->dls_cnt);
00067       TRY (RTLD_DI_SERINFO, buf)
00068        {
00069          if (counts.dls_cnt != buf->dls_cnt)
00070            {
00071              printf ("??? became %u library directories\n", buf->dls_cnt);
00072              status = 1;
00073            }
00074          for (unsigned int i = 0; i < buf->dls_cnt; ++i)
00075            printf ("\t%#02x\t%s\n",
00076                   buf->dls_serpath[i].dls_flags,
00077                   buf->dls_serpath[i].dls_name);
00078        }
00079     }
00080 
00081   unsigned long int lmid = 0xdeadbeefUL;
00082   if (dlinfo (handle, RTLD_DI_LMID, &lmid) != 0)
00083     printf ("dlinfo refuses RTLD_DI_LMID: %s\n", dlerror ());
00084   else
00085     {
00086       printf ("dlinfo RTLD_DI_LMID worked? %#lx\n", lmid);
00087       status = lmid == 0xdeadbeefUL;
00088     }
00089 
00090 #undef TRY
00091   dlclose (handle);
00092 
00093   return status;
00094 }
00095 
00096 #include "../test-skeleton.c"