b8b1 Add system call - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Development > FreeBSD Development

FreeBSD Development Kernel development, writing drivers, coding, and questions regarding FreeBSD internals.

Reply
 
Thread Tools Display Modes
  #1  
Old December 24th, 2010, 07:39
mansoda mansoda is offline
Junior Member
 
Join Date: Dec 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Add system call

Hi,
I am a student studying FreeBSD Kernel. I want to ask how to add a system call to FreeBSD. Is there any detailed tutorial to follow?
Thanks indeed!

Juson

Last edited by DutchDaemon; December 24th, 2010 at 17:32.
Reply With Quote
  #2  
Old December 24th, 2010, 17:32
DutchDaemon's Avatar
DutchDaemon DutchDaemon is offline
Administrator
 
Join Date: Nov 2008
Location: Rotterdam, the Netherlands
Posts: 9,819
Thanks: 30
Thanked 1,883 Times in 1,329 Posts
Default

Start here: http://www.freebsd.org/doc/en_US.ISO...opers-handbook
__________________
FreeBSD Forums: Information for New Members | FreeBSD Forums Rules
FreeBSD Resources: The FreeBSD Handbook | Manuals | FAQ | Wiki
Before you post: How to ask questions the smart way
If you must know .. So, what does an Adminstrator/Moderator do?
---> Do not PM me with FreeBSD questions. I do not work here. <---
Reply With Quote
  #3  
Old December 24th, 2010, 19:50
Zare Zare is offline
Member
 
Join Date: Nov 2008
Location: Split, Dalmatia
Posts: 360
Thanks: 26
Thanked 50 Times in 41 Posts
Default

The easiest (and AFAIK, preferred) way is to code a loadable kernel module which contains syscall code.
Search the google and find examples of skeletal, "hello world" style kernel module code, and Makefile example you'll use to compile it, kld skeleton is about 15 lines of code and Makefile is like two-three. Simple to begin with.



After you have a skeleton, make a variable definition that will hold your syscall number (don't use one that's already occupied, check /usr/src/sys/kern/syscalls.master), for instance

Code:
static int my_syscall_slot = 210;
Then define function that'll hold syscall's usable code

Code:
static int syscall_code(int something, char something_else, void *syscall_args)
{
   ...
}
syscall_args is mandatory, the first two are your optional arguments. Since this example uses two arguments for syscall, you need to define sysent for your syscall with 2.

Code:
static struct sysent my_syscall_sysent = { 2, syscall_code };
Then use SYSCALL_MODULE macro that'll declare the whole thing :

Code:
SYSCALL_MODULE(my_syscall, &my_syscall_slot, &my_syscall_sysent, put_the_name_of_the_module_entry_function_here, NULL);
So the args are : name (provisional), pointer to slot number, pointer to sysent, name of the kld entry function, optional callback argument for event handler.

Hope it helps, this is not tested and from the head. Last time i did a grounds up KLD was in days of FreeBSD 5.4, i might have missed something.
Reply With Quote
  #4  
Old December 29th, 2010, 03:22
vdvluc vdvluc is offline
Junior Member
 
Join Date: May 2009
Location: Netherlands
Posts: 20
Thanks: 1
Thanked 3 Times in 2 Posts
Default

You may want to look in /usr/share/examples/kld/syscall/ for example code.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
curiosity question, source port add or package add? pgmrdlm Installation and Maintenance of FreeBSD Ports or Packages 2 May 29th, 2010 16:45
dhclient and/or system can't add unroutable gateway daikichi Networking 1 May 4th, 2010 07:42
[Solved] system call explanation in the book jronald FreeBSD Development 2 March 21st, 2010 03:53
[Solved] how make a system call module? MIDOSE Userland Programming & Scripting 1 March 12th, 2010 10:06
SDL_Init() "Bad system call (core dumped)" Eponasoft Userland Programming & Scripting 0 August 8th, 2009 12:04


All times are GMT +1. The time now is 13:21.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0