Re: rebuild kernel add syscall

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It is a homework .  Use a kernel spcae as a char decieve
Which can offer  open write and so on.

I just  use a   char buffer[128] in kernel space.

Then i have some ideas.
I can use kernel space as char device. I can also use  kernel spcae as
a file system?  Could it be ?
If  memory  can be a filesystem  . Can  i use a file  to   simulate  。
It just  not be taken as a file . Like something
we store file  in it.





2011/3/13 Gilboa Davara <gilboad@xxxxxxxxx>:
> 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
>
> --
> users mailing list
> users@xxxxxxxxxxxxxxxxxxxxxxx
> To unsubscribe or change subscription options:
> https://admin.fedoraproject.org/mailman/listinfo/users
> Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
>
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux