mirror of
https://github.com/drasko/codezero.git
synced 2026-05-30 05:45:58 +02:00
Clarified a few confusing definitions in ipc.c
This commit is contained in:
@@ -63,12 +63,11 @@ int main(int argc, char *argv[])
|
|||||||
user_mutex_test();
|
user_mutex_test();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
exectest(parent_of_all);
|
exectest(parent_of_all);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
wait_pager(pagerid);
|
wait_pager(pagerid);
|
||||||
*/
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,10 +39,10 @@
|
|||||||
#define IPC_EXTENDED_MAX_SIZE L4_IPC_EXTENDED_MAX_SIZE
|
#define IPC_EXTENDED_MAX_SIZE L4_IPC_EXTENDED_MAX_SIZE
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ipc syscall uses an ipc_type variable and send/recv
|
* ipc syscall uses an ipc_dir variable and send/recv
|
||||||
* details are embedded in this variable.
|
* details are embedded in this variable.
|
||||||
*/
|
*/
|
||||||
enum IPC_TYPE {
|
enum IPC_DIR {
|
||||||
IPC_INVALID = 0,
|
IPC_INVALID = 0,
|
||||||
IPC_SEND = 1,
|
IPC_SEND = 1,
|
||||||
IPC_RECV = 2,
|
IPC_RECV = 2,
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ static inline l4id_t tid_to_cid(l4id_t tid)
|
|||||||
return (tid & TASK_CID_MASK) >> TASK_CID_SHIFT;
|
return (tid & TASK_CID_MASK) >> TASK_CID_SHIFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int task_id_special(l4id_t id)
|
static inline int tid_special_value(l4id_t id)
|
||||||
{
|
{
|
||||||
/* Special ids have top 2 nibbles all set */
|
/* Special ids have top 2 nibbles all set */
|
||||||
return (id & TASK_CID_MASK) == TASK_CID_MASK;
|
return (id & TASK_CID_MASK) == TASK_CID_MASK;
|
||||||
|
|||||||
@@ -471,12 +471,12 @@ int ipc_send_extended(l4id_t recv_tid, unsigned int flags)
|
|||||||
|
|
||||||
|
|
||||||
static inline int __sys_ipc(l4id_t to, l4id_t from,
|
static inline int __sys_ipc(l4id_t to, l4id_t from,
|
||||||
unsigned int ipc_type, unsigned int flags)
|
unsigned int ipc_dir, unsigned int flags)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (ipc_flags_get_type(flags) == IPC_FLAGS_EXTENDED) {
|
if (ipc_flags_get_type(flags) == IPC_FLAGS_EXTENDED) {
|
||||||
switch (ipc_type) {
|
switch (ipc_dir) {
|
||||||
case IPC_SEND:
|
case IPC_SEND:
|
||||||
ret = ipc_send_extended(to, flags);
|
ret = ipc_send_extended(to, flags);
|
||||||
break;
|
break;
|
||||||
@@ -492,7 +492,7 @@ static inline int __sys_ipc(l4id_t to, l4id_t from,
|
|||||||
ret = -ENOSYS;
|
ret = -ENOSYS;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (ipc_type) {
|
switch (ipc_dir) {
|
||||||
case IPC_SEND:
|
case IPC_SEND:
|
||||||
ret = ipc_send(to, flags);
|
ret = ipc_send(to, flags);
|
||||||
break;
|
break;
|
||||||
@@ -535,18 +535,18 @@ void printk_sysregs(syscall_context_t *regs)
|
|||||||
*/
|
*/
|
||||||
int sys_ipc(l4id_t to, l4id_t from, unsigned int flags)
|
int sys_ipc(l4id_t to, l4id_t from, unsigned int flags)
|
||||||
{
|
{
|
||||||
unsigned int ipc_type = 0;
|
unsigned int ipc_dir = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct ktcb *t = current; if (!t);
|
struct ktcb *t = current; if (!t);
|
||||||
|
|
||||||
/* Check arguments */
|
/* Check arguments */
|
||||||
if (task_id_special(from) &&
|
if (tid_special_value(from) &&
|
||||||
from != L4_ANYTHREAD && from != L4_NILTHREAD) {
|
from != L4_ANYTHREAD && from != L4_NILTHREAD) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (task_id_special(to) &&
|
if (tid_special_value(to) &&
|
||||||
to != L4_ANYTHREAD && to != L4_NILTHREAD) {
|
to != L4_ANYTHREAD && to != L4_NILTHREAD) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto error;
|
goto error;
|
||||||
@@ -559,24 +559,24 @@ int sys_ipc(l4id_t to, l4id_t from, unsigned int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* [0] for Send */
|
/* [0] for Send */
|
||||||
ipc_type |= (to != L4_NILTHREAD);
|
ipc_dir |= (to != L4_NILTHREAD);
|
||||||
|
|
||||||
/* [1] for Receive, [1:0] for both */
|
/* [1] for Receive, [1:0] for both */
|
||||||
ipc_type |= ((from != L4_NILTHREAD) << 1);
|
ipc_dir |= ((from != L4_NILTHREAD) << 1);
|
||||||
|
|
||||||
if (ipc_type == IPC_INVALID) {
|
if (ipc_dir == IPC_INVALID) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Everything in place, now check capability */
|
/* Everything in place, now check capability */
|
||||||
if ((ret = cap_ipc_check(to, from, flags, ipc_type)) < 0)
|
if ((ret = cap_ipc_check(to, from, flags, ipc_dir)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* Encode ipc type in task flags */
|
/* Encode ipc type in task flags */
|
||||||
tcb_set_ipc_flags(current, flags);
|
tcb_set_ipc_flags(current, flags);
|
||||||
|
|
||||||
if ((ret = __sys_ipc(to, from, ipc_type, flags)) < 0)
|
if ((ret = __sys_ipc(to, from, ipc_dir, flags)) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@@ -587,7 +587,7 @@ error:
|
|||||||
*/
|
*/
|
||||||
//printk("Erroneous ipc by: %d. from: %d, to: %d, Err: %d\n",
|
//printk("Erroneous ipc by: %d. from: %d, to: %d, Err: %d\n",
|
||||||
// current->tid, from, to, ret);
|
// current->tid, from, to, ret);
|
||||||
ipc_type = IPC_INVALID;
|
ipc_dir = IPC_INVALID;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user