summaryrefslogtreecommitdiff
path: root/tests/sys/vm/stack/stack_dlopen_exec_test.c
blob: d4d5fc7c5cf01fef57dcfa3e147e4c3b3b4a5563 (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
/*-
 * Copyright (c) 2023 Dmitry Chagin <dchagin@FreeBSD.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <sys/systm.h>
#include <vm/vm_param.h>

#include <atf-c.h>
#include <dlfcn.h>

static int jumpstack0(void) __noinline;
static int jumpstack1(void) __noinline;

static int (*socheckstack)(void) = NULL;

static int
checkstack(void)
{
	void *fh;

	if (socheckstack == NULL) {
		fh = dlopen("libsoxstack.so", RTLD_LAZY);
		ATF_REQUIRE(fh != NULL);
		socheckstack = dlsym(fh, "checkstack");
		ATF_REQUIRE(socheckstack != NULL);
	}
	return (socheckstack());
}

static int
jumpstack0(void)
{
	char stack[SGROWSIZ];

	explicit_bzero(stack, sizeof(stack));
	return (checkstack());
}

static int
jumpstack1(void)
{
	char stack[SGROWSIZ * 2];

	explicit_bzero(stack, sizeof(stack));
	return (checkstack());
}

ATF_TC_WITHOUT_HEAD(dlopen_test);
ATF_TC_BODY(dlopen_test, tc)
{

	ATF_REQUIRE(jumpstack0() == 0);
	ATF_REQUIRE(jumpstack1() == 0);
}

ATF_TP_ADD_TCS(tp)
{

	ATF_TP_ADD_TC(tp, dlopen_test);

	return (atf_no_error());
}