> 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/man/man4/ksyms.4.md).

# ksyms.4

`ksyms` — 内核符号表接口

## 名称

`ksyms`

## 概要

`device ksyms`

## 描述

`/dev/ksyms` 字符设备提供对内核符号表快照的只读接口。内核内符号管理器旨在能够处理多种类型的符号表，但此设备仅支持 [elf(5)](/man/man5/elf.5.md) 符号表。ELF 格式镜像包含两个节：一个符号表和对应的字符串表。

**`Symbol Table`** SYMTAB 节包含当前运行内核中存在的符号表条目，包括任何已加载模块的符号表条目。符号按内核模块加载时间排序，首先是内核文件符号，然后是第一个加载模块的符号，依此类推。

**`String Table`** STRTAB 节包含符号表条目引用的内核和任何已加载模块的符号名称字符串。

从 `/dev/ksyms` 文件读取的 ELF 格式符号表数据表示设备打开时内核的状态。由于 `/dev/ksyms` 没有文本或数据，大多数字段初始化为 NULL。`ksyms` 驱动不会在 `/dev/ksyms` 文件打开时阻止模块加载或卸载到内核中，但可能包含过期数据。

## 文件

**`/dev/ksyms`**

## 错误

如果出现以下情况，open(2) `/dev/ksyms` 将失败：

**\[Er** EBUSY] 设备已打开。进程必须先关闭 `/dev/ksyms` 才能再次打开。

**\[Er** ENOMEM] 内核资源不足。

**\[Er** ENXIO] 驱动无法创建内核符号表快照。如果内核正在加载或卸载模块，可能会发生此情况。

## 参见

nlist(3), [elf(5)](/man/man5/elf.5.md), [kldload(8)](/man/man8/kldload.8.md)

## 历史

许多不同的操作系统中都存在 `ksyms` 设备。此实现的功能类似于 Solaris 和 NetBSD 的 `ksyms` 驱动。

`ksyms` 驱动最早出现于 FreeBSD 8.0，用于支持 [lockstat(1)](/man/man1/lockstat.1.md)。

## 作者

`ksyms` 驱动由 Stacey Son <sson@FreeBSD.org> 编写。

## 缺陷

由于文件可随时动态链接到内核中，符号信息可能会变化。打开 `/dev/ksyms` 文件时，你可以访问一个 ELF 镜像，它表示该时刻内核符号信息状态的快照。保持设备打开不会阻止加载或卸载内核模块。要获取新快照，必须关闭并重新打开设备。

一个进程一次只能打开 `/dev/ksyms` 文件一次。进程必须先关闭 `/dev/ksyms` 才能再次打开。


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man4/ksyms.4.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
