Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>Note: I work predominately with ARM machines so some of these things might be ARM specific. Also, I'm going to try and simplify it as much as I can. Feel free to correct anything that might be wrong or oversimplified.</em></p> <blockquote> <p>Lets say the thread makes a system call. I am a bit unclear on the workings after this. The Interrupt will generate a call. One of my questions is who will answer this call?</p> </blockquote> <p>Usually, the processor will start executing at some predetermined location in kernel mode. The kernel will save the current process state and look at the userspace registers to determine which system call was requested and dispatch that to the correct system call handler.</p> <blockquote> <p>So the Kernel will lookup the Interrupt Vector Table and get the routine which needs to be executed. My next question is which stack will be used in the execution of the Interrupt? Will it be the Kernel Thread's Stack or the User level Thread's Stack? (I am assuming that it will be the Kernel Thread's Stack.)</p> </blockquote> <p>I'm pretty sure it will switch to a kernel stack. There would be some pretty severe security problems with information leaks if they used the userspace stack.</p> <blockquote> <p>Coming back to the flow of the program lets say the operation is opening a file using fopen. The subsequent question I have is how will the jump from the ISR to System Call take place? Or is our ISR mapped to a System Call? </p> </blockquote> <p><code>fopen()</code> is actually a libc function and not a system call itself. It may (and in most cases will) call the <code>open()</code> syscall in its implementation though.</p> <p>So, the process (roughly) is:</p> <ol> <li>Userspace calls <code>fopen()</code></li> <li><code>fopen</code> performs a system call to <code>open()</code></li> <li>This triggers some sort of exception or interrupt. In response, the processor switches into a more privileged mode and starts executing at some preset location in the kernel.</li> <li>Kernel determines what kind of interrupt and exception it is and handles it appropriately. In our case, it will be a system call.</li> <li>Kernel determines which system call is being requested by reading the userspace registers and extracts any arguments and passes it to the appropriate handler.</li> <li>Handler runs.</li> <li>Kernel puts any return code into userspace registers.</li> <li>Kernel transfers execution back to where the exception occured.</li> </ol> <blockquote> <p>Also at a more broader picture when the Kernel Thread is being executed I am assuming that the "OS region" on the RAM will be used to house the pages which are executing the System Call. </p> </blockquote> <p>Pages don't execute anything :) Usually, in Linux, any address mapped above 0xC0000000 belongs to the kernel.</p> <blockquote> <p>Again looking at it from a different angle (Hope your still with me) finally I am assuming that the corresponding Kernel Thread is being handled by the CPU Scheduler where in a context switch would have happened from the User Level Thread to the corresponding Kernel Level Thread when the fopen System Call was being answered. </p> </blockquote> <p>With a preemptive kernel, threads effectively aren't discriminated against. With my understanding, a new thread isn't created for the purpose of servicing a system call - it just runs in the same thread from which the system call was requested in, except in kernel mode.</p> <p>That means a thread that is in kernel mode servicing a system call can be scheduled out just the same as any other thread. Hence, this is where you hear about 'userspace context' when developing for the kernel. It means it's executing in kernel mode on a usermode thread.</p> <p>It's a little difficult to explain this so I hope I got it right.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload