Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Primeiro módulo de kernel
Search
Diego Ramos Ruggeri
May 16, 2014
Programming
0
24
Primeiro módulo de kernel
Diego Ramos Ruggeri
May 16, 2014
Tweet
Share
More Decks by Diego Ramos Ruggeri
See All by Diego Ramos Ruggeri
Exploiting process variability in voltage frequency control
diegor2
0
28
Energy profiler for android emulator
diegor2
0
27
Clamber network
diegor2
0
23
Designers e Programadores em um projeto ágil
diegor2
0
20
Prime quest
diegor2
0
20
Jogos Interativos como Ferramenta para Reconhecimento de Números Primos
diegor2
0
22
Open VSwitch on Android
diegor2
0
110
Other Decks in Programming
See All in Programming
初心者のためのRubyKaigi入門/RubyKaigi Introduction
a_matsuda
10
1.4k
障害対応を起点としたもっといい開発と運用のサイクル作りのためにできること / Hatena Enginner Seminar #29
polamjag
0
380
見た目から始める生産性向上
ikumatadokoro
10
1.4k
デフォルトにして至高、RubyMineの大好きな所
ruzia
0
760
Site Reliability Engineering for GMO
pyama86
8
1.1k
Tailwind CSSを本気でカスタマイズする方法
fsubal
14
5.5k
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
310
Let's learn code review
riofujimon
2
570
雑に思考を整理する技術と効能
konifar
63
30k
Git Lint
bkuhlmann
4
760
禅の心を手に入れよ
eltociear
1
330
CDKコントリビュートの最初の壁を越えよう! -簡単issueの見つけ方-
badmintoncryer
3
210
Featured
See All Featured
Pencils Down: Stop Designing & Start Developing
hursman
117
11k
A Philosophy of Restraint
colly
197
16k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
188
16k
Designing the Hi-DPI Web
ddemaree
276
33k
Scaling GitHub
holman
457
140k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
126
32k
What's new in Ruby 2.0
geeforr
337
31k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Fashionably flexible responsive web design (full day workshop)
malarkey
398
65k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
13
8.3k
How to Ace a Technical Interview
jacobian
273
22k
Being A Developer After 40
akosma
66
580k
Transcript
Escreva seu primeiro MÓDULO DE KERNEL (LINUX)
Em quatro atos • Hello World! • Character driver •
Miscellaneous driver • Ramdisk
0 – Hello World • Olá mundo! • Diego Ramos
Ruggeri • http://vai.la/62u3
0 – Hello World • Linux é monolítico • Módulos
carregados em tempo de execução • Ciclo de vida • Básico: Inicializar e Limpar
0 – Hello World Porque? • Hardware livre • Entender
o Linux • OOP em C • Projeto de software livre
static int __init hello_module(void) { printk(KERN_INFO "Hello World!\n"); return 0;
} static void __exit goodbye_module(void) { printk(KERN_INFO "Adios\n"); } module_init(hello_module); module_exit(goodbye_module); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Diego Ruggeri"); MODULE_DESCRIPTION("Hello World module");
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
0 – Hello World • modinfo • insmod • lsmod
• rmmod • dmesg
1 – Char Dev • ioctls • net • /dev
• /sys • /dev • Block device • Character device • Major Minor
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); }
2 – Misc Dev • mknod /dev/fisl15 c $MAJOR $MINOR
• udev • Miscellaneous API
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); }
3 - Ramdisk • Char device + • Misc api
+ • Aloca memória (slab) + • open, close, read, write
static int __init hello_module(void) { disk = (char*) kzalloc(DISK_SIZE *
sizeof(char), GFP_KERNEL); /*…*/ } static void __exit goodbye_module(void) { kfree(disk); /*...*/ }
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) }
Obrigado
[email protected]
http://github.com/diegor2