xref: /minix3/minix/tests/kernel/sys_vumap/vumaprelay.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc /* Test for sys_vumap() - by D.C. van Moolenbroek */
2*433d6423SLionel Sambuc #include <minix/drivers.h>
3*433d6423SLionel Sambuc #include <assert.h>
4*433d6423SLionel Sambuc 
5*433d6423SLionel Sambuc #include "com.h"
6*433d6423SLionel Sambuc 
do_request(message * m)7*433d6423SLionel Sambuc static int do_request(message *m)
8*433d6423SLionel Sambuc {
9*433d6423SLionel Sambuc 	struct vumap_vir vvec[MAPVEC_NR + 3];
10*433d6423SLionel Sambuc 	struct vumap_phys pvec[MAPVEC_NR + 3];
11*433d6423SLionel Sambuc 	int r, r2, access, vcount, pcount;
12*433d6423SLionel Sambuc 	size_t offset;
13*433d6423SLionel Sambuc 
14*433d6423SLionel Sambuc 	assert(m->m_type == VTR_RELAY);
15*433d6423SLionel Sambuc 
16*433d6423SLionel Sambuc 	vcount = m->VTR_VCOUNT;
17*433d6423SLionel Sambuc 	pcount = m->VTR_PCOUNT;
18*433d6423SLionel Sambuc 	offset = m->VTR_OFFSET;
19*433d6423SLionel Sambuc 	access = m->VTR_ACCESS;
20*433d6423SLionel Sambuc 
21*433d6423SLionel Sambuc 	r2 = sys_safecopyfrom(m->m_source, m->VTR_VGRANT, 0, (vir_bytes) vvec,
22*433d6423SLionel Sambuc 		sizeof(vvec[0]) * vcount);
23*433d6423SLionel Sambuc 	assert(r2 == OK);
24*433d6423SLionel Sambuc 
25*433d6423SLionel Sambuc 	r = sys_vumap(m->m_source, vvec, vcount, offset, access, pvec,
26*433d6423SLionel Sambuc 		&pcount);
27*433d6423SLionel Sambuc 
28*433d6423SLionel Sambuc 	if (pcount >= 1 && pcount <= MAPVEC_NR + 3) {
29*433d6423SLionel Sambuc 		r2 = sys_safecopyto(m->m_source, m->VTR_PGRANT, 0,
30*433d6423SLionel Sambuc 			(vir_bytes) pvec, sizeof(pvec[0]) * pcount);
31*433d6423SLionel Sambuc 		assert(r2 == OK);
32*433d6423SLionel Sambuc 	}
33*433d6423SLionel Sambuc 
34*433d6423SLionel Sambuc 	m->VTR_PCOUNT = pcount;
35*433d6423SLionel Sambuc 
36*433d6423SLionel Sambuc 	return r;
37*433d6423SLionel Sambuc }
38*433d6423SLionel Sambuc 
sef_cb_init_fresh(int UNUSED (type),sef_init_info_t * UNUSED (info))39*433d6423SLionel Sambuc static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
40*433d6423SLionel Sambuc {
41*433d6423SLionel Sambuc 	return OK;
42*433d6423SLionel Sambuc }
43*433d6423SLionel Sambuc 
sef_cb_signal_handler(int sig)44*433d6423SLionel Sambuc static void sef_cb_signal_handler(int sig)
45*433d6423SLionel Sambuc {
46*433d6423SLionel Sambuc 	if (sig == SIGTERM)
47*433d6423SLionel Sambuc 		exit(0);
48*433d6423SLionel Sambuc }
49*433d6423SLionel Sambuc 
sef_local_startup(void)50*433d6423SLionel Sambuc static void sef_local_startup(void)
51*433d6423SLionel Sambuc {
52*433d6423SLionel Sambuc 	sef_setcb_init_fresh(sef_cb_init_fresh);
53*433d6423SLionel Sambuc 	sef_setcb_signal_handler(sef_cb_signal_handler);
54*433d6423SLionel Sambuc 
55*433d6423SLionel Sambuc 	sef_startup();
56*433d6423SLionel Sambuc }
57*433d6423SLionel Sambuc 
main(int argc,char ** argv)58*433d6423SLionel Sambuc int main(int argc, char **argv)
59*433d6423SLionel Sambuc {
60*433d6423SLionel Sambuc 	message m;
61*433d6423SLionel Sambuc 	int r;
62*433d6423SLionel Sambuc 
63*433d6423SLionel Sambuc 	env_setargs(argc, argv);
64*433d6423SLionel Sambuc 
65*433d6423SLionel Sambuc 	sef_local_startup();
66*433d6423SLionel Sambuc 
67*433d6423SLionel Sambuc 	for (;;) {
68*433d6423SLionel Sambuc 		if ((r = sef_receive(ANY, &m)) != OK)
69*433d6423SLionel Sambuc 			panic("sef_receive failed (%d)\n", r);
70*433d6423SLionel Sambuc 
71*433d6423SLionel Sambuc 		m.m_type = do_request(&m);
72*433d6423SLionel Sambuc 
73*433d6423SLionel Sambuc 		ipc_send(m.m_source, &m);
74*433d6423SLionel Sambuc 	}
75*433d6423SLionel Sambuc 
76*433d6423SLionel Sambuc 	return 0;
77*433d6423SLionel Sambuc }
78