Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
PUBLIC int sys_sendrec(int function, int src_dest, MESSAGE *p_msg, PROCESS *p_proc)
{
assert(k_reenter == 0);
assert((src_dest >= 0 && src_dest < NR_TASKS + NR_PROCS) ||
src_dest == ANY ||
src_dest == INTERRUPT);
int ret = 0;
int caller = proc2pid(p_proc);
MESSAGE *mla = (MESSAGE *)va2la(caller, p_msg);
mla->source = caller;
assert(mla->source != src_dest);
/* Actually we have the third message type: BOTH. However, it is not
* allowed to be passed to the kernel directly. Kernel doesn't know
* it at all. It is transformed into a SEDN followed by a RECEIVE
* by 'send_recv()'.
*/
if(function == SEND)
{
/* ret = msg_send(p_proc, src_dest, p_msg); */
if(ret != 0)
{
return ret;
}
}
else if(function == RECEIVE)
{
/* ret = msg_receive(p_proc, src_dest, p_msg); */
if(ret != 0)
{
return ret;
}
}
else
{
panic("{sys_sendrec} invalid function: "
"%d (SEND: %d, RECEIVE: %d).",
function, SEND, RECEIVE);
}
return 0;
}
why transform the address of msg to linear address?
The instruction says virtual (segmentation+paging) to linear (paging only), which probably means the OS uses segmentation with non-zero bases in userspace and the kernel needs to translate the user-relative address to a kernel-relative address.
This is possibly about Small Address Spaces support, and therefore I want to make a guess you're showing us L4 code without telling it what it is - At any rate, it is not your OS. Since this forum is about developing your own OS, I suspect there is a underlying question or goal you have not told us about, no?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Combuster wrote:This is possibly about Small Address Spaces support, and therefore I want to make a guess you're showing us L4 code without telling it what it is - At any rate, it is not your OS. Since this forum is about developing your own OS, I suspect there is a underlying question or goal you have not told us about, no?
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Combuster wrote:Since this forum is about developing your own OS, I suspect there is a underlying question or goal you have not told us about, no?
Yes, the code is from a book called "Orange's" as Brendan said.
I wonder why it is necessary to access p_msg's member "source" by translating to its linear address.
Is it possible to access source just like p_msg->source = caller;
thx.
the pursuit of excellence, success will inadvertently catch up with you.