Get the App
SLTechnology News&Howtos  ›  Servers  › 

Create kernel character module and oops information understanding

Shulou Source: shulou.com Published: 2022-06-03 09:26:31 10月04日 Update

Simply record the positioning steps of the Linux Oops. First create a demo, this demo is to create a character device demo.

First, create the code of demo module

# include # define MINOR_BASE 0#define COUNT_NUM 3static struct cdev * cdevp = NULL;static dev_t dev;struct class * demo_class = NULL;struct device * drv_device;int demo_open (struct inode * node, struct file * filp) {printk (KERN_INFO "% s% d demo_open called...\ n", _ _ func__,__LINE__); int * p = NULL;*p = 1; / * null pointer assignment * / return 0 } int demo_release (struct inode * node, struct file * filp) {printk (KERN_INFO "% s% d demo_release called...\ n", _ _ func__,__LINE__); return 0;} ssize_t demo_read (struct file * filep, char _ _ user * user, size_t size, loff_t * loffp) {printk (KERN_INFO "% s% d demo_read called...\ n", _ _ func__,__LINE__); return 0 } ssize_t demo_write (struct file * filep, const char _ user * user, size_t size, loff_t * loffp) {printk (KERN_INFO "% s% d demo_write called...\ n", _ _ func__,__LINE__); return size;} struct file_operations opfp = {.owner = THIS_MODULE, .open = demo_open, .release = demo_release, .read = demo_read, .write = demo_write,} Static int _ init demo_init (void) {int ret; / / dev_t ret = alloc_chrdev_region (& dev,MINOR_BASE,COUNT_NUM, "cdev_demo"); if (ret

Tags: Module error pointer code function that is information command method target analysis query character no position just address instruction point format Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple vpn Microsoft Linux Huawei