mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-27 12:04:27 +01:00
start moving malloc and friends in
This commit is contained in:
31
README.adoc
31
README.adoc
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user