SlideShare a Scribd company logo
Linux Device Driver
Chapter 2
Anupam Datta
Advised Reading
LDD3 Chapter 2 : https://static.lwn.net/images/pdf/LDD3/ch02.pdf
Additional Contents :
Source codes - https://goo.gl/Nir7b2
Quick reference - https://goo.gl/UYBwQq
Outline : Kernel Module
➔ A hello_world program for kernel (source code available in folder).
➔ insmod and rmmod for load unload kernel.
➔ Segmentation fault kills process.
➔ Modules runs in kernel space and application in user space.
➔ Each space has their own memory mapping and address space.
➔ Processor protects from unauthorized access through protection levels.
➔ Kernel is executed under highest level ie. supervisor mode.
➔ For a system call UNIX transfers execution from user to kernel space
Outline : Kernel Module
➔ Written in a way to maintain concurrent action can happen.
➔ Kernel codes must be reentrant - Running in multiple context in same time.
➔ Avoid race condition in data structure which might have shared data.
Current process -
➔ current is not truly global variable. For supporting SMP developer developed
this to find current process in relevant processor.
➔ The pointer refers to struct task_struct which refers process currently
executing.
Outline : Kernel Module
➔ Smaller stack size, as small as 4096 byte.
➔ DO NOT allocate large auto variable, instead use dynamic memory allocation.
➔ Functions with __ as start of name must be handled with care as these are
low level interface.
➔ No floating point arithmetic as it needs to save floating point state in
processor at each entry and exit. So extra overhead.
➔ modprobe searches for other symbols from any other modules and loads,
whereas insmod may fail with unresolved symbols.
➔ lsmod reads /proc/modules to list loaded modules.
➔ sysfs /sys/module shows same (both virtual filesystem).
Outline : Kernel Module
➔ Module build steps has version verification by linking vermagic.o with
module. If things doesn’t match, module won’t be loaded.
➔ /var/log/messages shows problem logs.
➔ To build kernel for multiple version, use macros.ie.LINUX_VERSION_CODE,
KERNEL_VERSION(major,minor,release).
➔ Deal incompatibilities with specific header file.
➔ Kernel symbol table contains global symbol and functions.
➔ Driver module exports symbol to table for other modules to benefit (Module
Stacking).
Outline : Kernel Module
➔ Initialization functions are declared as static as it should not be visible
outside specific file.
➔ Module can register many facilities and each facility a specific kernel function
accomplish the registration.
➔ Arguments passed to registration functions is pointer that points to data
structure containing details of facility.
➔ Cleanup function is declared as void as it has nothing to return.
Module : Error Handling
➔ For an error a module must perform an undo of all the things that it did before
failure. Linux doesn’t save these activities hence a module must implement
this.
➔ goto is used for error handling. For complex situations, run cleanup function
from within initialization function.
➔ Must check of status of each item before unregistering and clean-up function
can not have __exit when called from non-exit function.
➔ Module load race - Module must complete all supporting initialization before
enabling all facilities.
Module Parameter
➔ Parameter can be taken in load time by insmod or from /etc/modprobe.conf
by modprobe
➔ Parameters are declared with the module_param macro, defined in
moduleparam.h.
➔ Macros are placed outside function and found near the head of source file.
➔ All module params should be given a default value.
➔ User-space driver can be implemented although it has pros and cons.

More Related Content

What's hot

Threads
ThreadsThreads
Threads
Shivam Singh
 
Cache coherence
Cache coherenceCache coherence
Cache coherence
Employee
 
Thread management
Thread management Thread management
Thread management
Ayaan Adeel
 
Os Threads
Os ThreadsOs Threads
Os Threads
Salman Memon
 
Processes and Threads in Windows Vista
Processes and Threads in Windows VistaProcesses and Threads in Windows Vista
Processes and Threads in Windows Vista
Trinh Phuc Tho
 
Multithreading computer architecture
 Multithreading computer architecture  Multithreading computer architecture
