1 // User-level IPC library routines
4 // Receive a value via IPC and return it.
5 // If 'pg' is nonnull, then any page sent by the sender will be mapped at
7 // If 'fromenv' is nonnull, then store the IPC sender's envid in *fromenv.
8 // If 'perm' is nonnull, then store the IPC sender's page permission in *perm
9 // (this is nonzero iff a page was successfully transferred to 'pg').
10 // If the system call fails, then store 0 in *fromenv and *perm (if
11 // they're nonnull) and return the error.
14 // Use 'env' to discover the value and who sent it.
15 // If 'pg' is null, pass sys_ipc_recv a value that it will understand
16 // as meaning "no page". (Zero is not the right value.)
18 ipc_recv(envid_t
*from_env_store
, void *pg
, int *perm_store
)
20 // LAB 4: Your code here.
24 pg
= (void *)USTACKTOP
;
26 if ((r
= sys_ipc_recv(pg
)) < 0) {
34 *from_env_store
= env
->env_ipc_from
;
36 *perm_store
= env
->env_ipc_perm
;
37 return env
->env_ipc_value
;
41 // Send 'val' (and 'pg' with 'perm', assuming 'pg' is nonnull) to 'toenv'.
42 // This function keeps trying until it succeeds.
43 // It should panic() on any error other than -E_IPC_NOT_RECV.
46 // Use sys_yield() to be CPU-friendly.
47 // If 'pg' is null, pass sys_ipc_recv a value that it will understand
48 // as meaning "no page". (Zero is not the right value.)
50 ipc_send(envid_t to_env
, uint32_t val
, void *pg
, int perm
)
52 // LAB 4: Your code here.
56 r
= sys_ipc_try_send(to_env
, val
, pg
, perm
);
59 if (r
!= -E_IPC_NOT_RECV
)
60 panic("sys_ipc_try_send error: %e", r
);