start moving malloc and friends in

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-08-11 00:00:00 +00:00
parent 975b15b814
commit d7a24ea200
25 changed files with 222 additions and 26 deletions

View File

@@ -12523,8 +12523,6 @@ Programs under link:userland/c/[] are examples of https://en.wikipedia.org/wiki/
** `stdlib.h`
*** exit
**** link:userland/c/abort.c[]
*** malloc
**** link:userland/c/out_of_memory.c[]
** `stdio.h`
*** link:userland/c/stderr.c[]
*** link:userland/c/getchar.c[]
@@ -12533,6 +12531,15 @@ Programs under link:userland/c/[] are examples of https://en.wikipedia.org/wiki/
* Fun
** link:userland/c/infinite_loop.c[]
==== malloc
Allocate memory! Vs using the stack: https://stackoverflow.com/questions/4584089/what-is-the-function-of-the-push-pop-instructions-used-on-registers-in-x86-ass/33583134#33583134
* link:userland/c/malloc.c[]: `malloc` hello world: allocate two ints and use them.
* link:userland/c/out_of_memory.c[]: test how much memory Linux lets us allocate
LInux 5.1 / glibc 2.29 implements it with the <<mmap,`mmap` system call>>.
==== GCC C extensions
===== C empty struct
@@ -12629,6 +12636,26 @@ getconf -a
`getconf` is also specified by POSIX at: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/getconf.html but not the `-a` option which shows all configurations.
==== mmap
The mmap system call allows advanced memory operations:
* link:userland/posix/mmap_file.c[]: memory mapped file example
mmap is notably used to implement the <<malloc,malloc ANSI C>> function, replacing the previously used break system call.
Linux adds has several POSIX extension flags to it.
===== brk
Previously <<posix>>, but was deprecated in favor of <<malloc>>
Example: link:userland/glibc/brk.c[]
The example allocates two ints and uses them, and then deallocates back.
Bibliography: https://stackoverflow.com/questions/6988487/what-does-the-brk-system-call-do/31082353#31082353
=== Userland multithreading
The following sections are related to multithreading in userland: