xref: /minix/minix/tests/safecopy/requestor.c (revision 433d6423)
1 #include "inc.h"
2 
3 char buf_buf[BUF_SIZE + CLICK_SIZE];
4 
5 endpoint_t ep_granter;
6 int gid;
7 char *buf;
8 
9 /*===========================================================================*
10  *				    test				     *
11  *===========================================================================*/
test(size_t size)12 int test(size_t size)
13 {
14 	u32_t low1, high1;
15 	u32_t low2, high2;
16 	int r;
17 
18 	/* Timing. */
19 	read_tsc(&high1, &low1);
20 	r = sys_safecopyfrom(ep_granter, gid, 0, (long)buf, size);
21 	read_tsc(&high2, &low2);
22 	if(r != OK) {
23 		printf("REQUESTOR: error in safecopy: %d\n", r);
24 		return r;
25 	}
26 	printf("REQUESTOR: SAFECOPY 0x%-8x - %d\n", size, low2 -  low1);
27 
28 	/* Test. */
29 	if(buf[0] != BUF_START) {
30 		printf("REQUESTOR: error in safecopy!\n");
31 		printf("	size, value: %d, %d\n", size, buf[0]);
32 		return r;
33 	}
34 
35 	return OK;
36 }
37 
38 /* SEF functions and variables. */
39 static void sef_local_startup(void);
40 
41 /*===========================================================================*
42  *				    main				     *
43  *===========================================================================*/
main(int argc,char ** argv)44 int main(int argc, char **argv)
45 {
46 	endpoint_t ep_self;
47 	int fid_send, fid_get;
48 	int i;
49 
50 	/* SEF local startup. */
51 	env_setargs(argc, argv);
52 	sef_local_startup();
53 
54 	/* Prepare work. */
55 	buf = (char*) CLICK_CEIL(buf_buf);
56 	fid_get = open(FIFO_GRANTOR, O_RDONLY);
57 	fid_send = open(FIFO_REQUESTOR, O_WRONLY);
58 	if(fid_get < 0 || fid_send < 0) {
59 		printf("REQUESTOR: can't open fifo files.\n");
60 		return 1;
61 	}
62 
63 	/* Sending the endpoint to the granter, in order to let him
64 	 * create the grant.
65 	 */
66 	ep_self = sef_self();
67 	write(fid_send, &ep_self, sizeof(ep_self));
68 	dprint(("REQUESTOR: sending my endpoint: %d\n", ep_self));
69 
70 	/* Getting the granter's endpoint and gid. */
71 	read(fid_get, &ep_granter, sizeof(ep_granter));
72 	read(fid_get, &gid, sizeof(gid));
73 	dprint(("REQUESTOR: getting granter's endpoint %d and gid %d\n",
74 		ep_granter, gid));
75 
76 	/* Test SAFECOPY. */
77 	for(i = 0; i <= TEST_PAGE_SHIFT; i++) {
78 		if(test(1 << i) != OK)
79 			break;
80 	}
81 
82 	/* Notify grantor we are done. */
83 	FIFO_NOTIFY(fid_send);
84 
85 	return 0;
86 }
87 
88 /*===========================================================================*
89  *			       sef_local_startup			     *
90  *===========================================================================*/
sef_local_startup()91 static void sef_local_startup()
92 {
93   /* Let SEF perform startup. */
94   sef_startup();
95 }
96 
97