atomicity and alignment of data in memory

A data item is aligned in memory when its address is a multiple of its size in bytes. For instance, the address of an aligned short integer must be a multiple of two while the address of an aligned integer must be a multiple of four.
Why is it important to know about alignment ?
Assembly language [...]

fork and vfork

quick question: what’s the difference between fork() and vfork() system calls ?
quick answer: vfork() system call creates a process that shares the memory address space of its parent.
details:
fork() is implemented by linux as a clone() system call whose flags parameter specifies both a SIGCHLD signal and all the clone flags cleared and whose child_stack parameter [...]

difference between jmp and far jmp

a quick question in interviews: what is the difference between jmp and far jmp ?
a quick answer: far jmp modified both CS and EIP while jmp modifies only EIP.

verifying user space addresses in kernel

We can verify a user space address while executing in kernel by using the following function
int access_ok(int type, const void *addr, unsigned long size);
Defined in <asm/uaccess.h>, this function returns 1 if the address addr is a user space address and 0 if its a kernel space address (talking of the virtual address of course). argument [...]

Slab Poisoning

Slab Poisoning is a term popular among linux kernel hackers and refers to the condition caused by using an uninitialized dynamically allocated memory location, mostly a panic (or oops).
How to find if you have a slab poisoning ?
If you have an offending address 0xa5a5a5a5 somewhere in the kernel oops message, you can be almost be [...]

Sleep/Wakeup and Linux kernel threads

As a part of understanding the scheduling of kernel thread in linux, I wrote following module code.
#include <linux/module.h>
#include <linux/kernel.h>
#define DBG_FN_ENTRY()  \
do { \
printk(KERN_INFO “Inside function [ %s ]\n”, \
__FUNCTION__); \
} while(0)
struct task_struct *sleeping_task = NULL;
int k = 0;
int func(void *s)
{
int i;
for(i=0;i<20;i++) {
printk(“[%d][%s]\n”, i, (char *)s);
if(sleeping_task)
wake_up_process(sleeping_task);
if(i==10) {
sleeping_task = current;
set_current_state(TASK_INTERRUPTIBLE);
schedule();
}
}
}
int init_module(void)
{
DBG_FN_ENTRY();
kernel_thread(func, (void *)”first”, 0);
kernel_thread(func, (void *)”second”, 0);
return [...]