---
name: "cache"
section: "3"
platform: "macos"
package: "libplatform"
version: "375.120.2"
release: "macOS 26.5"
platforms: ["macos"]
url: "https://new.carta.tech/cache"
---

# cache(3)

cache control

## NAME

**sys\_cache\_control**, **sys\_icache\_invalidate**, **sys\_dcache\_flush** – cache control

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<libkern/OSCacheControl.h\>**

*int*\

**sys\_cache\_control**(*int function*, *void \*start*, *size\_t len*);

*void*\

**sys\_icache\_invalidate**(*void \*start*, *size\_t len*);

*void*\

**sys\_dcache\_flush**(*void \*start*, *size\_t len*);

## DESCRIPTION

These functions operate on every cache line containing one of the  *len* bytes of memory pointed to by *start*. Normally the operations apply to every processor in the system, but the exact semantics of these operations is platform dependent.  They should be used with caution.

**sys\_cache\_control**() performs the operation specified by *function*. Refer to the header file for a list of currently supported functions.

**sys\_icache\_invalidate**() prepares memory for execution, typically by invalidating the instruction cache for the indicated range.  This should be called after writing machine instructions to memory, and before executing them.  On IA32 processors this function is a NOP, because their instruction caches are coherent.

**sys\_dcache\_flush**() writes modified data cache lines to main memory, and then invalidates all lines in the range being operated on. It can be useful when dealing with cache incoherent devices or DMA.

## RETURN VALUES

**sys\_cache\_control**() returns zero on success, ENOTSUP if *function* is not valid.

## SEE ALSO

[atomic(3)](/atomic/3.md), barrier(3)

## HISTORY

These functions first appeared in Mac OS 10.5 (Leopard).
