Subject: [Help] making my system calls
To: None <tech-kern@netbsd.org>
From: Ilhwan Kwon <ik26+@andrew.cmu.edu>
List: tech-kern
Date: 02/05/1999 11:17:51
Hi.

I am trying to write my own system call functions for BSD.
I am trying to calculate the maximum amount of memory a PC needs
when it is used as a router.
First, I declare "u_long max_memused" in /usr/src/sys/sys/mbuf.h.

Second, I add following code in m_devget function in
/usr/src/sys/kern/uipc_mbuf.c.

	u_long mem_used = size of memory currently used by mbufs and clusters.
	if(mem_used > max_memused) max_memused = mem_used;

Third, I make prototype for my system calls in mbuf.h like following.
	
	long get_mem_stat __P((void));
	void clear_mem_stat __P((void));

Fourth, I declare above system calls in uipc_mbuf.c like following.

	long get_mem_stat(){
		return (long) max_memused;
	}
	void clear_mem_stat(){
		max_memused = 0;
	}

Fifth, I put entries in init_sysent.c like following.

	struct sysent sysent[] = {
		/*......*/
		{0, (*sy_call)get_mem_stat},	/*241 = get_mem_stat */
		{0, (*sy_call)clear_mem_stat},  /*242 = clear_mem_stat */
		/* ..... */
	};
	
	the 241th and 242th wer originally looked like {0, (*sy_call)no_sys},

finally, I put entries in syscalls.c

	"get_mem_stat"		/*241 = get_mem_stat*/
	"clear_mem_stat" 	/*242 = clear_mem_stat*/
	
	they were originally "no_sys".

Now, I recompile the kernel and reboot.  but kernel library is not updated.
I copy /usr/src/sys/sys/mbuf.h to /usr/include/sys/mbuf.h.
I write a small program which includes <sys/mbuf.h> and calls get_mem_stat
and clear_mem_stat system calls.

Whe I compile, I get
"get_mem_stat" : undefined reference from the text segent"
"clear_mem_stat" : undefined reference from the text segent"

What did I do wrong?
Any help on this matter will be greatly appreciated.

Thanks
-James Kwon