Things to keep in mind for kernel programming
If you want to hack Linux kernel and do some programs, before you start keep some points in mind First and very basic point to make you feel relax with linux kernel, as,
kernel is nothing but a program as like other programs, which includes memory management, process scheduling, system management and all you need to work in.
1. In kernel space you do not have leisure of GLIBc library, ie you can not use printf also you have printk in kernel space.
2. Limited stack - you have limited stack space in kernel so do not make unnecessary variables declared, as tomorrow you may be going to add some new features. In user space you have almost unlimited stack so you will be little worried about how many variables you are using.
3. In kernel space no memory protection is there, as in user space if some memory corruption occurs kernel will trap and send signal. In kernel space there is no-one to trap memory corruption, it is like you are directly accessing the actual bit of physical memory. you have to be careful for oops messages.
4. In kernel space avoid using floting point operations. Floting point operations requires storing and restoring of floting point registers. Same is true that do not use floting point operations in Interrupt handler (sometimes favorite question in interview.) .
5. Take care of synchronization
Linux being preemptive kernel meaning if one process is working on one resource and interrupt comes, control of execution is given to interrupt and if interrupt handler also works on same resource then race condition occurs.
one has to take care of race conditions using spinlocks and semaphors.
If you want to hack Linux kernel and do some programs, before you start keep some points in mind First and very basic point to make you feel relax with linux kernel, as,
kernel is nothing but a program as like other programs, which includes memory management, process scheduling, system management and all you need to work in.
1. In kernel space you do not have leisure of GLIBc library, ie you can not use printf also you have printk in kernel space.
2. Limited stack - you have limited stack space in kernel so do not make unnecessary variables declared, as tomorrow you may be going to add some new features. In user space you have almost unlimited stack so you will be little worried about how many variables you are using.
3. In kernel space no memory protection is there, as in user space if some memory corruption occurs kernel will trap and send signal. In kernel space there is no-one to trap memory corruption, it is like you are directly accessing the actual bit of physical memory. you have to be careful for oops messages.
4. In kernel space avoid using floting point operations. Floting point operations requires storing and restoring of floting point registers. Same is true that do not use floting point operations in Interrupt handler (sometimes favorite question in interview.) .
5. Take care of synchronization
Linux being preemptive kernel meaning if one process is working on one resource and interrupt comes, control of execution is given to interrupt and if interrupt handler also works on same resource then race condition occurs.
one has to take care of race conditions using spinlocks and semaphors.
Comments