Vortrag:Howto Linux-Kernel: Unterschied zwischen den Versionen
Aus k4cg.org
Noqqe (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „TODO ====== HOWTO Linux Kernel ====== === Meta === Datum: 20.11.08 20:00 Uhr Referent: Georg / gnu === Code === == Makefile == <code> obj-m += minDev.o obj-m…“) |
Noqqe (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
Zeile 1: | Zeile 1: | ||
== HOWTO Linux Kernel == | |||
=== Meta === | === Meta === | ||
Zeile 8: | Zeile 7: | ||
=== Code === | === Code === | ||
== Makefile == | == Makefile == | ||
< | |||
<pre> | |||
obj-m += minDev.o | obj-m += minDev.o | ||
obj-m += halloKernel.o | obj-m += halloKernel.o | ||
Zeile 18: | Zeile 18: | ||
clean: | clean: | ||
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean | make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean | ||
</ | </pre> | ||
== bad.c == | == bad.c == | ||
< | <pre> | ||
#include <linux/module.h> | #include <linux/module.h> | ||
#include <linux/mm.h> | #include <linux/mm.h> | ||
Zeile 53: | Zeile 53: | ||
MODULE_AUTHOR("gnu"); | MODULE_AUTHOR("gnu"); | ||
MODULE_LICENSE("GPL"); | MODULE_LICENSE("GPL"); | ||
</ | </pre> | ||
== halloKernel.c == | == halloKernel.c == | ||
< | <pre> | ||
#include <linux/module.h> | #include <linux/module.h> | ||
Zeile 72: | Zeile 72: | ||
MODULE_AUTHOR("gun"); | MODULE_AUTHOR("gun"); | ||
MODULE_LICENSE("GPL"); | MODULE_LICENSE("GPL"); | ||
</ | </pre> | ||
== minDev.c == | == minDev.c == | ||
< | <pre> | ||
#include <linux/module.h> | #include <linux/module.h> | ||
#include <linux/fs.h> | #include <linux/fs.h> | ||
Zeile 135: | Zeile 135: | ||
MODULE_AUTHOR("gnu"); | MODULE_AUTHOR("gnu"); | ||
MODULE_LICENSE("GPL"); | MODULE_LICENSE("GPL"); | ||
</ | </pre> | ||
== Links zum Workshop == | == Links zum Workshop == | ||
* Alle Links von http://www.linuxhq.com/lkprogram.html | |||
* Handbuch zur Linux Kernel-Entwicklung (organisatorisches) http://ldn.linuxfoundation.org/book/how-participate-linux-community |
Version vom 14. Mai 2015, 20:23 Uhr
HOWTO Linux Kernel
Meta
Datum: 20.11.08 20:00 Uhr Referent: Georg / gnu
Code
Makefile
obj-m += minDev.o obj-m += halloKernel.o obj-m += bad.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
bad.c
#include <linux/module.h> #include <linux/mm.h> int init_module ( void ) { int* badarray, *funcptr; int i; printk ("Bad Kernel Module\n"); badarray = (int*) kmalloc(100, GFP_KERNEL); if(!badarray) { printk(KERN_WARNING "no more memory :(\n"); return 0; } funcptr = (int*) &do_gettimeofday; printk("0x%08x do_gettimeofday\n", (int)funcptr); /* badarray = funcptr for(i=0; i<500; ++i) badarray[i] = 0xfea1dead; */ kfree(badarray); return 0; } void cleanup_module( void ) { printk ("Goodbye Kernel.\n"); } MODULE_AUTHOR("gnu"); MODULE_LICENSE("GPL");
halloKernel.c
#include <linux/module.h> int init_module ( void ) { printk ("Hello Kernel!\n"); return 0; } void cleanup_module( void ) { printk ("Goodbye Kernel.\n"); } MODULE_AUTHOR("gun"); MODULE_LICENSE("GPL");
minDev.c
#include <linux/module.h> #include <linux/fs.h> static int device_open(struct inode *inp, struct file *filp) { return 0; } static ssize_t device_read(struct file *filp, char *buf, size_t length, loff_t *f_pos) { return 0; } static ssize_t device_write(struct file *filp, const char *buf, size_t length, loff_t *f_pos) { printk( "received: %c%c\n",buf[0], buf[1]); return 2; } static int device_release(struct inode *inp, struct file *filp) { return 0; } static struct file_operations fops = { open: device_open, read: device_read, write: device_write, release: device_release }; ////////////////////////////////////////////////////////////// static int MajorNumber = 0; int init_module ( void ) { printk ("mindev loaded!\n"); MajorNumber = register_chrdev(0, "mydevice", &fops); if( MajorNumber < 0 ) { printk ("Registering mydevice failed.\n"); return MajorNumber; } else { printk ("create a device: 'mknod /dev/mydevice c %d 0'.\n",MajorNumber); } return 0; } void cleanup_module( void ) { unregister_chrdev(MajorNumber, "mydevice"); printk ("mindev unloaded.\n"); } MODULE_AUTHOR("gnu"); MODULE_LICENSE("GPL");
Links zum Workshop
- Alle Links von http://www.linuxhq.com/lkprogram.html
- Handbuch zur Linux Kernel-Entwicklung (organisatorisches) http://ldn.linuxfoundation.org/book/how-participate-linux-community