Find the answer to your Linux question:
Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    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?

  2. #2
    Just Joined! probe's Avatar
    Join Date
    Oct 2009
    Location
    Belgrade, Serbia
    Posts
    29
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •