lkml.org 
[lkml]   [2004]   [Apr]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectvfree in timerfunciton causes kernel crash
Hi

Idea: a module allocates memory (vmalloc) for userspace program which
then craches.
Due to lack of activity timer is expires and free's the unused memory
(vfree).
(see tc_core.c later in this mail for details)

Problem: when timer expires and vfree is called then kernel crashes -
or rather freezes silently.

Can anyone explain why this happens? a kernel bug?

Cheers
Mikkel

kernel 2.6.5

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/spinlock.h>
#include <linux/vmalloc.h>
#include <linux/timer.h>
#include <linux/sched.h>

#define MODULE_NAME "tf"

#ifdef __KERNEL__

int *buf;
struct timer_list timer;

static void timeoutfun(unsigned long b) {
printk("tf: timeoutfun\n");
vfree(buf);
}

struct timer_list timer;

int __init init_tf(void)
{
printk("init_tf\n");
buf = vmalloc(10*sizeof(int));

init_timer(&timer); /* Initialization of the timer */

timer.function = &timeoutfun;
timer.data = 10;
timer.expires = jiffies + (10 * HZ); /* 1 sec */

add_timer(&timer);

return 0;
}


void __exit exit_tf(void)
{
printk("exit_tf\n");
vfree(buf);
}


module_init(init_tf);
module_exit(exit_tf);
MODULE_LICENSE("GPL");


#endif
KERNEL_SOURCE = /home/mixxel/pack/linux-2.6.4
PWD = `pwd`
obj-m := tf.o

tf-objs := tf_core.o

default:
make -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules

clean:
rm *.{o,ko} .*.cmd
\
 
 \ /
  Last update: 2005-03-22 14:02    [W:0.333 / U:0.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site