Multithreading computer architecture
Haris456
 
Lecutur24 25
Lecutur24 25Lecutur24 25
Lecutur24 25
Gaurang Pachani
 
StartUpOpen 2011 - Projekat13
StartUpOpen 2011 - Projekat13StartUpOpen 2011 - Projekat13
StartUpOpen 2011 - Projekat13
BlogOpen
 
Cache coherence
Cache coherenceCache coherence
Cache coherence
Shyam Krishna Khadka
 
10 Multicore 07
10 Multicore 0710 Multicore 07
10 Multicore 07
timcrack
 
Browsing Linux Kernel Source
Browsing Linux Kernel SourceBrowsing Linux Kernel Source
Browsing Linux Kernel Source
Motaz Saad
 
Os Linux
Os LinuxOs Linux
Comparison of Amoeba, Mach & Chorus: DOS
Comparison of Amoeba, Mach & Chorus: DOSComparison of Amoeba, Mach & Chorus: DOS
Comparison of Amoeba, Mach & Chorus: DOS
Er. Shiva K. Shrestha
 
Multi processing
Multi processingMulti processing
Multi processing
Muhammad Ishaq
 
Scheduler Activations - Effective Kernel Support for the User-Level Managemen...
Scheduler Activations - Effective Kernel Support for the User-Level Managemen...Scheduler Activations - Effective Kernel Support for the User-Level Managemen...
Scheduler Activations - Effective Kernel Support for the User-Level Managemen...
Kasun Gajasinghe
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
Harshith Meela
 
Application Performance & Flexibility on Exokernel Systems paper review
Application Performance & Flexibility on Exokernel Systems paper reviewApplication Performance & Flexibility on Exokernel Systems paper review
Application Performance & Flexibility on Exokernel Systems paper review
Vimukthi Wickramasinghe
 
Chorus - Distributed Operating System [ case study ]
Chorus - Distributed Operating System [ case study ]Chorus - Distributed Operating System [ case study ]
Chorus - Distributed Operating System [ case study ]
Akhil Nadh PC
 
The Windows Scheduler
The Windows SchedulerThe Windows Scheduler
The Windows Scheduler
Peter Shirley-Quirk
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor scheduling
Shashank Kapoor
 

What's hot (20)

Threads
ThreadsThreads
Threads
 
Cache coherence
Cache coherenceCache coherence
Cache coherence
 
Thread management
Thread management Thread management
Thread management
 
Os Threads
Os ThreadsOs Threads
Os Threads
 
Processes and Threads in Windows Vista
Processes and Threads in Windows VistaProcesses and Threads in Windows Vista
Processes and Threads in Windows Vista
 
Multithreading computer architecture
 Multithreading computer architecture  Multithreading computer architecture
Multithreading computer architecture
 
Lecutur24 25
Lecutur24 25Lecutur24 25
Lecutur24 25
 
StartUpOpen 2011 - Projekat13
StartUpOpen 2011 - Projekat13StartUpOpen 2011 - Projekat13
StartUpOpen 2011 - Projekat13
 
Cache coherence
Cache coherenceCache coherence
Cache coherence
 
10 Multicore 07
10 Multicore 0710 Multicore 07
10 Multicore 07
 
Browsing Linux Kernel Source
Browsing Linux Kernel SourceBrowsing Linux Kernel Source
Browsing Linux Kernel Source
 
Os Linux
Os LinuxOs Linux
Os Linux
 
Comparison of Amoeba, Mach & Chorus: DOS
Comparison of Amoeba, Mach & Chorus: DOSComparison of Amoeba, Mach & Chorus: DOS
Comparison of Amoeba, Mach & Chorus: DOS
 
Multi processing
Multi processingMulti processing
Multi processing
 
Scheduler Activations - Effective Kernel Support for the User-Level Managemen...
Scheduler Activations - Effective Kernel Support for the User-Level Managemen...Scheduler Activations - Effective Kernel Support for the User-Level Managemen...
Scheduler Activations - Effective Kernel Support for the User-Level Managemen...
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
 
