summaryrefslogtreecommitdiff
path: root/libexec/rtld-elf/tests/dlopen_test.c
blob: ab1e8da1cb416c451df516e8f0c3d909ad3f6d11 (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
/*-
 *
 * Copyright (C) 2024 Kyle Evans <kevans@FreeBSD.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 *
 */

#include <dlfcn.h>

#include <atf-c.h>

ATF_TC_WITHOUT_HEAD(dlopen_basic);
ATF_TC_BODY(dlopen_basic, tc)
{
	void *hdl, *sym;

	hdl = dlopen("libthr.so", RTLD_NOW);
	ATF_REQUIRE(hdl != NULL);

	sym = dlsym(hdl, "pthread_create");
	ATF_REQUIRE(sym != NULL);

	dlclose(hdl);

	sym = dlsym(hdl, "pthread_create");
	ATF_REQUIRE(sym == NULL);
}

ATF_TC_WITHOUT_HEAD(dlopen_recursing);
ATF_TC_BODY(dlopen_recursing, tc)
{
	void *hdl;

	/*
	 * If this doesn't crash, we're OK; a regression at one point caused
	 * some infinite recursion here.
	 */
	hdl = dlopen("libthr.so", RTLD_NOW | RTLD_GLOBAL);
	ATF_REQUIRE(hdl != NULL);

	dlclose(hdl);
}

ATF_TP_ADD_TCS(tp)
{

	ATF_TP_ADD_TC(tp, dlopen_basic);
	ATF_TP_ADD_TC(tp, dlopen_recursing);

	return atf_no_error();
}