Я пытаюсь применить некоторые примеры из книги LDD3. но мой модуль cra sh, когда я пишу на устройство, вызывающий процесс убит, cra sh вызывается из вызова wake_up_interruptible. Я использую ядро 5.3.0-42-generi c.
весь код: https://pastebin.com/aDiGDQTa
вот код:
ssize_t device_write(struct file* fd, const char __user* buf, size_t size,
loff_t* offset)
{
printk(KERN_INFO "MyLinuxModule: device is being written to, fd=%X.\n", fd);
struct device_info mydevice = charDevices[MINOR(fd->f_inode->i_rdev)];
if (*offset > DEVICE_BLOCK_SIZE) // reached Max size
{
return 0;
}
int true_len = min(size, DEVICE_BLOCK_SIZE - *offset);
if (mutex_lock_interruptible(&mydevice.my_mutex))
return -ERESTARTSYS;
copy_from_user(mydevice.data, buf, true_len);
mydevice.max_data_avaliable += true_len;
mutex_unlock(&mydevice.my_mutex);
printk(KERN_INFO "MyLinuxModule: my_queue=%X.\n", &mydevice.my_queue);
wake_up_interruptible(&mydevice.my_queue);
*offset += true_len;
return true_len;
}
int setup_cdevice(int index)
{
char* device_message = "Hello from the other side\n";
// initiate the cdev struct
cdev_init(&charDevices[index].chardev, &myfops);
// initiate the data
charDevices[index].data = kmalloc(DEVICE_BLOCK_SIZE, GFP_KERNEL);
memcpy(charDevices[index].data, device_message, strlen(device_message));
// initiate the semaphore & queue
mutex_init(&charDevices[index].my_mutex);
init_waitqueue_head(&charDevices[index].my_queue);
charDevices[index].max_data_avaliable = 0;
int err = cdev_add(&charDevices[index].chardev,
MKDEV(MAJOR(majMin), MINOR(majMin) + index), numOfDevices);
if (err) {
printk(KERN_INFO "MyLinuxModule: cdev_add Error : %X\n", err);
return -1;
}
return 0;
}
[ 8952.921117] BUG: kernel NULL pointer dereference, address: 0000000000000000
[ 8952.921119] #PF: supervisor instruction fetch in kernel mode
[ 8952.921120] #PF: error_code(0x0010) - not-present page
[ 8952.921121] PGD 0 P4D 0
[ 8952.921123] Oops: 0010 [#7] SMP PTI
[ 8952.921137] CPU: 3 PID: 14892 Comm: main Tainted: G D OE 5.3.0-42-generic #34~18.04.1-Ubuntu