Application Performance & Flexibility on Exokernel Systems paper review
Application Performance & Flexibility on Exokernel Systems paper reviewApplication Performance & Flexibility on Exokernel Systems paper review
Application Performance & Flexibility on Exokernel Systems paper review
 
Chorus - Distributed Operating System [ case study ]
Chorus - Distributed Operating System [ case study ]Chorus - Distributed Operating System [ case study ]
Chorus - Distributed Operating System [ case study ]
 
The Windows Scheduler
The Windows SchedulerThe Windows Scheduler
The Windows Scheduler
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor scheduling
 

Similar to Linux Device Driver v3 [Chapter 2]

Studienarb linux kernel-dev
Studienarb linux kernel-devStudienarb linux kernel-dev
Studienarb linux kernel-dev
murali_purushothaman
 
Linux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesungLinux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesung
dns -
 
Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel Programming
Nalin Sharma
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
Priyank Kapadia
 
DUSK - Develop at Userland Install into Kernel
DUSK - Develop at Userland Install into KernelDUSK - Develop at Userland Install into Kernel
DUSK - Develop at Userland Install into Kernel
Alexey Smirnov
 
Exploiting Llinux Environment
Exploiting Llinux EnvironmentExploiting Llinux Environment
Exploiting Llinux Environment
Enrico Scapin
 
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdfunixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
PRATIKSINHA7304
 
Readme
ReadmeReadme
Readme
rec2006
 
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B KuteUnit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Tushar B Kute
 
Apache Cassandra Lunch #41: Cassandra on Kubernetes - Docker/Kubernetes/Helm ...
Apache Cassandra Lunch #41: Cassandra on Kubernetes - Docker/Kubernetes/Helm ...Apache Cassandra Lunch #41: Cassandra on Kubernetes - Docker/Kubernetes/Helm ...
Apache Cassandra Lunch #41: Cassandra on Kubernetes - Docker/Kubernetes/Helm ...
Anant Corporation
 
Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned  Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned
RightScale
 
Lecture 5 Kernel Development
Lecture 5 Kernel DevelopmentLecture 5 Kernel Development
Lecture 5 Kernel Development
Mohammed Farrag
 
Kernel module programming
Kernel module programmingKernel module programming
Kernel module programming
Vandana Salve
 
Open Dayligth usando SDN-NFV
Open Dayligth usando SDN-NFVOpen Dayligth usando SDN-NFV
Open Dayligth usando SDN-NFV
Open Networking Perú (Opennetsoft)
 
Chapter 3 chapter reading task
Chapter 3 chapter reading taskChapter 3 chapter reading task
Chapter 3 chapter reading task
Grievous Humorist-Ilham
 
Introductiontoasp netwindbgdebugging-100506045407-phpapp01
Introductiontoasp netwindbgdebugging-100506045407-phpapp01Introductiontoasp netwindbgdebugging-100506045407-phpapp01
Introductiontoasp netwindbgdebugging-100506045407-phpapp01
Camilo Alvarez Rivera
 
Walking around linux kernel
Walking around linux kernelWalking around linux kernel
Walking around linux kernel
Dharshana Kasun Warusavitharana
 
Linux kernel code
Linux kernel codeLinux kernel code
Linux kernel code
Ganesh Naik
 
Java programming concept
Java programming conceptJava programming concept
Java programming concept
Sanjay Gunjal
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
dibyajyotig
 

Similar to Linux Device Driver v3 [Chapter 2] (20)

Studienarb linux kernel-dev
Studienarb linux kernel-devStudienarb linux kernel-dev
Studienarb linux kernel-dev
 
Linux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesungLinux kernel driver tutorial vorlesung
Linux kernel driver tutorial vorlesung
 
Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel Programming
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
 
