Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Create kernel character module and oops information understanding

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report