---
name: "cap_getmode"
section: "2"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/cap_enter"
---

# cap\_getmode(2)

Capability mode system calls

Part of [cap\_enter(2)](/cap_enter/2.md).

## NAME

**cap\_enter**, **cap\_getmode** – Capability mode system calls

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<sys/capsicum.h\>**

*int*\

**cap\_enter**(*void*);

*int*\

**cap\_getmode**(*u\_int \*modep*);

## DESCRIPTION

**cap\_enter**() places the current process into capability mode, a mode of execution in which processes may only issue system calls operating on file descriptors or reading limited global system state. Access to global name spaces, such as file system or IPC name spaces, is prevented. If the process is already in a capability mode sandbox, the system call is a no-op. Future process descendants created with [fork(2)](/fork/2.md) or [pdfork(2)](/pdfork/2.md) will be placed in capability mode from inception.

When combined with [cap\_rights\_limit(2)](/cap_rights_limit/2.md), [cap\_ioctls\_limit(2)](/cap_ioctls_limit/2.md), [cap\_fcntls\_limit(2)](/cap_fcntls_limit/2.md), **cap\_enter**() may be used to create kernel-enforced sandboxes in which appropriately-crafted applications or application components may be run.

**cap\_getmode**() returns a flag indicating whether or not the process is in a capability mode sandbox.

## RUN-TIME SETTINGS

If the kern.trap\_enotcap sysctl MIB is set to a non-zero value, then for any process executing in a capability mode sandbox, any syscall which results in either an ENOTCAPABLE or ECAPMODE error also generates the synchronous SIGTRAP signal to the thread on the syscall return. On signal delivery, the *si\_errno* member of the *siginfo* signal handler parameter is set to the syscall error value, and the *si\_code* member is set to TRAP\_CAP.

See also the PROC\_TRAPCAP\_CTL and PROC\_TRAPCAP\_STATUS operations of the [procctl(2)](/procctl/2.md) function for similar per-process functionality.

## RETURN VALUES

The **cap\_enter()** and **cap\_getmode()** functions return the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

When the process is in capability mode, **cap\_getmode**() sets the flag to a non-zero value. A zero value means the process is not in capability mode.

## ERRORS

The **cap\_enter**() and **cap\_getmode**() system calls will fail if:

- \[ENOSYS\]

  The running kernel was compiled without **options CAPABILITY\_MODE**.

The **cap\_getmode**() system call may also return the following error:

- \[EFAULT\]

  Pointer *modep* points outside the process's allocated address space.

## SEE ALSO

[cap\_fcntls\_limit(2)](/cap_fcntls_limit/2.md), [cap\_ioctls\_limit(2)](/cap_ioctls_limit/2.md), [cap\_rights\_limit(2)](/cap_rights_limit/2.md), [fexecve(2)](/fexecve/2.md), [procctl(2)](/procctl/2.md), [cap\_sandboxed(3)](/cap_sandboxed/3.md), [capsicum(4)](/capsicum/4.md), [sysctl(9)](/sysctl/9.md)

## HISTORY

The **cap\_getmode**() system call first appeared in FreeBSD 8.3. Support for capabilities and capabilities mode was developed as part of the TrustedBSD Project.

## AUTHORS

These functions and the capability facility were created by Robert N. M. Watson at the University of Cambridge Computer Laboratory with support from a grant from Google, Inc.

## CAVEATS

Creating effective process sandboxes is a tricky process that involves identifying the least possible rights required by the process and then passing those rights into the process in a safe manner. Consumers of **cap\_enter**() should also be aware of other inherited rights, such as access to VM resources, memory contents, and other process properties that should be considered. It is advisable to use [fexecve(2)](/fexecve/2.md) to create a runtime environment inside the sandbox that has as few implicitly acquired rights as possible.
