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 ?
I mean weather i can use sys_open in /kernel/sys.c Or how can i test it but i am in user space ?
2011/3/10 xinyou yan yxy.716@gmail.com:
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.
- 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
- make menuconfig
- 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 ?
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.
- 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
- make menuconfig
- 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
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@gmail.com:
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.
- 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
- make menuconfig
- 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:
- 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@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
On Sun, 2011-03-13 at 21:51 +0800, xinyou yan wrote:
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.
As a general rule, using static parameters in kernel space is considered hazardous; nevertheless, a 128 bytes is relatively safe.
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 ?
I'm not sure what you mean. But in general, yes, you could register a character device that has read/write/seek operations on a memory buffer. (Preferably, dynamically allocated memory buffer) A relatively simple (and easy to understand / implement) example is the /proc file system. (Search for create_proc_entry in the kernel code)
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@gmail.com:
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.
- 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
- make menuconfig
- 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:
- 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@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
2011/3/14 Gilboa Davara gilboad@gmail.com:
On Sun, 2011-03-13 at 21:51 +0800, xinyou yan wrote:
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.
As a general rule, using static parameters in kernel space is considered hazardous; nevertheless, a 128 bytes is relatively safe.
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 ?
I'm not sure what you mean.
May be it can't be implement. I mean . I create a file with a big size . Then i write a super block struct ( I define it like the linux) Then Inode table. Then Date Blocks.
I reimplement some syscall on it . I just want to make it like a filesystem . However I stop at . How to init all of this struct.
So sorry to make you confuse . English is not my native language , I will try to do better than what early i was .
But in general, yes, you could register a character device that has read/write/seek operations on a memory buffer. (Preferably, dynamically allocated memory buffer) A relatively simple (and easy to understand / implement) example is the /proc file system. (Search for create_proc_entry in the kernel code)
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@gmail.com:
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.
- 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
- make menuconfig
- 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:
- 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@lists.fedoraproject.org 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@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
On Mon, 2011-03-14 at 21:24 +0800, xinyou yan wrote:
May be it can't be implement. I mean . I create a file with a big size . Then i write a super block struct ( I define it like the linux) Then Inode table. Then Date Blocks.
I reimplement some syscall on it . I just want to make it like a filesystem . However I stop at . How to init all of this struct.
So sorry to make you confuse . English is not my native language , I will try to do better than what early i was .
First, don't worry about your English - you're not alone. (My English usually takes a dive when I wake up) Second, if I understand you correctly, you plan to: 1. Implement your own syscall. 2. Call the syscall from a user process. 3. Open a file (from within kernel mode). 4. Write data. 5. Close the file. 6. Exit from the syscall.
... And you have to use syscall because it's the assignment. (Making it impossible to use far less intrusive methods such as procfs, character-device, ioctl, etc)
Am I correct?
- Gilboa
If I want to sleep until a event happened ? How can i do it in user mode.
2011/3/15 Joe Zeff joe@zeff.us:
On 03/14/2011 03:21 AM, Gilboa Davara wrote:
As a general rule, using static parameters in kernel space is considered hazardous; nevertheless, a 128 bytes is relatively safe.
Just make sure that you never write more than 128 bytes (including termination) into it. -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
xinyou yan <yxy.716 <at> gmail.com> writes:
If I want to sleep until a event happened ? How can i do it in user mode. ...
Well, it depends what event and under what circumstances.
The are single-threading and multi-threading programs.
An event can be triggered by a counter, timer, signal, inotify, mutex lock/ unlock, barrier, polling, etc.
Some of these logical constructs are generic, others are composites of existing ones.
Often you put these logical constructs in a loop, perhaps with your own added timing or break-out logic.
$ apropos timer $ apropos signal $ apropos pthread $ propos notify $ apropos event $ apropos sleep $ apropos poll
JB