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

# kernacc.9

`kernacc` — 检查内存区域的可访问性

## 名称

`kernacc`, `useracc`

## 概要

```c
#include <sys/param.h>
#include <sys/proc.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>

int
kernacc(void *addr, int len, int rw)

int
useracc(void *addr, int len, int rw)
```

## 描述

`kernacc` 和 `useracc` 函数检查由 `addr` 和 `len` 给定的虚拟地址范围内是否允许执行 `rw` 中指定类型的操作。`rw` 的可能值为 `VM_PROT_READ`、`VM_PROT_WRITE` 和 `VM_PROT_EXECUTE` 的任意按位组合。`kernacc` 检查内核地址空间中的地址，而 `useracc` 将 `addr` 视为用户空间地址。用于此操作的进程上下文取自全局变量 `curproc`。

## 返回值

如果允许 `rw` 指定的访问类型，两个函数都返回布尔值 true。否则返回布尔值 false。

## 缺陷

进程指针应作为参数传递给 `useracc`。


---

# 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/kernacc.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.
