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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Diego Ramos Ruggeri
May 16, 2014
Programming
0
32
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
36
Energy profiler for android emulator
diegor2
0
39
Clamber network
diegor2
0
27
Designers e Programadores em um projeto ágil
diegor2
0
26
Prime quest
diegor2
0
28
Jogos Interativos como Ferramenta para Reconhecimento de Números Primos
diegor2
0
28
Open VSwitch on Android
diegor2
0
120
Other Decks in Programming
See All in Programming
Oxlint JS plugins
kazupon
1
850
CSC307 Lecture 03
javiergs
PRO
1
490
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
1
2.5k
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
7
3.8k
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
180
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
190
CSC307 Lecture 02
javiergs
PRO
1
770
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4.3k
「ブロックテーマでは再現できない」は本当か?
inc2734
0
920
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
1k
SourceGeneratorのススメ
htkym
0
190
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
160
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
135
9.7k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
120
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
180
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
110
The Curious Case for Waylosing
cassininazir
0
230
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.4k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
910
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
450
Large-scale JavaScript Application Architecture
addyosmani
515
110k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
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