简体   繁体   English

系统调用通常是如何实现的

[英]How is syscall typically implemented

I am implementing something very similar to simplistic OS but I am struggling to grasp what syscalls actually are:我正在实施与简单操作系统非常相似的东西,但我正在努力掌握系统调用实际上是什么:
First of all - in process system which thread does typically * execute the interrupt routine(the syscall kernel function) - one of the kernel threads or the user space thread given temporal privilege and routine address?首先 - 在进程系统中哪个线程通常* 执行中断例程(系统调用内核函数) - 内核线程之一或用户空间线程被赋予临时特权和例程地址?
How would be syscall mechanism implemented in user space - does either of following match roughly what is going on under hood?系统调用机制将如何在用户空间中实现 - 以下任一是否与引擎盖下发生的事情大致匹配?
Implementation A:实施A:

//equivalent to assembly
//MOV EAX sys_call_no
//INT 0x80
void* interrupt(int service, void* args)
{
   return kernel::int_vector[service](args);
}

Implementation B:实施B:

//equivalent to assembly
//MOV EAX sys_call_no
//INT 0x80
void* interrupt(int service, void* args, void* ret)
{
   kernel::intr_queue.push_back_syncd(interrupt_context(){kernel::int_vector[service], args, ret});
   waitForServiceCompleted();
   return ret;
}
//in kernel thread
while(true)
{
  while(!intr_queue.isEmpty())
  {
    auto context = intr_queue.pop();
    context.ret = context.func(context.args);
    notifyDone();
  }
}

C: I don't understand it at all - it works completely differently. C:我完全不明白——它的工作方式完全不同。
* by typically I mean most common current desktop systems like window 7/8 or latest Ubuntu distribution *通常我指的是当前最常见的桌面系统,例如 window 7/8 或最新的 Ubuntu 发行版
note: sorry if this is not the correct SE site to post this question - please comment me to move it注意:抱歉,如果这不是发布此问题的正确 SE 站点 - 请评论我以移动它

Implementation A is typically how it works.实现 A 通常是它的工作方式。 Operating systems primarily use their own threads only for tasks that don't involve directly responding to a specific process request.操作系统主要将自己的线程仅用于不涉及直接响应特定进程请求的任务。 When a process makes a typical system call, that thread switches to a kernel stack and begins running kernel code in kernel context.当进程进行典型的系统调用时,该线程会切换到内核堆栈并开始在内核上下文中运行内核代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM