fluffos/docs/driver/malloc.md

28 lines
1.5 KiB
Markdown
Raw Permalink Normal View History

2018-12-30 16:43:04 -08:00
---
title: general / malloc
---
2023-11-25 09:50:24 -08:00
# malloc
2018-12-30 16:43:04 -08:00
Note: some machines don't allow the system calls to be replaced with
2018-12-30 16:59:01 -08:00
a function of the same name. In particular, the compile will fail during
the link phase with a 'duplicate symbol' error. Most of the machines
1993-01-07 13:20:58 -05:00
I've seen that exhibit this behavior use shared libraries (NeXT, RS/6000).
Also note that smalloc.c uses sbrk() and brk() and these routines cannot
be used in a program that uses malloc() (read the sbrk() man page for more
2018-12-30 16:59:01 -08:00
information). Even if the program doesn't explicitly call malloc, it will
fail if it calls system calls that internally use malloc. Thus the only
truly safe way to use sbrk and brk is to replace the definition of system
2018-12-30 16:59:01 -08:00
malloc. And some machines do not allow system malloc to be replaced.
2017-09-29 17:00:30 -07:00
1993-09-14 12:43:23 -04:00
Note: if you plan to hack on the driver, you should use MALLOC(x, ...),
1993-03-21 06:13:14 -05:00
FREE(x, ...), REALLOC(x, ...), and CALLOC(x, ...) instead of the lowercase
2018-12-30 16:59:01 -08:00
counterparts. Be sure to look at how these macros are used in the driver
source itself in order to figure out the right syntax. The uppercase
1993-03-21 06:13:14 -05:00
versions are macros that get replaced with the proper function names
2018-12-30 16:59:01 -08:00
depending upon which malloc package is chosen. This change was made in
1993-03-21 06:13:14 -05:00
order to provide for those machines that complain when functions are added
2018-12-30 16:59:01 -08:00
with the same names as system calls. The change also allows some stats to
be collected even when using system malloc. Various debug version of these
macros also exist. Look at the macros defined near the end of the file
1993-03-21 06:13:14 -05:00
config.h in the src directory.