> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/4.3-bsd-unix-cao-zuo-xi-tong-she-ji-yu-shi-xian/di-yi-bu-fen-gai-lan/2.3.-nei-he-fu-wu.md).

# 2.3 内核服务

内核级代码与用户级代码之间的边界由底层硬件提供的硬件保护设施强制实施。内核运行在一个用户进程无法访问的独立地址空间中。启动 I/O、停止中央处理器（CPU）运行这类特权操作只对内核开放。应用程序用系统调用向内核请求服务。系统调用用于让内核执行复杂操作（如把数据写到辅存）和简单操作（如返回当前时刻）。所有系统调用在应用程序看来都是同步的：内核执行与系统调用相关的动作期间，不允许应用程序运行。

系统调用通常实现为一个硬件陷阱，它改变 CPU 的执行模式和当前的地址空间映射。用户在系统调用中提供的参数，内核在使用前都会校验，以确保系统的完整性。传入内核的所有参数都会复制到内核的地址空间。复制参数是为了保证已校验的参数不会因系统调用的副作用而改变。系统调用的结果由内核通过硬件寄存器返回，或把值复制进用户提供的缓冲区。与传入内核的参数一样，用于返回结果的用户缓冲区也必须校验，以确保它们属于应用程序的地址空间。内核在处理系统调用时若遇到错误，就向用户返回一个错误码。对 C 语言来说，这个错误码存放在全局变量 `errno` 中，而发起系统调用的函数调用则返回 −1。

用户应用程序与内核彼此独立运行。UNIX 不会把 I/O 控制块或其他操作系统相关的数据结构放进应用程序的地址空间，从而不干扰应用程序。每个用户级应用程序都在各自独立的地址空间中运行。大多数状态变化——例如挂起一个进程好让另一个进程运行——对相关进程都是不可见的。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://book.bsdcn.org/4.3-bsd-unix-cao-zuo-xi-tong-she-ji-yu-shi-xian/di-yi-bu-fen-gai-lan/2.3.-nei-he-fu-wu.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
