Page 1 of 1

Custom syscalls and how to install them.

Posted: Sun Feb 03, 2008 7:55 pm
by piranha
I am at the point of allowing modules to create their own syscalls.
I have a syscall table (syscalls[MAXSYSCALL]). How would a module add a syscall to it?

I could have a 'total_syscalls' value and the module adds the syscall and then increments that value.

Or, I could have syscalls[WHATEVER_VALUE] call whatever is stored in another array, called custom_syscalls[]. Then you call syscalls[WHATEVER_VALUE] which calls custom_syscalls[registers->ebx] or something.

Thoughts? Other ideas?
-JL

Posted: Sun Feb 03, 2008 8:24 pm
by bloodhound23
I thought about something like this once. I thought about assigning each call a value and having a pointer to that function entered into a syscall table when the modules are loaded. All that is needed is the documentation for the driver and you can write assembly programs that utilize them. It's of course a bit more complicated than this, and there is the problem of having more than one driver trying to create a syscall with the same index into the table.

you could have something like this in asm.

Code: Select all

mov ax,[index];the index into the table
;load parameters and such here
int 0x80;or whatever value you choose.

Posted: Sun Feb 03, 2008 8:31 pm
by piranha
Thats what I have working, I just want to figure out how to have modules create custom syscalls.

-JL

Posted: Sun Feb 03, 2008 8:44 pm
by bloodhound23
Well if you don't have your OS link the modules with the kernel, you could just have all your modules run once in userspace with a main procedure that calls the system call to create a system call for all of the necessary driver functions.

Posted: Mon Feb 04, 2008 5:45 pm
by AndrewAPrice
I'm not sure what sort of driver/server system you are using, but basically store a list of (however big you want) of ints. Each int is the process ID of the server/driver to call when the syscall is fired.

When a syscall is fired, the kernel sends a SYSCALL event to the module (just like the kernel would call READ, WRITE, KILL, etc to the module). Attached to the message would include what syscall was called and the PID of the calling processes. You could possibly point to a struct which includes things like:
- Time of the syscall
- A bool that indicates if to wake the receiving program when the syscall has completed (if a program put itself to sleep after making the syscall (you'lld need sort of atomic syscall-and-sleep operation) for blocking operations). This could also be implemented as a address to a callback function.