DUSK - Develop at Userland Install into Kernel
DUSK - Develop at Userland Install into KernelDUSK - Develop at Userland Install into Kernel
DUSK - Develop at Userland Install into Kernel
 
Exploiting Llinux Environment
Exploiting Llinux EnvironmentExploiting Llinux Environment
Exploiting Llinux Environment
 
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdfunixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
 
Readme
ReadmeReadme
Readme
 
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B KuteUnit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
Unit 6 Operating System TEIT Savitribai Phule Pune University by Tushar B Kute
 
Apache Cassandra Lunch #41: Cassandra on Kubernetes - Docker/Kubernetes/Helm ...
Apache Cassandra Lunch #41: Cassandra on Kubernetes - Docker/Kubernetes/Helm ...Apache Cassandra Lunch #41: Cassandra on Kubernetes - Docker/Kubernetes/Helm ...
Apache Cassandra Lunch #41: Cassandra on Kubernetes - Docker/Kubernetes/Helm ...
 
Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned  Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned
 
Lecture 5 Kernel Development
Lecture 5 Kernel DevelopmentLecture 5 Kernel Development
Lecture 5 Kernel Development
 
Kernel module programming
Kernel module programmingKernel module programming
Kernel module programming
 
Open Dayligth usando SDN-NFV
Open Dayligth usando SDN-NFVOpen Dayligth usando SDN-NFV
Open Dayligth usando SDN-NFV
 
Chapter 3 chapter reading task
Chapter 3 chapter reading taskChapter 3 chapter reading task
Chapter 3 chapter reading task
 
Introductiontoasp netwindbgdebugging-100506045407-phpapp01
Introductiontoasp netwindbgdebugging-100506045407-phpapp01Introductiontoasp netwindbgdebugging-100506045407-phpapp01
Introductiontoasp netwindbgdebugging-100506045407-phpapp01
 
Walking around linux kernel
Walking around linux kernelWalking around linux kernel
Walking around linux kernel
 
Linux kernel code
Linux kernel codeLinux kernel code
Linux kernel code
 
Java programming concept
Java programming conceptJava programming concept
Java programming concept
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 

Recently uploaded

一比一原版(UQ文凭证书)昆士兰大学毕业证如何办理
一比一原版(UQ文凭证书)昆士兰大学毕业证如何办理一比一原版(UQ文凭证书)昆士兰大学毕业证如何办理
一比一原版(UQ文凭证书)昆士兰大学毕业证如何办理
xuqdabu
 
一比一原版(UOL文凭证书)利物浦大学毕业证如何办理
一比一原版(UOL文凭证书)利物浦大学毕业证如何办理一比一原版(UOL文凭证书)利物浦大学毕业证如何办理
一比一原版(UOL文凭证书)利物浦大学毕业证如何办理
eydeofo
 
一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
bttak
 
买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样
买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样
买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样
nvoyobt
 
一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理
一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理
一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理
bttak
 
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalRBuilding a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR
Peter Gallagher
 
按照学校原版(KCL文凭证书)伦敦国王学院毕业证快速办理
按照学校原版(KCL文凭证书)伦敦国王学院毕业证快速办理按照学校原版(KCL文凭证书)伦敦国王学院毕业证快速办理
按照学校原版(KCL文凭证书)伦敦国王学院毕业证快速办理
terpt4iu
 
一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理
一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理
一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理
byfazef
 
按照学校原版(SUT文凭证书)斯威本科技大学毕业证快速办理
按照学校原版(SUT文凭证书)斯威本科技大学毕业证快速办理按照学校原版(SUT文凭证书)斯威本科技大学毕业证快速办理
按照学校原版(SUT文凭证书)斯威本科技大学毕业证快速办理
1jtj7yul
 
按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理
按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理
按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理
yizxn4sx
 
按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理
按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理
按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理
6oo02s6l
 
