Download presentation
Presentation is loading. Please wait.
Published byReynard Heath Modified over 9 years ago
1
kernel mode linux
2
Why? ● The pros – There is a C like interface inside the Linux kernel already. – The speed. – The size of AP. ● The cons – Missing functions – complex dependencies
3
What do we have? ● basic system calls – open,read,write, ● string handling routines – strnicmp,strcpy, strcat, strncat,strcmp,,strncmp,strchr,strrchr,strlen,strnlen,strspn,strpbrk,strs ep,memset,bcopy,memcpy,memmove,memcmp,mems can,strstr,memchr, ● strtoul,strtol,strtoull,strtoll,vsnprintf,printk,sprintf,vsprintf,vsscanf,sscanf,
4
Create a kernel thread ● create_kernel: clone with CLONE_VM – int (*fn)(void *) – void * arg – unsigned long flags ● CLONE_VFORK – wait the child finish before return ● CLONE_VM – Use the same VM as the parent instead creating a private copy. ● CLONE_FS – Use the same filesystem as the parent ● CLONE_FILES – Use the same file descriptors as the parent
5
do_fork ● CLONE_SIGHAND – Use the same signal handler as the parent ● CLONE_PTRACE – If the clinet will be traced after the do_fork() ● CLONE_PID – Use the same PID as the paqrent. Only used in the SMP system to create the init ● CLONE_THREAD,CLONE_PARENT – Used in the thread. It will set the parent of the thread as the previous thread.
6
Example: kernel thread ● kernel_thread(thread_func,&data,CLONE_FS|CL ONE_FILES|CLONE_SIGHAND) – Execute thread_func in the new thread with data as argument. – Clone the FS/FILES and Signal handler. ● Like fork
7
Access the file ● The easy way – open,read,write are provided. – It's a system call. Slow ● The hard way – do_generic_file_read – do_generic_file_write – filp_open
8
Access the network ● sock_create ===> socket ● sock->ops->bind ====> bind ● sock->ops->listen ===> listen ● sock_release ===> close ● sock_recvmsg ===> recv ● sock_sendmsg ===> send
9
khttpd ● It's a kernel level web server, which can handle the static web pgae acces. ● It's extra fast. ● All dynamic URL requests will be redirected to the user space. ● Exec: Setup a web site by using khttpd and then forward a dynamic URL request to a kernel space CGI.
10
How to setup the khttpd ● Enable khttpd and rebuild the Linux kernel ● Setup server port – echo 8080 > /proc/sys/net/khttpd/serverport ● Setup the root directory of HTML pages – echo /html > /proc/sys/net/khttpd/documentroot ● Start the daemon – echo 1 > /proc/sys/net/khttpd/start
11
The management daemon ● initialize the globval variables ● wait for activation ● fork threads ● wait for deactivation
12
The MainDaemon ● Wait for new connection ● handle connection in DataSending queue and UserSpace queue ● Log connections if necessary
13
Connection handling ● Accept connections and put them into either datasending queue or user space queue. ● Datasending Queue – Static page ● User Space Queue – Dynamic page
14
Static Page ● Open the file by using filp_open. ● sock_wspace: get the size of unused buffer in a socket. ● send data by using sendfile or read/send depending on the capability of the filesystem.
15
Dynamic page ● Get the user space daemon – tcp_v4_lookup_listener ● transfer the socket to the user space daemon – tcp_acceptq_queue
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.