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
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
4
250
Package Management Learnings from Homebrew
mikemcquaid
0
200
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
160
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
140
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
20
6.7k
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.8k
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
680
2026年 エンジニアリング自己学習法
yumechi
0
130
CSC307 Lecture 03
javiergs
PRO
1
490
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
62
A Tale of Four Properties
chriscoyier
162
24k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
ラッコキーワード サービス紹介資料
rakko
1
2.2M
KATA
mclloyd
PRO
34
15k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
750
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
55
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
320
Un-Boring Meetings
codingconduct
0
200
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
50
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
0
250
The Art of Programming - Codeland 2020
erikaheidi
57
14k
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