按照学校原版(Adelaide文凭证书)阿德莱德大学毕业证快速办理
按照学校原版(Adelaide文凭证书)阿德莱德大学毕业证快速办理按照学校原版(Adelaide文凭证书)阿德莱德大学毕业证快速办理
按照学校原版(Adelaide文凭证书)阿德莱德大学毕业证快速办理
terpt4iu
 
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
bttak
 
欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】
欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】
欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】
hanniaarias53
 
按照学校原版(QU文凭证书)皇后大学毕业证快速办理
按照学校原版(QU文凭证书)皇后大学毕业证快速办理按照学校原版(QU文凭证书)皇后大学毕业证快速办理
按照学校原版(QU文凭证书)皇后大学毕业证快速办理
8db3cz8x
 
按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理
按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理
按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理
1jtj7yul
 
一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理
一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理
一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理
kuehcub
 
按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理
按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理
按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理
uwoso
 
按照学校原版(USD文凭证书)圣地亚哥大学毕业证快速办理
按照学校原版(USD文凭证书)圣地亚哥大学毕业证快速办理按照学校原版(USD文凭证书)圣地亚哥大学毕业证快速办理
按照学校原版(USD文凭证书)圣地亚哥大学毕业证快速办理
snfdnzl7
 
一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理
一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理
一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理
xuqdabu
 

Recently uploaded (20)

一比一原版(UQ文凭证书)昆士兰大学毕业证如何办理
一比一原版(UQ文凭证书)昆士兰大学毕业证如何办理一比一原版(UQ文凭证书)昆士兰大学毕业证如何办理
一比一原版(UQ文凭证书)昆士兰大学毕业证如何办理
 
一比一原版(UOL文凭证书)利物浦大学毕业证如何办理
一比一原版(UOL文凭证书)利物浦大学毕业证如何办理一比一原版(UOL文凭证书)利物浦大学毕业证如何办理
一比一原版(UOL文凭证书)利物浦大学毕业证如何办理
 
一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版不列颠哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
 
买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样
买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样
买(usyd毕业证书)澳洲悉尼大学毕业证研究生文凭证书原版一模一样
 
一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理
一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理
一比一原版西三一大学毕业证(TWU毕业证书)学历如何办理
 
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalRBuilding a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR
Building a Raspberry Pi Robot with Dot NET 8, Blazor and SignalR
 
按照学校原版(KCL文凭证书)伦敦国王学院毕业证快速办理
按照学校原版(KCL文凭证书)伦敦国王学院毕业证快速办理按照学校原版(KCL文凭证书)伦敦国王学院毕业证快速办理
按照学校原版(KCL文凭证书)伦敦国王学院毕业证快速办理
 
一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理
一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理
一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理
 
按照学校原版(SUT文凭证书)斯威本科技大学毕业证快速办理
按照学校原版(SUT文凭证书)斯威本科技大学毕业证快速办理按照学校原版(SUT文凭证书)斯威本科技大学毕业证快速办理
按照学校原版(SUT文凭证书)斯威本科技大学毕业证快速办理
 
按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理
按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理
按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理
 
按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理
按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理
按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理
 
按照学校原版(Adelaide文凭证书)阿德莱德大学毕业证快速办理
按照学校原版(Adelaide文凭证书)阿德莱德大学毕业证快速办理按照学校原版(Adelaide文凭证书)阿德莱德大学毕业证快速办理
按照学校原版(Adelaide文凭证书)阿德莱德大学毕业证快速办理
 
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
一比一原版圣托马斯大学毕业证(UST毕业证书)学历如何办理
 
欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】
欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】
欧洲杯赌钱-欧洲杯赌钱冠军-欧洲杯赌钱冠军赔率|【​网址​🎉ac10.net🎉​】
 
按照学校原版(QU文凭证书)皇后大学毕业证快速办理
按照学校原版(QU文凭证书)皇后大学毕业证快速办理按照学校原版(QU文凭证书)皇后大学毕业证快速办理
按照学校原版(QU文凭证书)皇后大学毕业证快速办理
 
