Posts

Showing posts from March, 2021

Procfs creation at kernel

 source : https://github.com/kishorePonnoju/ModuleLoding/blob/main/charDev/basic.c

Device Driver Basics

 What is device driver ?    is piece of software that controls a particular type of device which connected to the computer system  Diff b/w kernel moulde and Device driver?     A kernel module is a piece of the code that can be added loaded/inserted and unloaded/removed as per the demand/need.  what happened we do insmod on a module? it calls init_module() to intimate the kernel that a module is attempted to be loaded and transfers the control to the kernel. In the kernel, sys_init_module is run. It does a sequence of operations as follows: Verifies if the user who attempts to load the module has permission to do so or not .  After verification, the load_moudle function is called .  The load_module function assigns temporary memory and copies the elf module from userspace to kernel memory using copy_from_user.    It then checks the sanity of the ELF file (verification if it is a proper ELF file)  Then based on the ELF file inte...

Mutex and semaphores

Why we need synchronization? Please thin about the below question, how will u solve the problem. There are two process P1 (having statement S1) and P2 (having statement S2).  write a program to execute statements s2 only after S1? Reader and writer problem, there one shared data is present between 5 readers and one writer.  here is required condition are,  allow multiple readers to read at the same time.  only one single writer can access shared data at the same time. I2c buses acquired by the concurrent user process, how ur driver will handle the concurrent requests.?  The dining philosophers problem states that there are 5 philosophers sharing a circular table and they eat and think alternatively. There is a bowl of rice for each of the philosophers and 5 chopsticks. A philosopher needs both their right and a left chopstick to eat. A hungry philosopher may only eat if there are both chopsticks available. Otherwise, a philosopher puts down their chopstick and b...

USB audio Driver

 Sources: http://ben-collins.blogspot.com/2010/04/writing-alsa-driver.html https://www.alsa-project.org/wiki/Main_Page https://www.ukuug.org/events/linux2003/papers/TIwai/soundsystems.pdf https://www.alsa-project.org/wiki/Main_Page

kernel module access user space file:

Image
is it possible to create a file from kernel space? is it possible to create store the data in kernel space? Yes. its possible  source code:  #include <linux/module.h>   #include <linux/init.h>   #include <linux/fs.h>   #include <linux/uaccess.h>      static char buf[] ="access from the kernel \n";   static char buf1[32];       int __init test_init(void)   {       struct file *fp;       mm_segment_t fs;        int result;       loff_t pos;       printk("test enter\n");       printk("KERNEL_DS=0x%llx USER_DS=0x%llx get_fs()=0x%llx\n", KERNEL_DS, USER_DS, get_fs());       fp =filp_open("/home/kishore/kernel_file",O_RDWR | O_CREAT,0644);       if (IS_ERR(fp)){           printk("create file error\n");           return -1;  ...