Your SlideShare is downloading. ×
Primeiro módulo de kernel
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Primeiro módulo de kernel

130
views

Published on

Escrevendo seu primeiro módulo de kernel (Linux)

Escrevendo seu primeiro módulo de kernel (Linux)

Published in: Technology

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
130
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Escreva seu primeiro MÓDULO DE KERNEL (LINUX)
  • 2. Em quatro atos ● Hello World! ● Character driver ● Miscellaneous driver ● Ramdisk
  • 3. 0 – Hello World ● Olá mundo! ● Diego Ramos Ruggeri ● http://vai.la/62u3
  • 4. 0 – Hello World ● Linux é monolítico ● Módulos carregados em tempo de execução ● Ciclo de vida ● Básico: Inicializar e Limpar
  • 5. 0 – Hello World Porque? ● Hardware livre ● Entender o Linux ● OOP em C ● Projeto de software livre
  • 6. static int __init hello_module(void) { printk(KERN_INFO "Hello World!n"); return 0; } static void __exit goodbye_module(void) { printk(KERN_INFO "Adiosn"); } module_init(hello_module); module_exit(goodbye_module); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Diego Ruggeri"); MODULE_DESCRIPTION("Hello World module");
  • 7. 0 – Hello World obj-m += hello.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
  • 8. 0 – Hello World ● modinfo ● insmod ● lsmod ● rmmod ● dmesg
  • 9. 1 – Char Dev ● ioctls ● net ● /dev ● /sys ● /dev ● Block device ● Character device ● Major Minor
  • 10. static struct file_operations fops = { .read = device_read, .write = device_write, .open = device_open, .release = device_release }; static int __init hello_module(void) { major = register_chrdev(0, DEVICE, &fops); /* … */ } static void __exit goodbye_module(void) { unregister_chrdev(major, DEVICE); }
  • 11. 2 – Misc Dev ● mknod /dev/fisl15 c $MAJOR $MINOR ● udev ● Miscellaneous API
  • 12. static struct file_operations fops = { /*...*/ }; static struct miscdevice mdev = { .minor = MISC_DYNAMIC_MINOR, .name = DEVICE, .fops = &fops, }; static int __init hello_module(void) { misc_register(&mdev) /* … */ } static void __exit goodbye_module(void) { misc_deregister(&mdev); }
  • 13. 3 - Ramdisk ● Char device + ● Misc api + ● Aloca memória (slab) + ● open, close, read, write
  • 14. static int __init hello_module(void) { disk = (char*) kzalloc(DISK_SIZE * sizeof(char), GFP_KERNEL); /*…*/ } static void __exit goodbye_module(void) { kfree(disk); /*...*/ }
  • 15. static ssize_t device_read(struct file *filp, char *buffer, size_t length,loff_t * offset) { /*...*/ copy_to_user(buffer, message, len); /*...*/ } static ssize_t device_write(struct file *filp, const char *buff, size_t len, loff_t * off) { copy_from_user(disk, buff, len) }
  • 16. Obrigado diego@ruggeri.net.br http://github.com/diegor2