I'm trying to write my own system calls. I have a .c file where I'm putting the system calls. My system calls use a struct, so I have declared a global variable that is an array of my struct. Lets just call it

//Stuff is the name of the struct I declared.
Stuff myStuff[100];

I have a function inside of my .c file called "init_Stuff". In order for the stuct to behave properly when a system call it made, init_Stuff must be called one time before any of the system calls will work. From within one of my system calls, I could just say "if the structs aren't initialized yet, go initialize them". But I'm wondering if there is a more elegant/normal way to just call init_Stuff right away. I also have a Makefile that currently just creates an object file of my .c file.

I also have one more question. My professor has said that we should not use kmalloc because he says that he has not yet taught us enough information in order for us to understand all the issues behind its proper use. So doesn't that only leave me with one other option -- setting aside all of the memory that the system calls could possibly need ahead of time? (Btw, that seems possible to me, since he gave us a limit on the total length of the messages we're passing around. But I'm concerned that perhaps the amount of memory I want will be too much - its in the MB, but what happens if the kernel decides it is too much contiguous memory, and is that a realistic worry?)

Thanks for any insight or links you guys can give.

I'm trying to write my own system calls. I have a .c file where I'm putting the system calls. My system calls use a struct, so I have declared a global variable that is an array of my struct. Lets just call it

//Stuff is the name of the struct I declared.
Stuff myStuff[100];

I have a function inside of my .c file called "init_Stuff". In order for the stuct to behave properly when a system call it made, init_Stuff must be called one time before any of the system calls will work. From within one of my system calls, I could just say "if the structs aren't initialized yet, go initialize them". But I'm wondering if there is a more elegant/normal way to just call init_Stuff right away. I also have a Makefile that currently just creates an object file of my .c file.

Declare (and define) it with the __init qualifier:

#include <linux/init.h>
void __init init_Stuff();

and call it from linux/init/main.c:start_kernel()

Comments
Thanks again

Thanks a lot for your suggestion. I'll try it out and get back to you, and also ask my TA if I'm actually allowed to do that (we have to submit a patch file). But that makes more sense to me than it does to intertwine that function call with my other function calls.

This question has already been answered. Start a new discussion instead.