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
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
Architectural Extensions
denyspoltorak
0
280
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
990
AI時代の認知負荷との向き合い方
optfit
0
150
余白を設計しフロントエンド開発を 加速させる
tsukuha
7
2.1k
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
150
Patterns of Patterns
denyspoltorak
0
1.4k
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
AIエージェントのキホンから学ぶ「エージェンティックコーディング」実践入門
masahiro_nishimi
5
340
CSC307 Lecture 05
javiergs
PRO
0
500
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
200
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
370
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
Featured
See All Featured
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
170
Six Lessons from altMBA
skipperchong
29
4.1k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
98
YesSQL, Process and Tooling at Scale
rocio
174
15k
Accessibility Awareness
sabderemane
0
49
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
130
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
0
2.3k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
180
A better future with KSS
kneath
240
18k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
Raft: Consensus for Rubyists
vanstee
141
7.3k
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