Page 1 of 1

Question about micro-kernel's message sending and receiving

Posted: Sat Apr 16, 2011 7:46 pm
by gfreezy

Code: Select all

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?

Code: Select all

 MESSAGE *mla = (MESSAGE *)va2la(caller, p_msg);
 mla->source = caller;

Re: Question about micro-kernel's message sending and receiv

Posted: Sun Apr 17, 2011 1:23 am
by Combuster
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?

Re: Question about micro-kernel's message sending and receiv

Posted: Sun Apr 17, 2011 5:28 am
by Brendan
Hi,
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?
Looks like the code is taken from an OS and/or book called "Orange'S" (or translated by Google into English). The code posted here looks like a slightly different version of this file.


Cheers,

Brendan

Re: Question about micro-kernel's message sending and receiv

Posted: Sun Apr 17, 2011 7:18 am
by gfreezy
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.

Re: Question about micro-kernel's message sending and receiv

Posted: Sun Apr 17, 2011 7:26 am
by gfreezy
Brendan wrote:The code posted here looks like a slightly different version of this file.
Thanks for the reply.And the code is from "Orange's".I am studying it.
But he code i pasted here is exactly the same as the version of this file.