So, I’ve thought I’d implement a brk()
system call really quickly in
my tiny libc
library, but I’ve run into complications. Why? Short
answer: I read the documentation wrong. sbrk()
returns the old
address, not the new one!
But anyways, I’ve learned some other interesting things along the way.
For odd reasons that be, I was testing on Ubuntu 10.04 LTS, which has
this weird bug that under certain conditions like programs being
spawned from make, memory maps are setup such that
brk() is stuck
between two other allocations and can't move. Thus, only
mmap() can
be used on this particular Linux configuration to get more memory.
That's dumb.
mmap()` is too complicated to be recommendable for use
in very small, simple, statically-linked Linux programs.
Luckily, however, I was able to get sbrk()
working even on this
system.
Now it turns out there’s an easy way to check a process’s memory maps
on Linux:
Read on →