STACK(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… 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