> 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/man9/syscall_module.9.md).

# SYSCALL\_MODULE.9

`SYSCALL_MODULE` — 系统调用内核模块声明宏

## 名称

`SYSCALL_MODULE`

## 概要

```c
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/module.h>
#include <sys/sysent.h>

SYSCALL_MODULE(name, int *offset, struct sysent *new_sysent,
    modeventhand_t evh, void *arg)
```

## 描述

`SYSCALL_MODULE` 宏声明一个新的系统调用。`SYSCALL_MODULE` 展开为一个名为 `sys/` + `name` 的内核模块声明。

此宏所需的其他参数为：

```c
#include <sys/sysent.h>
```

**`offset`** 指向一个 `int` 的指针，用于保存在 `struct sysent` 中分配该系统调用的偏移量。如果 `offset` 所指向的位置持有非 0 值，则尽可能使用该值。如果持有 0，则分配一个新值。

**`new_sysent`** 是一个指向结构的指针，该结构指定实现系统调用的函数以及该函数所需的参数数量（参见

**`evh`** 指向内核模块事件处理程序函数的指针，带有参数 `arg`。更多信息请参见 [module(9)](/man/man9/module.9.md)。

**`arg`** 调用 `evh` 事件处理程序的回调函数时传递的参数。

分配给模块的系统调用号可以使用 modstat(2) 和 modfind(2) 系统调用获取。宏 `SYSCALL_MODULE_HELPER` 包含了 `SYSCALL_MODULE` 及其大部分样板代码。

## 实例

系统调用模块的最小示例可在 **`/usr/share/examples/kld/syscall/module/syscall.c`** 中找到。

## 参见

[module(9)](/man/man9/module.9.md), **`/usr/share/examples/kld/syscall/module/syscall.c`**

## 作者

本手册页由 Alexander Langer <alex@FreeBSD.org> 编写。


---

# 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/man9/syscall_module.9.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.
