Inline Assembly
Introduction to Inline Assembly
Example of speed with Inline Assembly
x86_64 Registers
GCC Basic Assembly Example
GCC Assembly Syntax
Extended Format
Output operand
Constraint string
Example of extended assembly
Example of extended assembly 2
What if i only have input operands
Debugging Inline assembly using gdb
Inline assembly example for add,sub,mul and div
Inline assembly example for accessing memory
Immediate integer operand
Example of immediate integer operand
Example of printing stack pointer
Matching constraints
Clobberring
Example of cloberring
Special specifiers in clobbering section
Immediate I
More constraints
More Example of Inline Assembly
Linux Kernel Inline Assembly Examples
Implementation of enable and disable interrupt
Implementation of irqs_disabled()
Implementation of saving and restore flags
Can we read EFLAGS register from userspace
Can we enable disable interrupts from userspace
Will cli disable interrupts on other processors
Halt Instruction
Instructions for accessing I/O Ports
iopl
What happens to flag register when we call iopl
Enabling and disabling interrupts from userspace
Atomic operations
Atomic Increment and decrement
Example and solution of race condition
Locking technique for multiple instructions
CPUID
Processor Info and Feature bits
Reading Timestamp counter
Control Register 0
Control Registers in Oops
MSR
CPU_RELAX
Introduction to System Calls
What is System call
What happens inside a system call
Why do we need system calls
Current Privilege Level
Difference between system call and function call
System call number and system call table
Passing Parameters
int $0x80
entry_INT80_32
Example of int $0x80
Problem with int $0x80
Fast System calls
Sysenter and sysexit
kernel_vsyscall
ELF Auxiliary Vectors
kernel_vsyscall from inline assembly
64-bit fast system calls
dump_stack in module init
syscall instruction from inline assembly
How system call is executed in other architectures
Return value of system call
syscall library function
What happens when we pass a system call number which is not implemented
VDSO
Introduction to VDSO
Example of VDSO
strace on vdso
Where is linux-vdso.so present
vsyscalls
Adding a new system call
SYSCALL_DEFINEn
Example of SYSCALL_DEFINEn
asmlinkage
How userspace reaches sys_read
Adding a new system call
Return value of system calls
Adding a system call accepting argument
What happens if i pass a different type of argument
Generic System call table
What happens when we compile user space app for 32 bit
How is ia32_sys_hello map to x64_sys_hello
System call Table
Compatibility System calls
Kernel Symbols
Kernel Symbols and Kernel Symbol table
How do you find out whether a function is static or global
A peek inside LKM
kallsyms_lookup_name
Dynamically find the address at which the kernel is loaded
kallsyms_on_each_symbol
Finding the size of kernel function
Use function pointer returned by kallsysms_lookup_name
Can we access non exported symbols
Can we update symbol address
Updating system call table
Access the parameters passed to system call