3 char buf_buf
[BUF_SIZE
+ CLICK_SIZE
];
7 /* SEF functions and variables. */
8 static void sef_local_startup(void);
10 /*===========================================================================*
12 *===========================================================================*/
13 int main(int argc
, char **argv
)
15 endpoint_t ep_self
, ep_requestor
, ep_child
;
21 /* SEF local startup. */
22 env_setargs(argc
, argv
);
26 buf
= (char*) CLICK_CEIL(buf_buf
);
27 fid_send
= open(FIFO_GRANTOR
, O_WRONLY
);
28 fid_get
= open(FIFO_REQUESTOR
, O_RDONLY
);
29 if(fid_get
< 0 || fid_send
< 0) {
30 printf("GRANTOR: can't open fifo files.\n");
34 /* Get the requestor's endpoint. */
35 read(fid_get
, &ep_requestor
, sizeof(ep_requestor
));
36 dprint("GRANTOR: getting requestor's endpoint: %d\n", ep_requestor
);
39 gid
= cpf_grant_direct(ep_requestor
, (long)buf
, BUF_SIZE
,
40 CPF_READ
| CPF_WRITE
| CPF_MAP
);
41 ep_self
= getprocnr();
42 dprint("GRANTOR: sending my endpoint %d and gid %d\n", ep_self
, gid
);
43 write(fid_send
, &ep_self
, sizeof(ep_self
));
44 write(fid_send
, &gid
, sizeof(gid
));
47 buf
[0] = BUF_START_GRANTOR
;
48 FIFO_NOTIFY(fid_send
);
50 CHECK_TEST("GRANTOR", buf
[0], BUF_START_REQUESTOR
, "MAP");
53 buf
[0] = BUF_START_GRANTOR
;
54 FIFO_NOTIFY(fid_send
);
56 CHECK_TEST("GRANTOR", buf
[0], BUF_START_GRANTOR
, "UNMAP");
59 r
= sys_saferevmap_gid(gid
);
61 printf("GRANTOR: error in sys_saferevmap_gid: %d\n", r
);
64 buf
[0] = BUF_START_GRANTOR
+1;
65 FIFO_NOTIFY(fid_send
);
67 CHECK_TEST("GRANTOR", buf
[0], BUF_START_GRANTOR
+1, "REVOKE");
70 FIFO_NOTIFY(fid_send
);
72 buf
[0] = BUF_START_GRANTOR
;
73 FIFO_NOTIFY(fid_send
);
75 CHECK_TEST("GRANTOR", buf
[0], BUF_START_GRANTOR
, "SMAP_COW");
78 r
= sys_saferevmap_gid(gid
);
80 printf("GRANTOR: error in sys_saferevmap_gid: %d\n", r
);
83 buf
[0] = BUF_START_GRANTOR
+1;
86 printf("GRANTOR: error in fork.\n");
90 buf
[0] = BUF_START_GRANTOR
+2;
93 FIFO_NOTIFY(fid_send
);
95 ep_child
= getnprocnr(pid
);
96 if ((r
= sys_privctl(ep_child
, SYS_PRIV_SET_USER
, NULL
)) != OK
) {
97 printf("GRANTOR: unable to set privileges: %d\n", r
);
100 if ((r
= sys_privctl(ep_child
, SYS_PRIV_ALLOW
, NULL
)) != OK
) {
101 printf("GRANTOR: child process can't run: %d\n", r
);
105 FIFO_NOTIFY(fid_send
);
106 CHECK_TEST("GRANTOR", buf
[0], BUF_START_GRANTOR
+1, "COW_SMAP");
108 /* Test COW_SMAP2 (with COW safecopy). */
109 r
= sys_saferevmap_gid(gid
);
111 printf("GRANTOR: error in sys_saferevmap_gid: %d\n", r
);
114 FIFO_NOTIFY(fid_send
);
116 CHECK_TEST("GRANTOR", buf
[0], BUF_START_REQUESTOR
, "COW_SMAP2");
121 /*===========================================================================*
122 * sef_local_startup *
123 *===========================================================================*/
124 static void sef_local_startup()
126 /* Let SEF perform startup. */