summaryrefslogtreecommitdiff
path: root/410user/progs/swexn_uninstall_test.c
blob: 34d898f749fddd20ed993a07d8479f2389e64b9e (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
/**
 * @file swexn_basic_test.c
 * @author bblum
 * @brief Tests uninstalling handlers
 * @public yes
 * @for p4
 */

#include <stddef.h>
#include <stdlib.h>
#include <syscall.h>
#include "410_tests.h"

DEF_TEST_NAME("swexn_uninstall_test:");

#define STAQ_SIZE (4096)
char exn_staq[STAQ_SIZE];
#define EXN_STAQ_TOP ((void *)(&exn_staq[STAQ_SIZE-8]))

#define BAD_MEMORY ((void *)0x40000000)

volatile int success = 0;

void handler(void *arg, ureg_t *uregs)
{
	REPORT_MISC("Uh-oh, we weren't supposed to be called!");
	REPORT_END_FAIL;
	exit(-1);
	return;
}

int main()
{
	int ret;
	void (*x)() = (typeof(x))NULL;

	REPORT_START_ABORT;

	ret = swexn(EXN_STAQ_TOP, handler, NULL, NULL);
	if (ret < 0) {
		REPORT_MISC("swexn call rejected");
		REPORT_END_FAIL;
		exit(-1);
	}

	/* uninstall */
	ret = swexn(NULL, NULL, NULL, NULL);
	if (ret < 0) {
		REPORT_MISC("swexn call rejected (2)");
		REPORT_END_FAIL;
		exit(-1);
	}

	/* Invoke handler */
	success = *(int *)BAD_MEMORY;

	REPORT_MISC("D:");
	REPORT_END_FAIL;
	exit(-1);
}