Question about micro-kernel's message sending and receiving

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.
Post Reply
User avatar
gfreezy
Posts: 3
Joined: Sat Apr 16, 2011 7:41 pm
Location: China

Question about micro-kernel's message sending and receiving

Post 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;
the pursuit of excellence, success will inadvertently catch up with you.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post 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?
"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 ]
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

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

Post 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
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.
User avatar
gfreezy
Posts: 3
Joined: Sat Apr 16, 2011 7:41 pm
Location: China

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

Post 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.
the pursuit of excellence, success will inadvertently catch up with you.
User avatar
gfreezy
Posts: 3
Joined: Sat Apr 16, 2011 7:41 pm
Location: China

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

Post 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.
the pursuit of excellence, success will inadvertently catch up with you.
Post Reply