Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > The Linux Kernel > About self-defined syscall

Forgot Password?
 The Linux Kernel   Compiling, theory, programming or other discussion about the linux kernel

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 10-02-2009   #1 (permalink)
Just Joined!
 
Join Date: Oct 2009
Posts: 1
About self-defined syscall

I just try to define a new syscall set_limit(), which is used for set a limitation for syscall read() or write(). This syscall should retain two value max_read_bytes and max_write_bytes in each process. I try to add these two new fields in task_struct. But how can I initialize these two values and make them available in each process, so that read/write can get these values?
glassesmouse is offline  


Reply With Quote
Old 10-08-2009   #2 (permalink)
Just Joined!
 
probe's Avatar
 
Join Date: Oct 2009
Location: Belgrade, Serbia
Posts: 21
Ok, this is instruction how to add new system call in kernel 2.6 from web address

http://courses.cs.vt.edu/~cs3204/spr...inux_rev00.pdf

------------------------------------------------------------------
1. Download the latest version of the 2.6 Linux kernel from The Linux Kernel Archives.
2. Unzip and untar the kernel directory into /usr/src/.
3. In /usr/src/Linux-x.x.x/kernel/, Create a new file myservice.c to define your
system call.
#include <Linux/linkage.h> //for linking a system call
#include <Linux/kernel.h> //for the printk
asmlinkage int sys_myservice (int arg1, char* arg2) {
printk(KERN_EMERG “my service is running”);
//kernel messages logged to /var/log/kernel/warnings
return(1);
}
4. In /usr/src/Linux-x.x.x/include/asm/unistd.h, define an index for your system call.
Your index should be the number after the last system call defined in the list.
#define __NR_myservice 274
5. Also, you should increment the system call count.
#define __NR_syscalls 275
6. In /usr/src/Linux-x.x.x/arch/i386/kernel/entry.S, you should define a pointer to
hold a reference to your system call routine. It is important that your data entry
placement corresponds to the index you assigned to your system call.
.long sys_myservice
7. Add your system call to the Makefile in /usr/src/Linux-x.x.x/kernel/Makefile.
Add your object after the other kernel objects have been declared.
obj-y += myservice.o
8. Make your system from /usr/src/Linux- x.x.x
make xconfig //save the defaults
make dep //make dependency list
make bzImage //build your kernel
9. Add a new boot image to Lilo, by editing /etc/lilo.conf. Your lilo configuration
will vary slightly. After saving, run lilo –v to install your settings. Don’t just
modify an existing lilo entry; you may need it if your new kernel has bugs.
image=/usr/src/Linux-x.x.x/arch/i386/boot/bzImage
label=”Linux-test”
root=/dev/hda5
read-only
10. Making a user test file. You also need to copy your edited unistd.h from
/usr/src/Linux- x.x.x/include/asm/ to /usr/include/kernel/ because it contains your
system call’s index.
#include <Linux/errno.h>
#include<sys/syscall.h>
#include <Linux/unistd.h>
long errno; //this is the return code from the system call
//this is a macro defined in unistd.h to help prototype sys calls
_syscall2(int, myservice, int, arg1, char*, arg2);
main() {
myservice(1, "hi");
}
11. Reboot into your new kernel and compile your user test program to try out
your system call. You will know if it worked if you see a kernel message in
/var/log/kernel/warnings announcing that your service is running.
------------------------------------------------------------------

So this is how you create new syscall [I supose it works, didn't try it yet, but will when I get home tonight ]

Did you figure out where syscalls read() or write() hold their values for max_write_bytes and max_read_bytes. Or does these limitations even exist explicitly in kernel or they have some physical limitations ?

If you add two new fields to task_struct, each process will by default have access to them, since you represent each process with task_struct. So now, you have to look how communication goes between process and read() and write() syscalls, and there set these values. And to do this I think you will have to modify task_struct and read() and write() syscalls accordingly. Maybe even more kernel code to change for this to work.

regards

---------------------------------------------------------
"Didn't you know, we are obsolete."

card M.Sc. in Astrophysics; Programmer
contact dragoslav.zaric.kd@gmail.com
web-site www.tech-vibe.com
probe is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 08:09 AM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2