aboutsummaryrefslogtreecommitdiff
path: root/elf/tst-dlmopen2.c
blob: 8489ffba08a8545fe4dd28db8daad0675abeb780 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <dlfcn.h>
#include <stdio.h>
#include <string.h>
#include <gnu/lib-names.h>
#include <ldsodefs.h>


static int
do_test (void)
{
  int result = 0;

  for (int i = 1; i <= 10; ++i)
    {
      void *h[DL_NNS - 1];
      char used[DL_NNS];

      printf ("round %d\n", i);

      memset (used, '\0', sizeof (used));
      used[LM_ID_BASE] = 1;

      for (int j = 0; j < DL_NNS - 1; ++j)
	{
	  h[j] = dlmopen (LM_ID_NEWLM, "$ORIGIN/tst-dlmopen1mod.so",
			  RTLD_LAZY);
	  if (h[j] == NULL)
	    {
	      printf ("round %d, namespace %d: load failed: %s\n",
		      i, j, dlerror ());
	      return 1;
	    }
	  Lmid_t ns;
	  if (dlinfo (h[j], RTLD_DI_LMID, &ns) != 0)
	    {
	      printf ("round %d, namespace %d: dlinfo failed: %s\n",
		      i, j, dlerror ());
	      return 1;
	    }
	  if (ns < 0 || ns >= DL_NNS)
	    {
	      printf ("round %d, namespace %d: invalid namespace %ld",
		      i, j, (long int) ns);
	      result = 1;
	    }
	  else if (used[ns] != 0)
	    {
	      printf ("\
round %d, namespace %d: duplicate allocate of namespace %ld",
		      i, j, (long int) ns);
	      result = 1;
	    }
	  else
	    used[ns] = 1;
	}

      for (int j = 0; j < DL_NNS - 1; ++j)
	if (dlclose (h[j]) != 0)
	  {
	    printf ("round %d, namespace %d: close failed: %s\n",
		    i, j, dlerror ());
	    return 1;
	  }
    }

  return result;
}

#include <support/test-driver.c>