---
name: "memguard"
section: "9"
platform: "linux"
package: "freebsd-manpages"
version: "6.0-5"
release: "Debian 4.0 (Etch)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/memguard"
---

# memguard(9)

memory allocator for debugging purposes

## NAME

**MemGuard** – memory allocator for debugging purposes

## SYNOPSIS

**options DEBUG\_MEMGUARD**

## DESCRIPTION

**MemGuard** is a simple and small replacement memory allocator designed to help detect tamper-after-free scenarios. These problems are more and more common and likely with multithreaded kernels where race conditions are more prevalent.

Currently, **MemGuard** can only take over **malloc**(), **realloc**() and **free**() for a particular malloc type. **MemGuard** takes over M\_SUBPROC allocations by default.

## FILES

- *src/sys/kern/kern\_malloc.c*

  File to replace the malloc type in

## EXAMPLES

The following steps are necessary to use **MemGuard**:

1. Put the DEBUG\_MEMGUARD option into your kernel config.

2. Open *src/sys/kern/kern\_malloc.c* in your favourite editor. Look for lines containing “XXX CHANGEME!” and replace M\_SUBPROC with the appropriate malloc type. This might require additional but small/simple code modifications (e.g., if the malloc type is declared out of scope).

3. Build and install your kernel. Tune the *vm.memguard\_divisor* boot-time tunable, which is used to scale how much of *kmem\_map* you want to allot for **MemGuard**. The default is 10, so *kmem\_size*/10 bytes will be used. The *kmem\_size* value can be obtained via the *vm.kmem\_size* [sysctl(8)](/sysctl/8.md) variable.

## SEE ALSO

[sysctl(8)](/sysctl/8.md), [vmstat(8)](/vmstat/8.md), [contigmalloc(9)](/contigmalloc/9.md), [malloc(9)](/malloc/9.md)

## HISTORY

**MemGuard** first appeared in FreeBSD 6.0.

## AUTHORS

**MemGuard** was written by Bosko Milekic ⟨bmilekic@FreeBSD.org⟩. This manual page was written by Christian Brueffer ⟨brueffer@FreeBSD.org⟩.

## BUGS

Currently, it is not possible to override UMA [zone(9)](/zone/9.md) allocations.
