Results 1 to 10 of 10
hi..all i'm new to the kernel hacking ......
i'm trying to run the a system call as:
In /usr/src/linux-2.6.26.6/include/linux/wait.h, I added
struct evnt_queue
{
struct evnt_queue *next_event;
wait_queue_head_t waitq;
int ...
- 07-06-2009 #1Just Joined!
- Join Date
- Jul 2009
- Posts
- 6
problem in adding new system call
hi..all i'm new to the kernel hacking ......
i'm trying to run the a system call as:
In /usr/src/linux-2.6.26.6/include/linux/wait.h, I added
struct evnt_queue
{
struct evnt_queue *next_event;
wait_queue_head_t waitq;
int eid;
};
In /usr/src/linux-2.6.26.6/arch/x86/kernel/syscall_table_32.S I added
.long sys_evntopen
.long sys_evntclose /* 328 */
.long sys_evntwait
.long sys_evntsig
In /usr/src/linux-2.6.26.6/include/asm-x86/unistd_32.h I added
#define __NR_evntopen 327
#define __NR_evntclose 328
#define __NR_evntwait 329
#define __NR_evntsig 330
In /usr/src/linux-2.6.26.6/init/main.c I added
struct evnt_queue *eq;
static void __init event_init(void)
{
eq=(struct evnt_queue *)kmalloc(
sizeof(struct evnt_queue), GFP_KERNEL);
eq->next_event=NULL;
eq->eid=0;
init_waitqueue_head(&(eq->waitq));
}
asmlinkage void __init start_kernel(void)
{
......
event_init(); /* last statement */
}
In /usr/src/linux-2.6.26.6/sush/sys.c : I add the code of the new system call
asmlinkage int sys_evntopen(int eid)
{
int newid=-1;
struct evnt_queue *temp;
printk("sys_evntopen");
if (eq==NULL)
{
eq=(struct evnt_queue *)kmalloc(
sizeof(struct evnt_queue), GFP_KERNEL);
eq->next_event=NULL;
eq->eid=0;
init_waitqueue_head(&(eq->waitq));
}
temp=eq->next_event;
if (eid>0)
{
while ((temp!=NULL)&&(temp->eid!=eid))
{
temp=temp->next_event;
}
if ((temp!=NULL)&&(temp->eid==eid)) newid=eid;
}
else if (eid==0)
{
while (temp!=NULL)
{
if (newid<temp->eid) newid=temp->eid;
temp=temp->next_event;
}
newid++;
if (newid<1) newid=1;
temp=(struct evnt_queue *)kmalloc(
sizeof(struct evnt_queue), GFP_KERNEL);
if (temp==NULL) newid=-1;
else
{
temp->eid=newid;
temp->next_event=eq->next_event;
eq->next_event=temp;
init_waitqueue_head(&(temp->waitq));
}
}
return(newid);
}
asmlinkage int sys_evntclose(int eid)
{
int result=-1;
struct evnt_queue *prev, *temp;
printk("sys_evntclose");
prev=eq;
temp=prev->next_event;
while ((temp!=NULL)&&(temp->eid!=eid))
{
prev=temp;
temp=prev->next_event;
}
if ((temp!=NULL)&&(waitqueue_active(&(temp->waitq))))
wake_up_interruptible(&(temp->waitq));
if (temp!=NULL)
{
result=0;
prev->next_event=temp->next_event;
kfree(temp);
}
return(result);
}
asmlinkage int sys_evntwait(int eid)
{
int result=-1;
struct evnt_queue *temp;
printk("sys_evntwait");
temp=eq->next_event;
while ((temp!=NULL)&&(temp->eid!=eid))
{
temp=temp->next_event;
}
if (temp!=NULL)
{
result=0;
interruptible_sleep_on(&(temp->waitq));
}
return(result);
}
asmlinkage int sys_evntsig(int eid)
{
int result=-1;
struct evnt_queue *temp;
printk("sys_evntsig");
temp=eq->next_event;
while ((temp!=NULL)&&(temp->eid!=eid))
{
temp=temp->next_event;
}
if (temp!=NULL)
{
result=0;
wake_up_interruptible(&(temp->waitq));
}
return(result);
}
And this is the test programm which use the system call :
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <linux/unistd.h>
#include <linux/wait.h>
#include <linux/errno.h>
_syscall1(int, evntopen, int, eid);
_syscall1(int, evntclose, int, eid);
_syscall1(int, evntwait, int, eid);
_syscall1(int, evntsig, int, eid);
void *task_wait(void *eid) /* eventwait */
{
printf("event %d waiting\n", eid);
evntwait((int)eid);
printf("event %d waked up\n", eid);
}
void *task_signal(void *eid) /* eventsig */
{
printf("event %d signaling\n", eid);
evntsig((int)eid);
}
int main(int arg, char ** argv)
{
int i, k, n;
int eids[10];
pthread_t tasks[10];
n=3; /* open 3 threads */
for (i=0; i<n; i++)
{
eids[i]=evntopen(0); /* open events */
if (eids[i]>0) printf("event %d opened\n", eids[i]);
else printf("event #%d could not open\n", i);
}
for (i=0; i<n; i++)
{
/* creat threads */
pthread_create(&tasks[i], NULL, task_wait, (void *)eids[i]);
sleep(2);
}
for (i=n-1; i>=0; i--)
{
pthread_create(&tasks[i], NULL, task_signal, (void *)eids[i]);
sleep(2);
}
for (i=0; i<n; i++)
{
k=evntclose(eids[i]); /* test eventclose */
if (k==0) printf("event %d closed\n", eids[i]);
else printf("event %d could not close\n", eids[i]);
}
for (i=0; i<n; i++)
{
pthread_join(tasks[i], NULL);
}
return(0);
}
everything goes fine but while running the user program test.c,
i'm getting the following output:
event #0 could not open
event #1 could not open
event #2 could not open
event -1 waiting
event -1 waked up
event -1 waiting
event -1 waked up
event -1 waiting
event -1 waked up
event -1 signaling
event -1 signaling
event -1 signaling
event -1 could not close
event -1 could not close
event -1 could not close
this is happening so because calling the first system call in my case is returning -1 value.
in fact if i'm running any system call then every system call is returning -1 value
what should i do???? where is the problem??????? i'm also looking at strace file but not getting any solution.
thank you in advance.
any help will be appreciable.
- 07-06-2009 #2Just Joined!
- Join Date
- Jul 2009
- Posts
- 6
plzzzz sumone help...........
- 07-07-2009 #3
I'm not sure whether you will receive exact answer from here. Drop mail here
MailingList - Linux Kernel Newbies
Try and post your strace output ,I think should provide some hints
So obviously it's an error.To make sure write a simple c program with a system call and see whether that also producing errorsn fact if i'm running any system call then every system call is returning -1 value
Does this gives error?Code:main(){ char a='X'; write(1,&a,1); }- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 07-08-2009 #4Just Joined!
- Join Date
- Jul 2009
- Posts
- 6
thank u sir..
i've attached the strace output.
i've tried with the same program as u suggested me it gives no error...everything is ok in this case...
-1 is an error...but why this is happening??? infact this is the case with every new system call which i'm implementing..
thank you ...
- 07-08-2009 #5
Your strace says
Error code details areSYS_328(0xffffffff, 0xbf8af9b8, 0x804865f, 0xffffffff, 0) = -1 ENOSYS (Function not implemented)
write(1, "event -1 could not close\n", 25event -1 could not close
Are you following proper guide for adding a new system call? You might have missed something ,somewhere...ENOSYS:
Function not implemented. This indicates that the function called is not implemented at all, either in the C library itself or in the operating system. When you get this error, you can be sure that this particular function will always fail with ENOSYS unless you install a new version of the C library or the operating system.- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 07-08-2009 #6Just Joined!
- Join Date
- Jul 2009
- Posts
- 6
thank you sir thank you so much......
sir i've installed & build a new kernel. and i think i'm following every steps involved correctly.sir still problem is dere it means sumthing wrong i'm doing.
sir could you plz give me any way any suggetion so dat i can get out of this.
- 07-08-2009 #7
what's the guide ,you are following? any book ?
Best method would be try a simple "hello world" system call.If everything if fine,then you can go ahead with your program. If "hello world" didn't work,then there is something wrong with your custom kernel (may be missed some modules)
I found this link :
Adding a Custom System Call to Ubuntu - Tech Today- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 07-08-2009 #8Just Joined!
- Join Date
- Jul 2009
- Posts
- 6
no sir not any perticuler guide or book i'm following. i just do googling for dis dere i found so many tutes and link den for perticular architecture and kernel version i followd one of them.
i go through the link u provided same thing i'm doing.....u r right it seems dere is sum problem with my custom kernel i'm going to install & compile another kernel....may be dat would help me out...
thank you so much for your time sir.
- 07-08-2009 #9
I just google out the above link So not sure about results.
But here is another one,
Kernel command using Linux system calls
I would suggest you to download the same kernel version as mentioned in the documents.- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 07-08-2009 #10Just Joined!
- Join Date
- Jul 2009
- Posts
- 6
k sir thank you now i'm going tom try again with the same....
thank you


Reply With Quote