按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理
按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理
按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理
 
一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理
一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理
一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理
 
按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理
按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理
按照学校原版(UPenn文凭证书)宾夕法尼亚大学毕业证快速办理
 
按照学校原版(USD文凭证书)圣地亚哥大学毕业证快速办理
按照学校原版(USD文凭证书)圣地亚哥大学毕业证快速办理按照学校原版(USD文凭证书)圣地亚哥大学毕业证快速办理
按照学校原版(USD文凭证书)圣地亚哥大学毕业证快速办理
 
一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理
一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理
一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理
 

Linux Device Driver v3 [Chapter 2]

  • 2. Advised Reading LDD3 Chapter 2 : https://static.lwn.net/images/pdf/LDD3/ch02.pdf Additional Contents : Source codes - https://goo.gl/Nir7b2 Quick reference - https://goo.gl/UYBwQq
  • 3. Outline : Kernel Module ➔ A hello_world program for kernel (source code available in folder). ➔ insmod and rmmod for load unload kernel. ➔ Segmentation fault kills process. ➔ Modules runs in kernel space and application in user space. ➔ Each space has their own memory mapping and address space. ➔ Processor protects from unauthorized access through protection levels. ➔ Kernel is executed under highest level ie. supervisor mode. ➔ For a system call UNIX transfers execution from user to kernel space
  • 4. Outline : Kernel Module ➔ Written in a way to maintain concurrent action can happen. ➔ Kernel codes must be reentrant - Running in multiple context in same time. ➔ Avoid race condition in data structure which might have shared data. Current process - ➔ current is not truly global variable. For supporting SMP developer developed this to find current process in relevant processor. ➔ The pointer refers to struct task_struct which refers process currently executing.
  • 5. Outline : Kernel Module ➔ Smaller stack size, as small as 4096 byte. ➔ DO NOT allocate large auto variable, instead use dynamic memory allocation. ➔ Functions with __ as start of name must be handled with care as these are low level interface. ➔ No floating point arithmetic as it needs to save floating point state in processor at each entry and exit. So extra overhead. ➔ modprobe searches for other symbols from any other modules and loads, whereas insmod may fail with unresolved symbols. ➔ lsmod reads /proc/modules to list loaded modules. ➔ sysfs /sys/module shows same (both virtual filesystem).
  • 6. Outline : Kernel Module ➔ Module build steps has version verification by linking vermagic.o with module. If things doesn’t match, module won’t be loaded. ➔ /var/log/messages shows problem logs. ➔ To build kernel for multiple version, use macros.ie.LINUX_VERSION_CODE, KERNEL_VERSION(major,minor,release). ➔ Deal incompatibilities with specific header file. ➔ Kernel symbol table contains global symbol and functions. ➔ Driver module exports symbol to table for other modules to benefit (Module Stacking).
  • 7. Outline : Kernel Module ➔ Initialization functions are declared as static as it should not be visible outside specific file. ➔ Module can register many facilities and each facility a specific kernel function accomplish the registration. ➔ Arguments passed to registration functions is pointer that points to data structure containing details of facility. ➔ Cleanup function is declared as void as it has nothing to return.
  • 8. Module : Error Handling ➔ For an error a module must perform an undo of all the things that it did before failure. Linux doesn’t save these activities hence a module must implement this. ➔ goto is used for error handling. For complex situations, run cleanup function from within initialization function. ➔ Must check of status of each item before unregistering and clean-up function can not have __exit when called from non-exit function. ➔ Module load race - Module must complete all supporting initialization before enabling all facilities.
  • 9. Module Parameter ➔ Parameter can be taken in load time by insmod or from /etc/modprobe.conf by modprobe ➔ Parameters are declared with the module_param macro, defined in moduleparam.h. ➔ Macros are placed outside function and found near the head of source file. ➔ All module params should be given a default value. ➔ User-space driver can be implemented although it has pros and cons.