Skip to content

Commit 2396c46

Browse files
authored
[libc] Add malloc.h header defining mallopt (#110908)
This patch adds the malloc.h header, declaring Scudo's mallopt entrypoint when built LLVM_LIBC_INCLUDE_SCUDO, as well as two constants that can be passed to it (M_PURGE and M_PURGE_ALL). Due to limitations of the current build system, only the declaration of mallopt is gated by LLVM_LIBC_INCLUDE_SCUDO, and the two new constants are defined irrespectively of it. We may need to refine this in the future. Note that some allocators other than Scudo may offer a mallopt implementation too (e.g. man 3 mallopt), albeit with different supported input values. This patch only supports the specific case of LLVM_LIBC_INCLUDE_SCUDO.
1 parent ef66936 commit 2396c46

File tree

15 files changed

+111
-0
lines changed

15 files changed

+111
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ set(TARGET_LIBC_ENTRYPOINTS
347347
libc.src.wchar.wctob
348348
)
349349

350+
if(LLVM_LIBC_INCLUDE_SCUDO)
351+
list(APPEND TARGET_LIBC_ENTRYPOINTS
352+
# malloc.h external entrypoints
353+
libc.src.stdlib.mallopt
354+
)
355+
endif()
356+
350357
set(TARGET_LIBM_ENTRYPOINTS
351358
# fenv.h entrypoints
352359
libc.src.fenv.feclearexcept

libc/config/linux/aarch64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(TARGET_PUBLIC_HEADERS
1111
libc.include.inttypes
1212
libc.include.limits
1313
libc.include.link
14+
libc.include.malloc
1415
libc.include.math
1516
libc.include.pthread
1617
libc.include.signal

libc/config/linux/arm/entrypoints.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ if(LLVM_LIBC_FULL_BUILD)
189189
)
190190
endif()
191191

192+
if(LLVM_LIBC_INCLUDE_SCUDO)
193+
list(APPEND TARGET_LIBC_ENTRYPOINTS
194+
# malloc.h external entrypoints
195+
libc.src.stdlib.mallopt
196+
)
197+
endif()
198+
192199
set(TARGET_LIBM_ENTRYPOINTS
193200
# fenv.h entrypoints
194201
libc.src.fenv.feclearexcept

libc/config/linux/arm/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(TARGET_PUBLIC_HEADERS
44
libc.include.fenv
55
libc.include.float
66
libc.include.inttypes
7+
libc.include.malloc
78
libc.include.math
89
libc.include.search
910
libc.include.setjmp

libc/config/linux/riscv/entrypoints.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,13 @@ set(TARGET_LIBC_ENTRYPOINTS
346346
libc.src.wchar.wctob
347347
)
348348

349+
if(LLVM_LIBC_INCLUDE_SCUDO)
350+
list(APPEND TARGET_LIBC_ENTRYPOINTS
351+
# malloc.h external entrypoints
352+
libc.src.stdlib.mallopt
353+
)
354+
endif()
355+
349356
set(TARGET_LIBM_ENTRYPOINTS
350357
# fenv.h entrypoints
351358
libc.src.fenv.feclearexcept

libc/config/linux/riscv/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(TARGET_PUBLIC_HEADERS
1111
libc.include.stdint
1212
libc.include.inttypes
1313
libc.include.limits
14+
libc.include.malloc
1415
libc.include.math
1516
libc.include.pthread
1617
libc.include.sched

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,13 @@ set(TARGET_LIBC_ENTRYPOINTS
346346
libc.src.wchar.wctob
347347
)
348348

349+
if(LLVM_LIBC_INCLUDE_SCUDO)
350+
list(APPEND TARGET_LIBC_ENTRYPOINTS
351+
# malloc.h external entrypoints
352+
libc.src.stdlib.mallopt
353+
)
354+
endif()
355+
349356
set(TARGET_LIBM_ENTRYPOINTS
350357
# fenv.h entrypoints
351358
libc.src.fenv.feclearexcept

libc/config/linux/x86_64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set(TARGET_PUBLIC_HEADERS
1313
libc.include.inttypes
1414
libc.include.limits
1515
libc.include.link
16+
libc.include.malloc
1617
libc.include.math
1718
libc.include.pthread
1819
libc.include.sched

libc/include/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ add_header_macro(
146146
.llvm-libc-macros.limits_macros
147147
)
148148

149+
add_header_macro(
150+
malloc
151+
../libc/newhdrgen/yaml/malloc.yaml
152+
malloc.h.def
153+
malloc.h
154+
DEPENDS
155+
.llvm_libc_common_h
156+
.llvm-libc-macros.malloc_macros
157+
)
158+
149159
add_header_macro(
150160
math
151161
../libc/newhdrgen/yaml/math.yaml

libc/include/llvm-libc-macros/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ add_macro_header(
109109
link-macros.h
110110
)
111111

112+
add_macro_header(
113+
malloc_macros
114+
HDR
115+
malloc-macros.h
116+
)
117+
112118
add_macro_header(
113119
math_macros
114120
HDR

0 commit comments

Comments
 (0)