Pick a Free OS

User login

Navigation

For Kernel_Newbies By a Kernel_Newbie

/usr/src/linux/include/asm-i386/system.h),which happens in the scheduler

(kernel/sched.c) which switches from the previous task to the next task. The

switch_to routine saves di,si and bp into the stack and then saves the stack

pointer,and the instruction pointer of the switched task set to the value just

after the (jmp __switch_to) instruction (a C routine defined in

asm-i386/process.c), in its thread_struct, and then resets the stack pointer to

the new task,and pushes the return address defined in task->thread.eip

(ret_from_fork) in the stack,before jumping to __switch_to routine. The

__switch_to saves the tss values for esp0 of the new switched task,also saves

the ioperm bitmaps,saves the fs,and gs in the prev_thread,and loads the fs,and

gs in the new thread,loads the debug registers from the new thread,and then bids

GOODBYE before entering ret_from_fork. This way,2 threads will go through

different return paths in a fork call.(which creates an additional process table

entry.) The caller of the fork routine goes through ret_from_sys_call,which is

the main destination of most of the routines,and returns with the pid of child

process. The child process instead gets back with a return of 0, which is setup

in copy_thread by making childregs->eax = 0. ret_from_fork also jumps to

ret_from_sys_call but not before calling schedule_tail (defined in

kernel/sched.c and will be explained in the scheduler section.)

ret_from_sys_call does the following: It first checks the softirq_active bitmask

for any active softirqs (tasklets or bottom halves to be run.) If its active,

then it calls handle_softirq which jumps to do_softirq (kernel/softirq.c). This

returns back to ret_from_intr which checks for its mode when it was called. If

in kernel_mode it jumps to restore_all straight, but if in User_Mode,it makes a

jump to ret_with_reschedule,which checks if task->need_resched is set ,before

jumping to reschedule which calls schedule,and gets a return path to

ret_from_sys_call. ret_from_sys_call also checks for signal pending,and if there

are signals pending,it jumps to signal_return which calls

do_signal(arch/i386/kernel.c) before jumping to restore_all,and back to the

USER_SPACE from HELL.

Schematic Representation from ret_from_sys_call: (for return from

System_calls)

ret_from_sys_call:Mode-Kernel_Mode | User_Mode