* copy_to_user
@ 2010-12-23 0:59 Hemanth Kumar
2010-12-23 1:18 ` copy_to_user Dexter Haslem
0 siblings, 1 reply; 24+ messages in thread
From: Hemanth Kumar @ 2010-12-23 0:59 UTC (permalink / raw)
To: kernelnewbies
Hi All,
I have small problem with copy_to_user in read function,below is my code,when I try to read from userspace I get segmentation fault,
Can any please point me where I went wrong,
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/proc_fs.h>
#include <linux/fs.h>
#include <linux/kdev_t.h>
#include <linux/jiffies.h>
#include <linux/cdev.h>
#include <asm/uaccess.h>
#include <linux/mutex.h>
struct mutex timer;
static struct cdev my_cdev;
dev_t devn;
int maj = 300;
int min = 0;
int count = 1;
char modname[] = "mytimer";
short x[10] = {1,2,3,4,5,6,7,8,9,10};
ssize_t my_read(struct file *file,char *buf,size_t count,loff_t *pos){
unsigned long res;
void *k = (void *)&x;
void *l = (void *)&x+1;
void *j = (void *)&x+2;
mutex_lock(&timer);
res = copy_to_user(buf,k,sizeof(short));
res = copy_to_user(buf,l,sizeof(short));
res = copy_to_user(buf,j,sizeof(short));
/* res = copy_to_user(buf,&x+4,sizeof(short));
res = copy_to_user(buf,&x+5,sizeof(short));
res = copy_to_user(buf,&x+6,sizeof(short));
res = copy_to_user(buf,&x+7,sizeof(short));
res = copy_to_user(buf,&x+8,sizeof(short));
res = copy_to_user(buf,&x+9,sizeof(short));
*/
mutex_unlock(&timer);
return 20;
}
static struct file_operations my_fops = {
.owner = THIS_MODULE,
.read = my_read,
};
static int __init my_init(void){
int ret;
devn = MKDEV(maj,min);
ret = register_chrdev_region(devn,count,modname);
cdev_init(&my_cdev,&my_fops);
cdev_add(&my_cdev,devn,count);
printk("<1> Register timer maj = %d\n",maj);
return 0;
}
static void __exit my_exit(void){
cdev_del(&my_cdev);
unregister_chrdev_region(devn,count);
printk("<1> Bye Bye \n");
}
module_init(my_init);
module_exit(my_exit);
MODULE_LICENSE("Dual BSD/GPL");
my userspace App:
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
int nbytes ;
char n[20];
short a = *((short *)&n[0]);
short b = *((short *)&n[2]);
short c = *((short *)&n[4]);
int fd = open( "/dev/mytimer", O_RDONLY );
if ( fd < 0 ) { perror( "/dev/mytimer" ); exit(1); }
while ( 1 )
{
nbytes = read( fd, n, 40 );
if ( nbytes < 0 ) break;
printf( "\r a = %d \n ", a);
printf("\r b = %d \n",b);
printf("\r c = %d \n",c);
sleep(1);
fflush( stdout );
}
return 0;
}
Best regards,
^ permalink raw reply [flat|nested] 24+ messages in thread* copy_to_user
2010-12-23 0:59 copy_to_user Hemanth Kumar
@ 2010-12-23 1:18 ` Dexter Haslem
2010-12-23 2:15 ` copy_to_user Hemanth Kumar
2010-12-23 4:35 ` copy_to_user Srinivas G.
0 siblings, 2 replies; 24+ messages in thread
From: Dexter Haslem @ 2010-12-23 1:18 UTC (permalink / raw)
To: kernelnewbies
On 12/22/2010 5:59 PM, Hemanth Kumar wrote:
> Hi All,
>
> I have small problem with copy_to_user in read function,below is my code,when I try to read from userspace I get segmentation fault,
> Can any please point me where I went wrong,
>
>
> #include<linux/kernel.h>
> #include<linux/module.h>
> #include<linux/init.h>
> #include<linux/types.h>
> #include<linux/proc_fs.h>
> #include<linux/fs.h>
> #include<linux/kdev_t.h>
> #include<linux/jiffies.h>
> #include<linux/cdev.h>
> #include<asm/uaccess.h>
> #include<linux/mutex.h>
>
> struct mutex timer;
> static struct cdev my_cdev;
> dev_t devn;
> int maj = 300;
> int min = 0;
> int count = 1;
> char modname[] = "mytimer";
> short x[10] = {1,2,3,4,5,6,7,8,9,10};
>
>
>
>
> ssize_t my_read(struct file *file,char *buf,size_t count,loff_t *pos){
> unsigned long res;
> void *k = (void *)&x;
> void *l = (void *)&x+1;
> void *j = (void *)&x+2;
>
> mutex_lock(&timer);
> res = copy_to_user(buf,k,sizeof(short));
> res = copy_to_user(buf,l,sizeof(short));
> res = copy_to_user(buf,j,sizeof(short));
>
> /* res = copy_to_user(buf,&x+4,sizeof(short));
> res = copy_to_user(buf,&x+5,sizeof(short));
> res = copy_to_user(buf,&x+6,sizeof(short));
> res = copy_to_user(buf,&x+7,sizeof(short));
> res = copy_to_user(buf,&x+8,sizeof(short));
> res = copy_to_user(buf,&x+9,sizeof(short));
> */
> mutex_unlock(&timer);
>
> return 20;
>
> }
>
>
> static struct file_operations my_fops = {
> .owner = THIS_MODULE,
> .read = my_read,
>
> };
>
>
> static int __init my_init(void){
> int ret;
> devn = MKDEV(maj,min);
>
> ret = register_chrdev_region(devn,count,modname);
>
> cdev_init(&my_cdev,&my_fops);
> cdev_add(&my_cdev,devn,count);
>
> printk("<1> Register timer maj = %d\n",maj);
>
>
>
>
> return 0;
> }
>
>
>
> static void __exit my_exit(void){
>
> cdev_del(&my_cdev);
> unregister_chrdev_region(devn,count);
> printk("<1> Bye Bye \n");
>
> }
>
>
> module_init(my_init);
> module_exit(my_exit);
> MODULE_LICENSE("Dual BSD/GPL");
>
>
>
>
> my userspace App:
>
> #include<stdio.h>
> #include<fcntl.h>
> #include<stdlib.h>
> #include<unistd.h>
>
> int main()
> {
> int nbytes ;
> char n[20];
> short a = *((short *)&n[0]);
> short b = *((short *)&n[2]);
> short c = *((short *)&n[4]);
>
> int fd = open( "/dev/mytimer", O_RDONLY );
> if ( fd< 0 ) { perror( "/dev/mytimer" ); exit(1); }
>
> while ( 1 )
> {
>
> nbytes = read( fd, n, 40 );
> if ( nbytes< 0 ) break;
>
> printf( "\r a = %d \n ", a);
> printf("\r b = %d \n",b);
> printf("\r c = %d \n",c);
>
> sleep(1);
> fflush( stdout );
> }
> return 0;
> }
>
>
>
>
> Best regards,
>
>
>
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Hi,
At first glance, you have char n[20], but read 40 bytes in the read
call. char is only 1 byte on x86 I believe so that might be your problem.
--
-Dexter Haslem
^ permalink raw reply [flat|nested] 24+ messages in thread* copy_to_user
2010-12-23 1:18 ` copy_to_user Dexter Haslem
@ 2010-12-23 2:15 ` Hemanth Kumar
2010-12-23 4:35 ` copy_to_user Srinivas G.
1 sibling, 0 replies; 24+ messages in thread
From: Hemanth Kumar @ 2010-12-23 2:15 UTC (permalink / raw)
To: kernelnewbies
--- On Thu, 23/12/10, Dexter Haslem <dexter.haslem@gmail.com> wrote:
> From: Dexter Haslem <dexter.haslem@gmail.com>
> Subject: Re: copy_to_user
> To: "Hemanth Kumar" <hemwire@yahoo.co.in>
> Cc: Kernelnewbies at kernelnewbies.org
> Date: Thursday, 23 December, 2010, 6:48 AM
> On 12/22/2010 5:59 PM, Hemanth Kumar
> wrote:
> > Hi All,
> >
> >? ? ? ? ? ???I
> have small problem with copy_to_user in read function,below
> is my code,when I try to read from userspace I get
> segmentation fault,
> > Can any please point me where I went wrong,
> >
> >
> > #include<linux/kernel.h>
> > #include<linux/module.h>
> > #include<linux/init.h>
> > #include<linux/types.h>
> > #include<linux/proc_fs.h>
> > #include<linux/fs.h>
> > #include<linux/kdev_t.h>
> > #include<linux/jiffies.h>
> > #include<linux/cdev.h>
> > #include<asm/uaccess.h>
> > #include<linux/mutex.h>
> >
> > struct mutex timer;
> > static struct cdev my_cdev;
> > dev_t devn;
> > int maj = 300;
> > int min = 0;
> > int count = 1;
> > char modname[] = "mytimer";
> > short x[10] = {1,2,3,4,5,6,7,8,9,10};
> >
> >
> >
> >
> > ssize_t my_read(struct file *file,char *buf,size_t
> count,loff_t *pos){
> >? ? ???unsigned long res;
> >? ? ???void *k = (void
> *)&x;
> >? ? ? ? ? ? void *l =
> (void *)&x+1;
> >? ? ? ? ? ? void *j =
> (void *)&x+2;
> >
> >? ? ? ? ? ? ? ?
> ? ? ???mutex_lock(&timer);
> >? ? ? ? ? ? ? ?
> ? ? ? ? ? ?
> ???res =? ?
> copy_to_user(buf,k,sizeof(short));
> >? ? ? ? ? ? ? ?
> ? ? ? ? ? ?
> ???res =? ?
> copy_to_user(buf,l,sizeof(short));
> >? ? ? ? ? ? ? ?
> ? ? ? ? ? ?
> ???res =? ?
> copy_to_user(buf,j,sizeof(short));
> >
> >? ? ? ? ? ? ? ?
> ? ? ? ???/*? ? res
> =? copy_to_user(buf,&x+4,sizeof(short));
> >? ? ? ? ? ? ? ?
> ? ? ? ? ? ?
> ???res =? ?
> copy_to_user(buf,&x+5,sizeof(short));
> >? ? ? ? ? ? ? ?
> ? ? ? ? ? ?
> ???res =? ?
> copy_to_user(buf,&x+6,sizeof(short));
> >? ? ? ? ? ? ? ?
> ? ? ? ? ? ?
> ???res =? ?
> copy_to_user(buf,&x+7,sizeof(short));
> >? ? ? ? ? ? ? ?
> ? ? ? ? ? ?
> ???res =? ?
> copy_to_user(buf,&x+8,sizeof(short));
> >? ? ? ? ? ? ? ?
> ? ? ? ? ? ?
> ???res =? ?
> copy_to_user(buf,&x+9,sizeof(short));
> >? ? ? ? ? ? ? ?
> ? ? ? ? ? */
> >? ? ? ? ? ? ? ?
> ???mutex_unlock(&timer);
> >
> >? ???return 20;
> >
> > }
> >
> >
> > static struct file_operations my_fops = {
> >? ? ? ? ? ? ? ?
> ???.owner = THIS_MODULE,
> >? ? ? ? ? ? ? ?
> ???.read = my_read,
> >
> > };
> >
> >
> > static int __init my_init(void){
> >? ? ? ? ? int ret;
> >? ???devn = MKDEV(maj,min);
> >
> >? ? ???ret =
> register_chrdev_region(devn,count,modname);
> >
> >? ? ? ?
> cdev_init(&my_cdev,&my_fops);
> >? ? ? ?
> cdev_add(&my_cdev,devn,count);
> >
> >? ? ? ? printk("<1>?
> Register timer maj = %d\n",maj);
> >
> >
> >
> >
> >???return 0;
> > }
> >
> >
> >
> > static void __exit my_exit(void){
> >
> >? ? ? ? cdev_del(&my_cdev);
> >? ? ?
> ???unregister_chrdev_region(devn,count);
> >? ? ? ? ?
> printk("<1>? Bye Bye \n");
> >
> > }
> >
> >
> > module_init(my_init);
> > module_exit(my_exit);
> > MODULE_LICENSE("Dual BSD/GPL");
> >
> >
> >
> >
> > my userspace App:
> >
> > #include<stdio.h>
> > #include<fcntl.h>
> > #include<stdlib.h>
> > #include<unistd.h>
> >
> > int main()
> > {
> >? ? ? ? ???int
> nbytes ;
> >? ? ? ? ???char
> n[20];
> >? ? ? ? ???short a =
> *((short *)&n[0]);
> >? ? ? ? ???short b =
> *((short *)&n[2]);
> >? ? ? ? ???short c =
> *((short *)&n[4]);
> >
> >? ? ? ? ? int?
> ???fd = open( "/dev/mytimer", O_RDONLY );
> >? ? ? ? ? if ( fd<? 0
> ) { perror( "/dev/mytimer" ); exit(1); }
> >
> > while ( 1 )
> >? ? ? ? ? ? ? ?
> ? {
> >
> >? ? ? ? ? ? ? ?
> ???nbytes = read( fd, n, 40 );
> >? ? ? ? ? ? ? ?
> ? if ( nbytes<? 0 ) break;
> >
> >? ? ? ? ? ? ? ?
> ? printf( "\r a = %d \n ", a);
> >? ? ? ? ? ? ? ?
> ? printf("\r b = %d \n",b);
> >? ? ? ? ? ? ? ?
> ? printf("\r c = %d \n",c);
> >
> >? ? ? ? ? ? ? ?
> ? sleep(1);
> >? ? ? ? ? ? ? ?
> ? fflush( stdout );
> >? ? ? ? ? ? ? ?
> ? }
> > return 0;
> > }
> >
> >
> >
> >
> > Best regards,
> >
> >
> >
> >
> >
> > _______________________________________________
> > Kernelnewbies mailing list
> > Kernelnewbies at kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> Hi,
>
> At first glance, you have char n[20], but read 40 bytes in
> the read
> call. char is only 1 byte on x86 I believe so that might be
> your problem.
Hi Dexter,
I have commented remaining copy_to_user read function , it should be 6bytes,
> --
> -Dexter Haslem
>
^ permalink raw reply [flat|nested] 24+ messages in thread* copy_to_user
2010-12-23 1:18 ` copy_to_user Dexter Haslem
2010-12-23 2:15 ` copy_to_user Hemanth Kumar
@ 2010-12-23 4:35 ` Srinivas G.
2010-12-23 5:18 ` copy_to_user Hemanth Kumar
2010-12-23 5:37 ` copy_to_user mukti jain
1 sibling, 2 replies; 24+ messages in thread
From: Srinivas G. @ 2010-12-23 4:35 UTC (permalink / raw)
To: kernelnewbies
> On 12/22/2010 5:59 PM, Hemanth Kumar wrote:
> > Hi All,
> >
> > I have small problem with copy_to_user in read
> function,below is my code,when I try to read from userspace I get
> segmentation fault,
> > Can any please point me where I went wrong,
I guess, you need to also implement open method in your driver. Because,
you are opening the device in your application. Could you try this?
Regards,
Srinivas G
> >
> >
> > #include<linux/kernel.h>
> > #include<linux/module.h>
> > #include<linux/init.h>
> > #include<linux/types.h>
> > #include<linux/proc_fs.h>
> > #include<linux/fs.h>
> > #include<linux/kdev_t.h>
> > #include<linux/jiffies.h>
> > #include<linux/cdev.h>
> > #include<asm/uaccess.h>
> > #include<linux/mutex.h>
> >
> > struct mutex timer;
> > static struct cdev my_cdev;
> > dev_t devn;
> > int maj = 300;
> > int min = 0;
> > int count = 1;
> > char modname[] = "mytimer";
> > short x[10] = {1,2,3,4,5,6,7,8,9,10};
> >
> >
> >
> >
> > ssize_t my_read(struct file *file,char *buf,size_t count,loff_t
> *pos){
> > unsigned long res;
> > void *k = (void *)&x;
> > void *l = (void *)&x+1;
> > void *j = (void *)&x+2;
> >
> > mutex_lock(&timer);
> > res =
> copy_to_user(buf,k,sizeof(short));
> > res =
> copy_to_user(buf,l,sizeof(short));
> > res =
> copy_to_user(buf,j,sizeof(short));
> >
> > /* res =
> copy_to_user(buf,&x+4,sizeof(short));
> > res =
> copy_to_user(buf,&x+5,sizeof(short));
> > res =
> copy_to_user(buf,&x+6,sizeof(short));
> > res =
> copy_to_user(buf,&x+7,sizeof(short));
> > res =
> copy_to_user(buf,&x+8,sizeof(short));
> > res =
> copy_to_user(buf,&x+9,sizeof(short));
> > */
> > mutex_unlock(&timer);
> >
> > return 20;
> >
> > }
> >
> >
> > static struct file_operations my_fops = {
> > .owner = THIS_MODULE,
> > .read = my_read,
> >
> > };
> >
> >
> > static int __init my_init(void){
> > int ret;
> > devn = MKDEV(maj,min);
> >
> > ret = register_chrdev_region(devn,count,modname);
> >
> > cdev_init(&my_cdev,&my_fops);
> > cdev_add(&my_cdev,devn,count);
> >
> > printk("<1> Register timer maj = %d\n",maj);
> >
> >
> >
> >
> > return 0;
> > }
> >
> >
> >
> > static void __exit my_exit(void){
> >
> > cdev_del(&my_cdev);
> > unregister_chrdev_region(devn,count);
> > printk("<1> Bye Bye \n");
> >
> > }
> >
> >
> > module_init(my_init);
> > module_exit(my_exit);
> > MODULE_LICENSE("Dual BSD/GPL");
> >
> >
> >
> >
> > my userspace App:
> >
> > #include<stdio.h>
> > #include<fcntl.h>
> > #include<stdlib.h>
> > #include<unistd.h>
> >
> > int main()
> > {
> > int nbytes ;
> > char n[20];
> > short a = *((short *)&n[0]);
> > short b = *((short *)&n[2]);
> > short c = *((short *)&n[4]);
> >
> > int fd = open( "/dev/mytimer", O_RDONLY );
> > if ( fd< 0 ) { perror( "/dev/mytimer" ); exit(1); }
> >
> > while ( 1 )
> > {
> >
> > nbytes = read( fd, n, 40 );
> > if ( nbytes< 0 ) break;
> >
> > printf( "\r a = %d \n ", a);
> > printf("\r b = %d \n",b);
> > printf("\r c = %d \n",c);
> >
> > sleep(1);
> > fflush( stdout );
> > }
> > return 0;
> > }
> >
> >
> >
> >
> > Best regards,
> >
> >
> >
> >
> >
> > _______________________________________________
> > Kernelnewbies mailing list
> > Kernelnewbies at kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> Hi,
>
> At first glance, you have char n[20], but read 40 bytes in the read
> call. char is only 1 byte on x86 I believe so that might be your
> problem.
>
> --
> -Dexter Haslem
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
^ permalink raw reply [flat|nested] 24+ messages in thread* copy_to_user
2010-12-23 4:35 ` copy_to_user Srinivas G.
@ 2010-12-23 5:18 ` Hemanth Kumar
2010-12-23 5:37 ` copy_to_user mukti jain
1 sibling, 0 replies; 24+ messages in thread
From: Hemanth Kumar @ 2010-12-23 5:18 UTC (permalink / raw)
To: kernelnewbies
--- On Thu, 23/12/10, Srinivas G. <srinivasg@esntechnologies.co.in> wrote:
> From: Srinivas G. <srinivasg@esntechnologies.co.in>
> Subject: RE: copy_to_user
> To: "Dexter Haslem" <dexter.haslem@gmail.com>, "Hemanth Kumar" <hemwire@yahoo.co.in>
> Cc: Kernelnewbies at kernelnewbies.org
> Date: Thursday, 23 December, 2010, 10:05 AM
> > On 12/22/2010 5:59 PM, Hemanth
> Kumar wrote:
> > > Hi All,
> > >
> > >? ? ? ? ?
> ???I have small problem with copy_to_user in
> read
> > function,below is my code,when I try to read from
> userspace I get
> > segmentation fault,
> > > Can any please point me where I went wrong,
>
> I guess, you need to also implement open method in your
> driver. Because,
> you are opening the device in your application. Could you
> try this?
>
> Regards,
> Srinivas G
Hi Srinivas,
I tried it,but with out any success,the same problem,
regards,
> > >
> > >
> > > #include<linux/kernel.h>
> > > #include<linux/module.h>
> > > #include<linux/init.h>
> > > #include<linux/types.h>
> > > #include<linux/proc_fs.h>
> > > #include<linux/fs.h>
> > > #include<linux/kdev_t.h>
> > > #include<linux/jiffies.h>
> > > #include<linux/cdev.h>
> > > #include<asm/uaccess.h>
> > > #include<linux/mutex.h>
> > >
> > > struct mutex timer;
> > > static struct cdev my_cdev;
> > > dev_t devn;
> > > int maj = 300;
> > > int min = 0;
> > > int count = 1;
> > > char modname[] = "mytimer";
> > > short x[10] = {1,2,3,4,5,6,7,8,9,10};
> > >
> > >
> > >
> > >
> > > ssize_t my_read(struct file *file,char
> *buf,size_t count,loff_t
> > *pos){
> > >? ? ???unsigned long
> res;
> > >? ? ???void *k = (void
> *)&x;
> > >? ? ? ? ? ? void *l
> = (void *)&x+1;
> > >? ? ? ? ? ? void *j
> = (void *)&x+2;
> > >
> > >? ? ? ? ? ? ?
> ? ? ?
> ???mutex_lock(&timer);
> > >? ? ? ? ? ? ?
> ? ? ? ? ? ? ?
> ???res =
> > copy_to_user(buf,k,sizeof(short));
> > >? ? ? ? ? ? ?
> ? ? ? ? ? ? ?
> ???res =
> > copy_to_user(buf,l,sizeof(short));
> > >? ? ? ? ? ? ?
> ? ? ? ? ? ? ?
> ???res =
> > copy_to_user(buf,j,sizeof(short));
> > >
> > >? ? ? ? ? ? ?
> ? ? ? ? ???/*?
> ? res =
> > copy_to_user(buf,&x+4,sizeof(short));
> > >? ? ? ? ? ? ?
> ? ? ? ? ? ? ?
> ???res =
> > copy_to_user(buf,&x+5,sizeof(short));
> > >? ? ? ? ? ? ?
> ? ? ? ? ? ? ?
> ???res =
> > copy_to_user(buf,&x+6,sizeof(short));
> > >? ? ? ? ? ? ?
> ? ? ? ? ? ? ?
> ???res =
> > copy_to_user(buf,&x+7,sizeof(short));
> > >? ? ? ? ? ? ?
> ? ? ? ? ? ? ?
> ???res =
> > copy_to_user(buf,&x+8,sizeof(short));
> > >? ? ? ? ? ? ?
> ? ? ? ? ? ? ?
> ???res =
> > copy_to_user(buf,&x+9,sizeof(short));
> > >? ? ? ? ? ? ?
> ? ? ? ? ? ? */
> > >? ? ? ? ? ? ?
> ? ???mutex_unlock(&timer);
> > >
> > >? ???return 20;
> > >
> > > }
> > >
> > >
> > > static struct file_operations my_fops = {
> > >? ? ? ? ? ? ?
> ? ???.owner = THIS_MODULE,
> > >? ? ? ? ? ? ?
> ? ???.read = my_read,
> > >
> > > };
> > >
> > >
> > > static int __init my_init(void){
> > >? ? ? ? ? int ret;
> > >? ???devn = MKDEV(maj,min);
> > >
> > >? ? ???ret =
> register_chrdev_region(devn,count,modname);
> > >
> > >? ? ? ?
> cdev_init(&my_cdev,&my_fops);
> > >? ? ? ?
> cdev_add(&my_cdev,devn,count);
> > >
> > >? ? ? ?
> printk("<1>? Register timer maj = %d\n",maj);
> > >
> > >
> > >
> > >
> > >???return 0;
> > > }
> > >
> > >
> > >
> > > static void __exit my_exit(void){
> > >
> > >? ? ? ?
> cdev_del(&my_cdev);
> > >? ? ?
> ???unregister_chrdev_region(devn,count);
> > >? ? ? ? ?
> printk("<1>? Bye Bye \n");
> > >
> > > }
> > >
> > >
> > > module_init(my_init);
> > > module_exit(my_exit);
> > > MODULE_LICENSE("Dual BSD/GPL");
> > >
> > >
> > >
> > >
> > > my userspace App:
> > >
> > > #include<stdio.h>
> > > #include<fcntl.h>
> > > #include<stdlib.h>
> > > #include<unistd.h>
> > >
> > > int main()
> > > {
> > >? ? ? ? ???int
> nbytes ;
> > >? ? ? ? ???char
> n[20];
> > >? ? ? ?
> ???short a = *((short *)&n[0]);
> > >? ? ? ?
> ???short b = *((short *)&n[2]);
> > >? ? ? ?
> ???short c = *((short *)&n[4]);
> > >
> > >? ? ? ? ? int?
> ???fd = open( "/dev/mytimer", O_RDONLY );
> > >? ? ? ? ? if (
> fd<? 0 ) { perror( "/dev/mytimer" ); exit(1); }
> > >
> > > while ( 1 )
> > >? ? ? ? ? ? ?
> ? ? {
> > >
> > >? ? ? ? ? ? ?
> ? ???nbytes = read( fd, n, 40 );
> > >? ? ? ? ? ? ?
> ? ? if ( nbytes<? 0 ) break;
> > >
> > >? ? ? ? ? ? ?
> ? ? printf( "\r a = %d \n ", a);
> > >? ? ? ? ? ? ?
> ? ? printf("\r b = %d \n",b);
> > >? ? ? ? ? ? ?
> ? ? printf("\r c = %d \n",c);
> > >
> > >? ? ? ? ? ? ?
> ? ? sleep(1);
> > >? ? ? ? ? ? ?
> ? ? fflush( stdout );
> > >? ? ? ? ? ? ?
> ? ? }
> > > return 0;
> > > }
> > >
> > >
> > >
> > >
> > > Best regards,
> > >
> > >
> > >
> > >
> > >
> > > _______________________________________________
> > > Kernelnewbies mailing list
> > > Kernelnewbies at kernelnewbies.org
> > > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> > Hi,
> >
> > At first glance, you have char n[20], but read 40
> bytes in the read
> > call. char is only 1 byte on x86 I believe so that
> might be your
> > problem.
> >
> > --
> > -Dexter Haslem
> >
> > _______________________________________________
> > Kernelnewbies mailing list
> > Kernelnewbies at kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
^ permalink raw reply [flat|nested] 24+ messages in thread* copy_to_user
2010-12-23 4:35 ` copy_to_user Srinivas G.
2010-12-23 5:18 ` copy_to_user Hemanth Kumar
@ 2010-12-23 5:37 ` mukti jain
2010-12-23 12:21 ` copy_to_user Hemanth Kumar
2010-12-24 6:07 ` copy_to_user Hemanth Kumar
1 sibling, 2 replies; 24+ messages in thread
From: mukti jain @ 2010-12-23 5:37 UTC (permalink / raw)
To: kernelnewbies
On Thu, Dec 23, 2010 at 10:05 AM, Srinivas G. <
srinivasg@esntechnologies.co.in> wrote:
> > On 12/22/2010 5:59 PM, Hemanth Kumar wrote:
> > > Hi All,
> > >
> > > I have small problem with copy_to_user in read
> > function,below is my code,when I try to read from userspace I get
> > segmentation fault,
> > > Can any please point me where I went wrong,
>
> I guess, you need to also implement open method in your driver. Because,
> you are opening the device in your application. Could you try this?
>
> Regards,
> Srinivas G
>
> > >
> > >
> > > #include<linux/kernel.h>
> > > #include<linux/module.h>
> > > #include<linux/init.h>
> > > #include<linux/types.h>
> > > #include<linux/proc_fs.h>
> > > #include<linux/fs.h>
> > > #include<linux/kdev_t.h>
> > > #include<linux/jiffies.h>
> > > #include<linux/cdev.h>
> > > #include<asm/uaccess.h>
> > > #include<linux/mutex.h>
> > >
> > > struct mutex timer;
> > > static struct cdev my_cdev;
> > > dev_t devn;
> > > int maj = 300;
> > > int min = 0;
> > > int count = 1;
> > > char modname[] = "mytimer";
> > > short x[10] = {1,2,3,4,5,6,7,8,9,10};
> > >
> > >
> > >
> > >
> > > ssize_t my_read(struct file *file,char *buf,size_t count,loff_t
> > *pos){
> > > unsigned long res;
> > > void *k = (void *)&x;
> > > void *l = (void *)&x+1;
> > > void *j = (void *)&x+2;
> > >
> > > mutex_lock(&timer);
> > > res =
> > copy_to_user(buf,k,sizeof(short));
> > > res =
> > copy_to_user(buf,l,sizeof(short));
> > > res =
> > copy_to_user(buf,j,sizeof(short));
> > >
> > > /* res =
> > copy_to_user(buf,&x+4,sizeof(short));
> > > res =
> > copy_to_user(buf,&x+5,sizeof(short));
> > > res =
> > copy_to_user(buf,&x+6,sizeof(short));
> > > res =
> > copy_to_user(buf,&x+7,sizeof(short));
> > > res =
> > copy_to_user(buf,&x+8,sizeof(short));
> > > res =
> > copy_to_user(buf,&x+9,sizeof(short));
> > > */
> > > mutex_unlock(&timer);
> > >
> > > return 20;
> > >
> > > }
> > >
> > >
> > > static struct file_operations my_fops = {
> > > .owner = THIS_MODULE,
> > > .read = my_read,
> > >
> > > };
> > >
> > >
> > > static int __init my_init(void){
> > > int ret;
> > > devn = MKDEV(maj,min);
> > >
> > > ret = register_chrdev_region(devn,count,modname);
> > >
> > > cdev_init(&my_cdev,&my_fops);
> > > cdev_add(&my_cdev,devn,count);
> > >
> > > printk("<1> Register timer maj = %d\n",maj);
> > >
> > >
> > >
> > >
> > > return 0;
> > > }
> > >
> > >
> > >
> > > static void __exit my_exit(void){
> > >
> > > cdev_del(&my_cdev);
> > > unregister_chrdev_region(devn,count);
> > > printk("<1> Bye Bye \n");
> > >
> > > }
> > >
> > >
> > > module_init(my_init);
> > > module_exit(my_exit);
> > > MODULE_LICENSE("Dual BSD/GPL");
> > >
> > >
> > >
> > >
> > > my userspace App:
> > >
> > > #include<stdio.h>
> > > #include<fcntl.h>
> > > #include<stdlib.h>
> > > #include<unistd.h>
> > >
> > > int main()
> > > {
> > > int nbytes ;
> > > char n[20];
> > > short a = *((short *)&n[0]);
> > > short b = *((short *)&n[2]);
> > > short c = *((short *)&n[4]);
> > >
> > > int fd = open( "/dev/mytimer", O_RDONLY );
> > > if ( fd< 0 ) { perror( "/dev/mytimer" ); exit(1); }
> > >
> > > while ( 1 )
> > > {
> > >
> > > nbytes = read( fd, n, 40 );
> > > if ( nbytes< 0 ) break;
> > >
> > > printf( "\r a = %d \n ", a);
> > > printf("\r b = %d \n",b);
> > > printf("\r c = %d \n",c);
> > >
> > > sleep(1);
> > > fflush( stdout );
> > > }
> > > return 0;
> > > }
> > >
> > >
> > >
> > >
> > > Best regards,
> > >
> > >
>
The mutex initialization is missing.
Adding mutex_init(&timer); in the driver init will make it work.
Thanks,
Mukti
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20101223/060d4f33/attachment-0001.html
^ permalink raw reply [flat|nested] 24+ messages in thread* copy_to_user
2010-12-23 5:37 ` copy_to_user mukti jain
@ 2010-12-23 12:21 ` Hemanth Kumar
2010-12-24 6:07 ` copy_to_user Hemanth Kumar
1 sibling, 0 replies; 24+ messages in thread
From: Hemanth Kumar @ 2010-12-23 12:21 UTC (permalink / raw)
To: kernelnewbies
--- On Thu, 23/12/10, mukti jain <muktijn@gmail.com> wrote:
From: mukti jain <muktijn@gmail.com>
Subject: Re: copy_to_user
To: "Srinivas G." <srinivasg@esntechnologies.co.in>
Cc: "Dexter Haslem" <dexter.haslem@gmail.com>, "Hemanth Kumar" <hemwire@yahoo.co.in>, Kernelnewbies at kernelnewbies.org
Date: Thursday, 23 December, 2010, 11:07 AM
On Thu, Dec 23, 2010 at 10:05 AM, Srinivas G. <srinivasg@esntechnologies.co.in> wrote:
> On 12/22/2010 5:59 PM, Hemanth Kumar wrote:
> > Hi All,
> >
> > ? ? ? ? ? ? I have small problem with copy_to_user in read
> function,below is my code,when I try to read from userspace I get
> segmentation fault,
> > Can any please point me where I went wrong,
I guess, you need to also implement open method in your driver. Because,
you are opening the device in your application. Could you try this?
Regards,
Srinivas G
> >
> >
> > #include<linux/kernel.h>
> > #include<linux/module.h>
> > #include<linux/init.h>
> > #include<linux/types.h>
> > #include<linux/proc_fs.h>
> > #include<linux/fs.h>
> > #include<linux/kdev_t.h>
> > #include<linux/jiffies.h>
> > #include<linux/cdev.h>
> > #include<asm/uaccess.h>
> > #include<linux/mutex.h>
> >
> > struct mutex timer;
> > static struct cdev my_cdev;
> > dev_t devn;
> > int maj = 300;
> > int min = 0;
> > int count = 1;
> > char modname[] = "mytimer";
> > short x[10] = {1,2,3,4,5,6,7,8,9,10};
> >
> >
> >
> >
> > ssize_t my_read(struct file *file,char *buf,size_t count,loff_t
> *pos){
> > ? ? ? unsigned long res;
> > ? ? ? void *k = (void *)&x;
> > ? ? ? ? ? ?void *l = (void *)&x+1;
> > ? ? ? ? ? ?void *j = (void *)&x+2;
> >
> > ? ? ? ? ? ? ? ? ? ? ? mutex_lock(&timer);
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,k,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,l,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,j,sizeof(short));
> >
> > ? ? ? ? ? ? ? ? ? ? ? ? /* ? ?res =
> copy_to_user(buf,&x+4,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,&x+5,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,&x+6,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,&x+7,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,&x+8,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,&x+9,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ?*/
> > ? ? ? ? ? ? ? ? ? mutex_unlock(&timer);
> >
> > ? ? return 20;
> >
> > }
> >
> >
> > static struct file_operations my_fops = {
> > ? ? ? ? ? ? ? ? ? .owner = THIS_MODULE,
> > ? ? ? ? ? ? ? ? ? .read = my_read,
> >
> > };
> >
> >
> > static int __init my_init(void){
> > ? ? ? ? ?int ret;
> > ? ? devn = MKDEV(maj,min);
> >
> > ? ? ? ret = register_chrdev_region(devn,count,modname);
> >
> > ? ? ? ?cdev_init(&my_cdev,&my_fops);
> > ? ? ? ?cdev_add(&my_cdev,devn,count);
> >
> > ? ? ? ?printk("<1> ?Register timer maj = %d\n",maj);
> >
> >
> >
> >
> > ? return 0;
> > }
> >
> >
> >
> > static void __exit my_exit(void){
> >
> > ? ? ? ?cdev_del(&my_cdev);
> > ? ? ? ? unregister_chrdev_region(devn,count);
> > ? ? ? ? ?printk("<1> ?Bye Bye \n");
> >
> > }
> >
> >
> > module_init(my_init);
> > module_exit(my_exit);
> > MODULE_LICENSE("Dual BSD/GPL");
> >
> >
> >
> >
> > my userspace App:
> >
> > #include<stdio.h>
> > #include<fcntl.h>
> > #include<stdlib.h>
> > #include<unistd.h>
> >
> > int main()
> > {
> > ? ? ? ? ? int nbytes ;
> > ? ? ? ? ? char n[20];
> > ? ? ? ? ? short a = *((short *)&n[0]);
> > ? ? ? ? ? short b = *((short *)&n[2]);
> > ? ? ? ? ? short c = *((short *)&n[4]);
> >
> > ? ? ? ? ?int ? ? fd = open( "/dev/mytimer", O_RDONLY );
> > ? ? ? ? ?if ( fd< ?0 ) { perror( "/dev/mytimer" ); exit(1); }
> >
> > while ( 1 )
> > ? ? ? ? ? ? ? ? ?{
> >
> > ? ? ? ? ? ? ? ? ? nbytes = read( fd, n, 40 );
> > ? ? ? ? ? ? ? ? ?if ( nbytes< ?0 ) break;
> >
> > ? ? ? ? ? ? ? ? ?printf( "\r a = %d \n ", a);
> > ? ? ? ? ? ? ? ? ?printf("\r b = %d \n",b);
> > ? ? ? ? ? ? ? ? ?printf("\r c = %d \n",c);
> >
> > ? ? ? ? ? ? ? ? ?sleep(1);
> > ? ? ? ? ? ? ? ? ?fflush( stdout );
> > ? ? ? ? ? ? ? ? ?}
> > return 0;
> > }
> >
> >
> >
> >
> > Best regards,
> >
> >
The mutex initialization is missing.
Adding? mutex_init(&timer); in the driver init will make it work.
Thanks,
Mukti
Hi All,
?still have dont have success,Can any please share some idea,
Regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20101223/786e1279/attachment-0001.html
^ permalink raw reply [flat|nested] 24+ messages in thread* copy_to_user
2010-12-23 5:37 ` copy_to_user mukti jain
2010-12-23 12:21 ` copy_to_user Hemanth Kumar
@ 2010-12-24 6:07 ` Hemanth Kumar
2010-12-24 7:59 ` copy_to_user Nilesh Tayade
1 sibling, 1 reply; 24+ messages in thread
From: Hemanth Kumar @ 2010-12-24 6:07 UTC (permalink / raw)
To: kernelnewbies
--- On Thu, 23/12/10, mukti jain <muktijn@gmail.com> wrote:
From: mukti jain <muktijn@gmail.com>
Subject: Re: copy_to_user
To: "Srinivas G." <srinivasg@esntechnologies.co.in>
Cc: "Dexter Haslem" <dexter.haslem@gmail.com>, "Hemanth Kumar" <hemwire@yahoo.co.in>, Kernelnewbies at kernelnewbies.org
Date: Thursday, 23 December, 2010, 11:07 AM
On Thu, Dec 23, 2010 at 10:05 AM, Srinivas G. <srinivasg@esntechnologies.co.in> wrote:
> On 12/22/2010 5:59 PM, Hemanth Kumar wrote:
> > Hi All,
> >
> > ? ? ? ? ? ? I have small problem with copy_to_user in read
> function,below is my code,when I try to read from userspace I get
> segmentation fault,
> > Can any please point me where I went wrong,
I guess, you need to also implement open method in your driver. Because,
you are opening the device in your application. Could you try this?
Regards,
Srinivas G
> >
> >
> > #include<linux/kernel.h>
> > #include<linux/module.h>
> > #include<linux/init.h>
> > #include<linux/types.h>
> > #include<linux/proc_fs.h>
> > #include<linux/fs.h>
> > #include<linux/kdev_t.h>
> > #include<linux/jiffies.h>
> > #include<linux/cdev.h>
> > #include<asm/uaccess.h>
> > #include<linux/mutex.h>
> >
> > struct mutex timer;
> > static struct cdev my_cdev;
> > dev_t devn;
> > int maj = 300;
> > int min = 0;
> > int count = 1;
> > char modname[] = "mytimer";
> > short x[10] = {1,2,3,4,5,6,7,8,9,10};
> >
> >
> >
> >
> > ssize_t my_read(struct file *file,char *buf,size_t count,loff_t
> *pos){
> > ? ? ? unsigned long res;
> > ? ? ? void *k = (void *)&x;
> > ? ? ? ? ? ?void *l = (void *)&x+1;
> > ? ? ? ? ? ?void *j = (void *)&x+2;
> >
> > ? ? ? ? ? ? ? ? ? ? ? mutex_lock(&timer);
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,k,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,l,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,j,sizeof(short));
> >
> > ? ? ? ? ? ? ? ? ? ? ? ? /* ? ?res =
> copy_to_user(buf,&x+4,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,&x+5,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,&x+6,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,&x+7,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,&x+8,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? res =
> copy_to_user(buf,&x+9,sizeof(short));
> > ? ? ? ? ? ? ? ? ? ? ? ? ?*/
> > ? ? ? ? ? ? ? ? ? mutex_unlock(&timer);
> >
> > ? ? return 20;
> >
> > }
> >
> >
> > static struct file_operations my_fops = {
> > ? ? ? ? ? ? ? ? ? .owner = THIS_MODULE,
> > ? ? ? ? ? ? ? ? ? .read = my_read,
> >
> > };
> >
> >
> > static int __init my_init(void){
> > ? ? ? ? ?int ret;
> > ? ? devn = MKDEV(maj,min);
> >
> > ? ? ? ret = register_chrdev_region(devn,count,modname);
> >
> > ? ? ? ?cdev_init(&my_cdev,&my_fops);
> > ? ? ? ?cdev_add(&my_cdev,devn,count);
> >
> > ? ? ? ?printk("<1> ?Register timer maj = %d\n",maj);
> >
> >
> >
> >
> > ? return 0;
> > }
> >
> >
> >
> > static void __exit my_exit(void){
> >
> > ? ? ? ?cdev_del(&my_cdev);
> > ? ? ? ? unregister_chrdev_region(devn,count);
> > ? ? ? ? ?printk("<1> ?Bye Bye \n");
> >
> > }
> >
> >
> > module_init(my_init);
> > module_exit(my_exit);
> > MODULE_LICENSE("Dual BSD/GPL");
> >
> >
> >
> >
> > my userspace App:
> >
> > #include<stdio.h>
> > #include<fcntl.h>
> > #include<stdlib.h>
> > #include<unistd.h>
> >
> > int main()
> > {
> > ? ? ? ? ? int nbytes ;
> > ? ? ? ? ? char n[20];
> > ? ? ? ? ? short a = *((short *)&n[0]);
> > ? ? ? ? ? short b = *((short *)&n[2]);
> > ? ? ? ? ? short c = *((short *)&n[4]);
> >
> > ? ? ? ? ?int ? ? fd = open( "/dev/mytimer", O_RDONLY );
> > ? ? ? ? ?if ( fd< ?0 ) { perror( "/dev/mytimer" ); exit(1); }
> >
> > while ( 1 )
> > ? ? ? ? ? ? ? ? ?{
> >
> > ? ? ? ? ? ? ? ? ? nbytes = read( fd, n, 40 );
> > ? ? ? ? ? ? ? ? ?if ( nbytes< ?0 ) break;
> >
> > ? ? ? ? ? ? ? ? ?printf( "\r a = %d \n ", a);
> > ? ? ? ? ? ? ? ? ?printf("\r b = %d \n",b);
> > ? ? ? ? ? ? ? ? ?printf("\r c = %d \n",c);
> >
> > ? ? ? ? ? ? ? ? ?sleep(1);
> > ? ? ? ? ? ? ? ? ?fflush( stdout );
> > ? ? ? ? ? ? ? ? ?}
> > return 0;
> > }
> >
> >
> >
> >
> > Best regards,
> >
> >
The mutex initialization is missing.
Adding? mutex_init(&timer); in the driver init will make it work.
Thanks,
Mukti
Hi All,
??? Can anybody please share some idea ,why I am getting segmentation fault & kernel oops,
Regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20101224/c69a2f0d/attachment-0001.html
^ permalink raw reply [flat|nested] 24+ messages in thread* copy_to_user
2010-12-24 6:07 ` copy_to_user Hemanth Kumar
@ 2010-12-24 7:59 ` Nilesh Tayade
2010-12-24 9:00 ` copy_to_user Dave Hylands
2010-12-24 9:26 ` copy_to_user Hemanth Kumar
0 siblings, 2 replies; 24+ messages in thread
From: Nilesh Tayade @ 2010-12-24 7:59 UTC (permalink / raw)
To: kernelnewbies
Hi,
On Fri, 2010-12-24 at 11:37 +0530, Hemanth Kumar wrote:
>
> > >
>
> The mutex initialization is missing.
> Adding mutex_init(&timer); in the driver init will make it
> work.
>
> Thanks,
> Mukti
>
>
> Hi All,
>
> Can anybody please share some idea ,why I am getting
> segmentation fault & kernel oops,
>
> Regards,
>
I tried it, and it seems adding mutex_init() works as Mukti mentioned. I
did get a kernel oops before (but no segfault). After adding
mutex_init() there is no oops/segfault. The code, however, is reading
the garbage, that needs to be fixed.
pun-nilesht-dt0:/home/nilesh/Documents/handson # !mknod
mknod /dev/mytimer c 300 0
pun-nilesht-dt0:/home/nilesh/Documents # dmesg
[ 2193.684735] Register timer maj = 300
pun-nilesht-dt0:/home/nilesh/Documents/handson # ./my_app.o
a = -30048
b = -23975
c = 32582
...
See the attachments in case something is missing the code.
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
--
Thanks,
Nilesh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: my_drv.c
Type: text/x-csrc
Size: 1799 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20101224/a8ecc427/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: my_app.c
Type: text/x-csrc
Size: 560 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20101224/a8ecc427/attachment-0001.bin
^ permalink raw reply [flat|nested] 24+ messages in thread
* copy_to_user
2010-12-24 7:59 ` copy_to_user Nilesh Tayade
@ 2010-12-24 9:00 ` Dave Hylands
2010-12-24 9:20 ` copy_to_user Nilesh Tayade
2010-12-24 9:26 ` copy_to_user Hemanth Kumar
1 sibling, 1 reply; 24+ messages in thread
From: Dave Hylands @ 2010-12-24 9:00 UTC (permalink / raw)
To: kernelnewbies
Hi Nilesh.
On Thu, Dec 23, 2010 at 11:59 PM, Nilesh Tayade
<nilesh.tayade@netscout.com> wrote:
...snip...
> I tried it, and it seems adding mutex_init() works as Mukti mentioned. I
> did get a kernel oops before (but no segfault). After adding
> mutex_init() there is no oops/segfault. The code, however, is reading
> the garbage, that needs to be fixed.
char n[20];
short a = *((short *)&n[0]);
short b = *((short *)&n[2]);
short c = *((short *)&n[4]);
This sets a b and c to have essentially random values.
nbytes = read( fd, n, 40);
This causes the value of n to change. However, the values of a, b, and
c retain the same random values you assigned them above.
printf( "\r a = %d \n ", a);
printf("\r b = %d \n",b);
printf("\r c = %d \n",c);
This prints the random values of a, b, and c rather than printing thee
values of n that you read in.
Dave Hylands
^ permalink raw reply [flat|nested] 24+ messages in thread* copy_to_user
2010-12-24 9:00 ` copy_to_user Dave Hylands
@ 2010-12-24 9:20 ` Nilesh Tayade
2010-12-24 10:00 ` copy_to_user Hemanth Kumar
0 siblings, 1 reply; 24+ messages in thread
From: Nilesh Tayade @ 2010-12-24 9:20 UTC (permalink / raw)
To: kernelnewbies
On Fri, 2010-12-24 at 01:00 -0800, Dave Hylands wrote:
> Hi Nilesh.
>
> On Thu, Dec 23, 2010 at 11:59 PM, Nilesh Tayade
> <nilesh.tayade@netscout.com> wrote:
> ...snip...
> > I tried it, and it seems adding mutex_init() works as Mukti mentioned. I
> > did get a kernel oops before (but no segfault). After adding
> > mutex_init() there is no oops/segfault. The code, however, is reading
> > the garbage, that needs to be fixed.
>
> char n[20];
> short a = *((short *)&n[0]);
> short b = *((short *)&n[2]);
> short c = *((short *)&n[4]);
>
> This sets a b and c to have essentially random values.
>
> nbytes = read( fd, n, 40);
>
> This causes the value of n to change. However, the values of a, b, and
> c retain the same random values you assigned them above.
>
> printf( "\r a = %d \n ", a);
> printf("\r b = %d \n",b);
> printf("\r c = %d \n",c);
>
> This prints the random values of a, b, and c rather than printing thee
> values of n that you read in.
Thanks for the explanation Dave.
I did not really bother to debug to avoid the garbage values, as the
main concern was for segfault and kernel oops.
>
> Dave Hylands
--
Thanks,
Nilesh
^ permalink raw reply [flat|nested] 24+ messages in thread* copy_to_user
2010-12-24 9:20 ` copy_to_user Nilesh Tayade
@ 2010-12-24 10:00 ` Hemanth Kumar
0 siblings, 0 replies; 24+ messages in thread
From: Hemanth Kumar @ 2010-12-24 10:00 UTC (permalink / raw)
To: kernelnewbies
Hi Dave & Nilesh,
Thanks for your support I fixed it,
Regards,
hemanth
--- On Fri, 24/12/10, Nilesh Tayade <nilesh.tayade@netscout.com> wrote:
> From: Nilesh Tayade <nilesh.tayade@netscout.com>
> Subject: Re: copy_to_user
> To: "Dave Hylands" <dhylands@gmail.com>
> Cc: "Srinivas G." <srinivasg@esntechnologies.co.in>, "Dexter Haslem" <dexter.haslem@gmail.com>, "Hemanth Kumar" <hemwire@yahoo.co.in>, "mukti jain" <muktijn@gmail.com>, Kernelnewbies at kernelnewbies.org
> Date: Friday, 24 December, 2010, 2:50 PM
> On Fri, 2010-12-24 at 01:00 -0800,
> Dave Hylands wrote:
> > Hi Nilesh.
> >
> > On Thu, Dec 23, 2010 at 11:59 PM, Nilesh Tayade
> > <nilesh.tayade@netscout.com>
> wrote:
> > ...snip...
> > > I tried it, and it seems adding mutex_init()
> works as Mukti mentioned. I
> > > did get a kernel oops before (but no segfault).
> After adding
> > > mutex_init() there is no oops/segfault. The code,
> however, is reading
> > > the garbage, that needs to be fixed.
> >
> > ??? char n[20];
> > ??? short a = *((short *)&n[0]);
> > ??? short b = *((short *)&n[2]);
> > ??? short c = *((short *)&n[4]);
> >
> > This sets a b and c to have essentially random
> values.
> >
> > ??? ??? nbytes = read(
> fd, n, 40);
> >
> > This causes the value of n to change. However, the
> values of a, b, and
> > c retain the same random values you assigned them
> above.
> >
> > ??? ??? printf( "\r a =
> %d \n ", a);
> > ??? ??? printf("\r b =
> %d \n",b);
> > ??? ??? printf("\r c =
> %d \n",c);
> >
> > This prints the random values of a, b, and c rather
> than printing thee
> > values of n that you read in.
>
> Thanks for the explanation Dave.
>
> I did not really bother to debug to avoid the garbage
> values, as the
> main concern was for segfault and kernel oops.
>
> >
> > Dave Hylands
>
>
> --
> Thanks,
> Nilesh
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* copy_to_user
2010-12-24 7:59 ` copy_to_user Nilesh Tayade
2010-12-24 9:00 ` copy_to_user Dave Hylands
@ 2010-12-24 9:26 ` Hemanth Kumar
1 sibling, 0 replies; 24+ messages in thread
From: Hemanth Kumar @ 2010-12-24 9:26 UTC (permalink / raw)
To: kernelnewbies
Hi Nilesh & mukti,
--- On Fri, 24/12/10, Nilesh Tayade <nilesh.tayade@netscout.com> wrote:
> From: Nilesh Tayade <nilesh.tayade@netscout.com>
> Subject: Re: copy_to_user
> To: "Hemanth Kumar" <hemwire@yahoo.co.in>
> Cc: "Dexter Haslem" <dexter.haslem@gmail.com>, "mukti jain" <muktijn@gmail.com>, "Srinivas G." <srinivasg@esntechnologies.co.in>, Kernelnewbies at kernelnewbies.org
> Date: Friday, 24 December, 2010, 1:29 PM
> Hi,
>
> On Fri, 2010-12-24 at 11:37 +0530, Hemanth Kumar wrote:
>
> >? ? ? ? ? ? ?
> ???
> >? ? ? ? ? ? ?
> ???> >
> >? ? ? ? ? ? ?
> ???
> >? ? ? ???The mutex
> initialization is missing.
> >? ? ? ???Adding?
> mutex_init(&timer); in the driver init will make it
> >? ? ? ???work.
> >? ? ? ???
> >? ? ? ???Thanks,
> >? ? ? ???Mukti
> >? ? ? ???
> >? ? ? ???
> >? ? ? ???Hi All,
> >? ? ? ???
> >? ? ? ? ?
> ???Can anybody please share some idea ,why I
> am getting
> >? ? ? ???segmentation
> fault & kernel oops,
> >? ? ? ???
> >? ? ? ???Regards,
> >
>
> I tried it, and it seems adding mutex_init() works as Mukti
> mentioned. I
> did get a kernel oops before (but no segfault). After
> adding
> mutex_init() there is no oops/segfault. The code, however,
> is reading
> the garbage, that needs to be fixed.
>
> pun-nilesht-dt0:/home/nilesh/Documents/handson # !mknod
> mknod /dev/mytimer c 300 0
>
> pun-nilesht-dt0:/home/nilesh/Documents # dmesg
> [ 2193.684735] Register timer maj = 300
>
> pun-nilesht-dt0:/home/nilesh/Documents/handson # ./my_app.o
>
> a = -30048
> b = -23975
> c = 32582
> ...
>
> See the attachments in case something is missing the code.
>
> > _______________________________________________
> > Kernelnewbies mailing list
> > Kernelnewbies at kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
> --
> Thanks,
> Nilesh
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
I tried to do that,But it is reading the last element in the array(x[2] = 43), I have modified a bit but still not able read for x[0],below is the code,
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/proc_fs.h>
#include <linux/fs.h>
#include <linux/kdev_t.h>
#include <linux/jiffies.h>
#include <linux/cdev.h>
#include <asm/uaccess.h>
#include <linux/mutex.h>
struct mutex timer;
static struct cdev my_cdev;
dev_t devn;
int maj = 300;
int min = 0;
int count = 1;
char modname[] = "mytimer";
short x[10] = {1,2,43,4,5,6,7,8,9,10};
ssize_t my_read(struct file *file,char *buf,size_t count,loff_t *pos) {
unsigned long res;
void *k = (void *)x;
void *l = (void *)(x+1);
void *j = (void *)(x+2);
mutex_unlock(&timer);
return 6;
}
static struct file_operations my_fops = {
.owner = THIS_MODULE,
.read = my_read,
};
static int __init my_init(void){
int ret;
devn = MKDEV(maj,min);
ret = register_chrdev_region(devn,count,modname);
cdev_init(&my_cdev,&my_fops);
cdev_add(&my_cdev,devn,count);
mutex_init(&timer);
printk(KERN_CRIT "Register timer maj = %d\n",maj);
return 0;
}
static void __exit my_exit(void){
cdev_del(&my_cdev);
unregister_chrdev_region(devn,count);
printk("<1> Bye Bye \n");
}
module_init(my_init);
module_exit(my_exit);
MODULE_LICENSE("Dual BSD/GPL");
user space app
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
int nbytes ;
char n[20];
int fd = open( "/dev/mytimer", O_RDONLY );
if ( fd < 0 ) { perror( "/dev/mytimer" ); exit(1); }
while ( 1 )
{
nbytes = read( fd, n, 20);
if ( nbytes < 0 ) break;
short a = *((short *)&n[0]);
short b = *((short *)&n[2]);
short c = *((short *)&n[4]);
printf( "\r a = %d \n ", a);
printf("\r b = %d \n",b);
printf("\r c = %d \n",c);
sleep(1);
fflush( stdout );
}
return 0;
}
[root@Praval userspace]# ./my_app
a = 43
b = 0
c = -26552
a = 43
b = 0
c = -26552
a = 43
b = 0
c = -26552
a = 43
b = 0
c = -26552
a = 43
b = 0
c = -26552
I think i still miss something,
^ permalink raw reply [flat|nested] 24+ messages in thread
[parent not found: <589679.60204.qm@web94707.mail.in2.yahoo.com>]
* copy_to_user
[not found] <589679.60204.qm@web94707.mail.in2.yahoo.com>
@ 2010-12-24 18:31 ` Mulyadi Santosa
2010-12-26 1:33 ` copy_to_user Hemanth Kumar
0 siblings, 1 reply; 24+ messages in thread
From: Mulyadi Santosa @ 2010-12-24 18:31 UTC (permalink / raw)
To: kernelnewbies
On Fri, Dec 24, 2010 at 17:08, Hemanth Kumar <hemwire@yahoo.co.in> wrote:
> Hi Mulyadi,
>
> ? ? ? ? Sorry sending mail the direclty,fixed the code with help of mailing list,once again sorry sending mail the directly,
This time it's fine :)
So, what's the solution? care to let us know?
--
regards,
Mulyadi Santosa
Freelance Linux trainer and consultant
blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
^ permalink raw reply [flat|nested] 24+ messages in thread* copy_to_user
2010-12-24 18:31 ` copy_to_user Mulyadi Santosa
@ 2010-12-26 1:33 ` Hemanth Kumar
0 siblings, 0 replies; 24+ messages in thread
From: Hemanth Kumar @ 2010-12-26 1:33 UTC (permalink / raw)
To: kernelnewbies
Hi Mulaydi,
Sorry for late reply,the answer was provide by dave hayland,
in previous mail's.
Regards,
Hemanth
--- On Sat, 25/12/10, Mulyadi Santosa <mulyadi.santosa@gmail.com> wrote:
> From: Mulyadi Santosa <mulyadi.santosa@gmail.com>
> Subject: Re: copy_to_user
> To: "Hemanth Kumar" <hemwire@yahoo.co.in>
> Cc: "kernelnewbies" <Kernelnewbies@kernelnewbies.org>
> Date: Saturday, 25 December, 2010, 12:01 AM
> On Fri, Dec 24, 2010 at 17:08,
> Hemanth Kumar <hemwire@yahoo.co.in>
> wrote:
> > Hi Mulyadi,
> >
> > ? ? ? ? Sorry sending mail the direclty,fixed the
> code with help of mailing list,once again sorry sending mail
> the directly,
>
> This time it's fine :)
>
> So, what's the solution? care to let us know?
>
> --
> regards,
>
> Mulyadi Santosa
> Freelance Linux trainer and consultant
>
> blog: the-hydra.blogspot.com
> training: mulyaditraining.blogspot.com
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: copy to user
@ 2001-11-25 21:58 Marco C. Mason
0 siblings, 0 replies; 24+ messages in thread
From: Marco C. Mason @ 2001-11-25 21:58 UTC (permalink / raw)
To: umiguel, linux-kernel
Luis Henriques--
Before making my suggestion: Apologies to the list if this has already
been settled. I'm trying to catch up on my LKML reading, and I'm only
up to Nov 20 so far...
Anyway: Here's what I'd do, if I had to do such a apalling thing 8^)
Drop a function in your code something like:
_xyzzy:
db 0x18, 0xfe ; jr $
Then, when you detect the condition where you want to waste time, then
put the address of this function on top of the user stack (along with
whatever else in the stack frame is required) so that the code just sits
there burning CPU. To clean it up, you'd simply restore the original
stack frame to the process.
It's hideous & gross, but if you need it.....
--marco
^ permalink raw reply [flat|nested] 24+ messages in thread* copy to user
@ 2001-11-20 20:54 Luis Miguel Correia Henriques
2001-11-20 21:28 ` John Alvord
` (4 more replies)
0 siblings, 5 replies; 24+ messages in thread
From: Luis Miguel Correia Henriques @ 2001-11-20 20:54 UTC (permalink / raw)
To: linux-kernel
The reason that I need it to spend CPU time is that I'm developing a fault
injector. The purpose of a fault injection tool is, as you could imagine,
to test some critical systems and it's capacity to recover from fails. The
reason for changing the code of a process is that process must be delayed
but without leaving the CPU - everything must look like nothing wrong is
happening, except for other processes that are waiting for something from
the delayed process...
Maybe I should have explained this before... sorry.
I suppose now you can understand why SIGSTOP won't work. Hope you can help
me :)
About using udelay... this soluction seemed fine to me at first but if I
hang the CPU with udelay the scheduler will no be doing it's job (isn't
it?). This would give me even more intrusiveness (another requirement: the
less intrusiveness as possible).
Isn't there any doubt that copy_to_user can handle my problem? When I use
it to change CS, this function returns the correct number of bytes (and no
error) but, when I try to read... the old data is still there. I suppose
there is a page/segment protection against writing to CS, isn't it?
Luis Henriques
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: copy to user
2001-11-20 20:54 Luis Miguel Correia Henriques
@ 2001-11-20 21:28 ` John Alvord
2001-11-20 21:44 ` Andreas Dilger
` (3 subsequent siblings)
4 siblings, 0 replies; 24+ messages in thread
From: John Alvord @ 2001-11-20 21:28 UTC (permalink / raw)
To: Luis Miguel Correia Henriques; +Cc: linux-kernel
On Tue, 20 Nov 2001 20:54:42 +0000 (WET), Luis Miguel Correia
Henriques <umiguel@alunos.deis.isec.pt> wrote:
>The reason that I need it to spend CPU time is that I'm developing a fault
>injector. The purpose of a fault injection tool is, as you could imagine,
>to test some critical systems and it's capacity to recover from fails. The
>reason for changing the code of a process is that process must be delayed
>but without leaving the CPU - everything must look like nothing wrong is
>happening, except for other processes that are waiting for something from
>the delayed process...
>
>Maybe I should have explained this before... sorry.
>
>I suppose now you can understand why SIGSTOP won't work. Hope you can help
>me :)
>
>About using udelay... this soluction seemed fine to me at first but if I
>hang the CPU with udelay the scheduler will no be doing it's job (isn't
>it?). This would give me even more intrusiveness (another requirement: the
>less intrusiveness as possible).
>
>Isn't there any doubt that copy_to_user can handle my problem? When I use
>it to change CS, this function returns the correct number of bytes (and no
>error) but, when I try to read... the old data is still there. I suppose
>there is a page/segment protection against writing to CS, isn't it?
Maybe the kernel logic could lock the relevent page so it couldn't be
paged out...
john alvord
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: copy to user
2001-11-20 20:54 Luis Miguel Correia Henriques
2001-11-20 21:28 ` John Alvord
@ 2001-11-20 21:44 ` Andreas Dilger
2001-11-21 11:02 ` Luís Henriques
2001-11-20 22:02 ` n0ano
` (2 subsequent siblings)
4 siblings, 1 reply; 24+ messages in thread
From: Andreas Dilger @ 2001-11-20 21:44 UTC (permalink / raw)
To: Luis Miguel Correia Henriques; +Cc: linux-kernel
On Nov 20, 2001 20:54 +0000, Luis Miguel Correia Henriques wrote:
> The reason that I need it to spend CPU time is that I'm developing a fault
> injector. The purpose of a fault injection tool is, as you could imagine,
> to test some critical systems and it's capacity to recover from fails. The
> reason for changing the code of a process is that process must be delayed
> but without leaving the CPU - everything must look like nothing wrong is
> happening, except for other processes that are waiting for something from
> the delayed process...
>
> I suppose now you can understand why SIGSTOP won't work.
If you put the process in (un)interruptible sleep in the kernel, won't this
be enough? This is different than SIGSTOP. Is the requirement that this
process not leave the kernel call, or that it is actually consuming CPU
cycles as well?
> About using udelay... this soluction seemed fine to me at first but if I
> hang the CPU with udelay the scheduler will no be doing it's job (isn't
> it?). This would give me even more intrusiveness (another requirement: the
> less intrusiveness as possible).
It would probably work OK on an SMP system, since tasks can still be run
on the other CPU.
Cheers, Andreas
--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://www-mddsp.enel.ucalgary.ca/People/adilger/
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: copy to user
2001-11-20 21:44 ` Andreas Dilger
@ 2001-11-21 11:02 ` Luís Henriques
0 siblings, 0 replies; 24+ messages in thread
From: Luís Henriques @ 2001-11-21 11:02 UTC (permalink / raw)
To: Andreas Dilger; +Cc: linux-kernel
> If you put the process in (un)interruptible sleep in the kernel, won't this
> be enough? This is different than SIGSTOP. Is the requirement that this
> process not leave the kernel call, or that it is actually consuming CPU
> cycles as well?
The process needs to be using CPU time, however, there must be a chance to
the scheduler to change the current process... if this occurs, than the delay
has to be aborted.
>
> > About using udelay... this soluction seemed fine to me at first but if I
> > hang the CPU with udelay the scheduler will no be doing it's job (isn't
> > it?). This would give me even more intrusiveness (another requirement:
> > the less intrusiveness as possible).
>
> It would probably work OK on an SMP system, since tasks can still be run
> on the other CPU.
>
> Cheers, Andreas
--
Luís Henriques
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: copy to user
2001-11-20 20:54 Luis Miguel Correia Henriques
2001-11-20 21:28 ` John Alvord
2001-11-20 21:44 ` Andreas Dilger
@ 2001-11-20 22:02 ` n0ano
2001-11-20 22:05 ` Chris Wright
2001-11-21 8:43 ` Mathijs Mohlmann
4 siblings, 0 replies; 24+ messages in thread
From: n0ano @ 2001-11-20 22:02 UTC (permalink / raw)
To: Luis Miguel Correia Henriques; +Cc: linux-kernel
Ignoring the merits of what you are trying to do why don't you put your
new code on the target's stack? This avoids all of the problems associated
with changing the code section (which is doable but tricky, after all if
`gdb' can change the code section you certainly could).
On Tue, Nov 20, 2001 at 08:54:42PM +0000, Luis Miguel Correia Henriques wrote:
> The reason that I need it to spend CPU time is that I'm developing a fault
> injector. The purpose of a fault injection tool is, as you could imagine,
> to test some critical systems and it's capacity to recover from fails. The
> reason for changing the code of a process is that process must be delayed
> but without leaving the CPU - everything must look like nothing wrong is
> happening, except for other processes that are waiting for something from
> the delayed process...
>
> Maybe I should have explained this before... sorry.
>
> I suppose now you can understand why SIGSTOP won't work. Hope you can help
> me :)
>
> About using udelay... this soluction seemed fine to me at first but if I
> hang the CPU with udelay the scheduler will no be doing it's job (isn't
> it?). This would give me even more intrusiveness (another requirement: the
> less intrusiveness as possible).
>
> Isn't there any doubt that copy_to_user can handle my problem? When I use
> it to change CS, this function returns the correct number of bytes (and no
> error) but, when I try to read... the old data is still there. I suppose
> there is a page/segment protection against writing to CS, isn't it?
>
> Luis Henriques
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
Don Dugger
"Censeo Toto nos in Kansa esse decisse." - D. Gale
n0ano@indstorage.com
Ph: 303/652-0870x117
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: copy to user
2001-11-20 20:54 Luis Miguel Correia Henriques
` (2 preceding siblings ...)
2001-11-20 22:02 ` n0ano
@ 2001-11-20 22:05 ` Chris Wright
2001-11-21 8:43 ` Mathijs Mohlmann
4 siblings, 0 replies; 24+ messages in thread
From: Chris Wright @ 2001-11-20 22:05 UTC (permalink / raw)
To: Luis Miguel Correia Henriques; +Cc: linux-kernel
* Luis Miguel Correia Henriques (umiguel@alunos.deis.isec.pt) wrote:
> The reason that I need it to spend CPU time is that I'm developing a fault
> injector. The purpose of a fault injection tool is, as you could imagine,
> to test some critical systems and it's capacity to recover from fails. The
> reason for changing the code of a process is that process must be delayed
> but without leaving the CPU - everything must look like nothing wrong is
> happening, except for other processes that are waiting for something from
> the delayed process...
with ptrace(2) you can write into the program's .bss, whatever...add a
little shellcode and you're dangerous ;-)
-chris
^ permalink raw reply [flat|nested] 24+ messages in thread* RE: copy to user
2001-11-20 20:54 Luis Miguel Correia Henriques
` (3 preceding siblings ...)
2001-11-20 22:05 ` Chris Wright
@ 2001-11-21 8:43 ` Mathijs Mohlmann
2001-11-21 10:12 ` Jan Hudec
4 siblings, 1 reply; 24+ messages in thread
From: Mathijs Mohlmann @ 2001-11-21 8:43 UTC (permalink / raw)
To: Luis Miguel Correia Henriques; +Cc: linux-kernel
On 20-Nov-2001 Luis Miguel Correia Henriques wrote:
> I suppose now you can understand why SIGSTOP won't work. Hope you can help
> me :)
how about making a signal handler for SIGUSR1 that checks a global variable and
loops. an other signal handler for SIGUSR2 to clear the variable so the SIGUSR1
handler can exit.
All in user space. (to delay execution kill -USR1 $pid, to continue: kill -USR2
$pid)
me
--
me
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: copy to user
2001-11-21 8:43 ` Mathijs Mohlmann
@ 2001-11-21 10:12 ` Jan Hudec
0 siblings, 0 replies; 24+ messages in thread
From: Jan Hudec @ 2001-11-21 10:12 UTC (permalink / raw)
To: linux-kernel
> > I suppose now you can understand why SIGSTOP won't work. Hope you can help
> > me :)
>
> how about making a signal handler for SIGUSR1 that checks a global variable and
> loops. an other signal handler for SIGUSR2 to clear the variable so the SIGUSR1
> handler can exit.
>
> All in user space. (to delay execution kill -USR1 $pid, to continue: kill -USR2
> $pid)
The same is possible within the kernel too! Add default handler to some
unused signals (there are more user-defineable signals than SIGUSR[12]
and noone cares to install handler for them) to do the loop in kernel.
Just make sure, that you call shedule() from time to time in that loop,
because in kernel you can't be preempted as you would in user-space.
--------------------------------------------------------------------------------
- Jan Hudec `Bulb' <bulb@ucw.cz>
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2010-12-26 1:33 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-23 0:59 copy_to_user Hemanth Kumar
2010-12-23 1:18 ` copy_to_user Dexter Haslem
2010-12-23 2:15 ` copy_to_user Hemanth Kumar
2010-12-23 4:35 ` copy_to_user Srinivas G.
2010-12-23 5:18 ` copy_to_user Hemanth Kumar
2010-12-23 5:37 ` copy_to_user mukti jain
2010-12-23 12:21 ` copy_to_user Hemanth Kumar
2010-12-24 6:07 ` copy_to_user Hemanth Kumar
2010-12-24 7:59 ` copy_to_user Nilesh Tayade
2010-12-24 9:00 ` copy_to_user Dave Hylands
2010-12-24 9:20 ` copy_to_user Nilesh Tayade
2010-12-24 10:00 ` copy_to_user Hemanth Kumar
2010-12-24 9:26 ` copy_to_user Hemanth Kumar
[not found] <589679.60204.qm@web94707.mail.in2.yahoo.com>
2010-12-24 18:31 ` copy_to_user Mulyadi Santosa
2010-12-26 1:33 ` copy_to_user Hemanth Kumar
-- strict thread matches above, loose matches on Subject: below --
2001-11-25 21:58 copy to user Marco C. Mason
2001-11-20 20:54 Luis Miguel Correia Henriques
2001-11-20 21:28 ` John Alvord
2001-11-20 21:44 ` Andreas Dilger
2001-11-21 11:02 ` Luís Henriques
2001-11-20 22:02 ` n0ano
2001-11-20 22:05 ` Chris Wright
2001-11-21 8:43 ` Mathijs Mohlmann
2001-11-21 10:12 ` Jan Hudec
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.