LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-19-2005, 04:42 AM   #1
yakul
LQ Newbie
 
Registered: Nov 2005
Posts: 1

Rep: Reputation: 0
Adding system calls to the kernel


Hello

I have linux red hat8 installed.
I want to add a system call to the kernel and recompile the kernel.
What I did is I added My.c inside linux-2.4.18-14custom/kernel
The code for My.c is:

Code:
#include <linux/kernel.h>
#include <linux/sched.h>
#include <errno.h>
//#include <current.h>

int sys_getpath (int pid, int * array, int size)
{
 task_struct * pTask;

 printk ("This is get path V0P02\n");
 //  pTask = current;
 printk ("%d", pTask->pid);
 while (pTask->pid!=1)
   {
     pTask = pTask->p_pptr; 
     printk ("%d", pTask->pid);
   }

 return 0;
}

The problem I have as when I add #include <linux/sched.h> I get all sort of errors on sched.h when compiling with gcc -c My.c or gcc My.c -c

I also tried to compile user.c in the kernel, because it also has an include to sched.h, and I got about the same errors on sched.h

So how am I suppose to create My.o from My.c?
Is there something I am missing?

Thanks in advance.
 
Old 11-19-2005, 09:38 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
You really need to modify the Makefile to add your source file and let it compile the kernel. Remember, the object code generated from your source file must be linked with the rest of the kernel code to make a working image. In addition, the Makefiles also set up various environment things (defining macros, optimization levels, etc.) to make sure that kernel code is generated directly. So you really should add your new source file to the appropriate Makefile in the kernel source tree.

Also, your syscall will not be accessible if you modify the entry.S file for your architecture and add it to the system call table. Otherwise the syscall interrupt handler will have no idea about what it is.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Some system calls Spooky Programming 1 11-24-2004 10:17 AM
counting system calls eltn Programming 2 10-15-2004 02:32 PM
system calls in Java AMMullan Programming 2 04-14-2004 01:48 AM
java and system calls aizkorri Programming 6 06-20-2003 01:54 AM
Adding new System Call to Kernel kurt_ram Linux - General 1 10-22-2002 03:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration