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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
28
Designers e Programadores em um projeto ágil
diegor2
0
27
Prime quest
diegor2
0
28
Jogos Interativos como Ferramenta para Reconhecimento de Números Primos
diegor2
0
30
Open VSwitch on Android
diegor2
0
120
Other Decks in Programming
See All in Programming
DevinとClaude Code、SREの現場で使い倒してみた件
karia
1
1.1k
Ruby and LLM Ecosystem 2nd
koic
1
1.2k
コードレビューをしない選択 #でぃーぷらすトウキョウ
kajitack
3
1k
米国のサイバーセキュリティタイムラインと見る Goの暗号パッケージの進化
tomtwinkle
2
620
Claude Code Skill入門
mayahoney
0
410
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
190
S3ストレージクラスの「見える」「ある」「使える」は全部違う ─ 体験から見た、仕様の深淵を覗く
ya_ma23
0
800
Codex の「自走力」を高める
yorifuji
0
1.3k
AI活用のコスパを最大化する方法
ochtum
0
250
Claude Codeセッション現状確認 2026福岡 / fukuoka-aicoding-00-beacon
monochromegane
4
440
CSC307 Lecture 15
javiergs
PRO
0
260
守る「だけ」の優しいEMを抜けて、 事業とチームを両方見る視点を身につけた話
maroon8021
3
1.1k
Featured
See All Featured
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
64
53k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
240
Un-Boring Meetings
codingconduct
0
230
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Everyday Curiosity
cassininazir
0
170
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
780
Building Applications with DynamoDB
mza
96
7k
The Cult of Friendly URLs
andyhume
79
6.8k
4 Signs Your Business is Dying
shpigford
187
22k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
240
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
Claude Code のすすめ
schroneko
67
220k
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