rebuild kernel add syscall

Gilboa Davara gilboad at gmail.com
Sun Mar 13 07:08:02 UTC 2011


On Thu, 2011-03-10 at 15:17 +0800, xinyou yan wrote:
> I want to and a new syscall
> 1  add
> .long sys_mysyscall
> in        arch/x86/kernel/syscall_table_32.S
> 
> 2    add
>        #define   __NR_mysyscall   341
> in    arch/x86/include/asm/unistd_32.
> 
> 3.    add
> 
> asmlinkage int sys_mysyscall(char* sourceFile,char* destFile)
> {
>     int source=sys_open(sourceFile,O_RDONLY,0);
>     int dest=sys_open(destFile,O_WRONLY|O_CREAT|O_TRUNC,0600);
>     char buf[1024];
>     mm_segment_t fs;
>     fs = get_fs();
>     set_fs(get_ds());
>     int nread;
> 
>     if(source>0 && dest>0)
>     {
>             while((nread=sys_read(source,buf,1024)) > 0)
>                        sys_write(dest,buf,read);
>     }
>     else
>     {
>              printk("Error!");
>     }
>     sys_close(source);
>     sys_close(dest);
>     set_fs(fs);
>     return 0;
> }
> in  kerrnel/sys.c
> 
> 4. make menuconfig
> 5. make  all
> 6  make  modules_install
> 
> reboot
> 
> 
> Now I want just do it one time
> How can i make sure the  new syscall here is mysyscall  work fine  ?

Are you locked on using syscalls?
Unless you really require syscalls, I'd imagine that it's far easier to
use ioctl's instead (doesn't require a custom kernel), and use
filp_open / filp_close / file->read / file->write to access files from
within kernel space.

Two more things:
1. I'd avoid using stack based allocations in kernel mode. (Down to 8KB
in certain situations)
2. Always check error codes.

- Gilboa



More information about the users mailing list