STACK(9)
π STACK(9) β stack macros β¨
okay bestie, this is the Kernel Developer's Manual page for STACK(9), and it's literally all about the stack macros. let's get into it π«Ά
πΈ NAME πΈ
STACK(9) β stack macros, aka the little macros that do stack pointer math for you π
β¨ SYNOPSIS β¨
no cap, here's the exact include and the exact calls:
#include <sys/param.h>
type
STACK_ALLOC(sp, size);
type
STACK_MAX(sp, size);
type
STACK_ALIGN(sp, bytes);
type
STACK_GROW(sp, size);
type
STACK_SHRINK(sp, size);
π¦ DESCRIPTION π¦
okay so real talk: a stack is an area of memory with a fixed origin but a variable size. a stack pointer points to the most recently referenced location on the stack. initially, when the stack has a size of zero, the stack pointer points to the origin of the stack. when data items are added to the stack, the stack pointer moves away from the origin. that's the whole vibe π«
the STACK_ALLOC() macro returns a pointer to allocated stack space of some size. given the returned pointer sp and size, STACK_MAX() returns the maximum stack address of the allocated stack space. the STACK_ALIGN() macro can be used to align the stack pointer sp by the specified amount of bytes. slay π
two basic operations are common to all stacks: a data item is added (βpushβ) to the location pointed by sp, or a data item is removed (βpopβ) from the stack. the stack pointer must be subsequently adjusted by the size of the data item. that part is important, bestie β don't forget the adjustment π
the STACK_GROW() and STACK_SHRINK() macros adjust the stack pointer sp by given size. iconic behavior, honestly π
a stack may grow either up or down. the described macros take this into account by using the __MACHINE_STACK_GROWS_UP preprocessor define. so yeah, the macros are doing a little vibe check on the direction for you π
π SEE ALSO π
go touch grass with these besties too:
signed off by Debian, dated April 8, 2011, and filed under STACK(9) β bye bestie π«Άπ
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2010 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms