musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/src/linux/sbrk.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014年01月02日 17:03:34 -0500
committerRich Felker <dalias@aerifal.cx>2014年01月02日 17:03:34 -0500
commit7a995fe706e519a4f55399776ef0df9596101f93 (patch)
tree72e03908db98617da9d06eadb8e1d83a0206772d /src/linux/sbrk.c
parent5c81b8fe453994a74afa7cd355dd707ee2d01a24 (diff)
downloadmusl-7a995fe706e519a4f55399776ef0df9596101f93.tar.gz
disable sbrk for all values of increment except 0
use of sbrk is never safe; it conflicts with malloc, and malloc may be used internally by the implementation basically anywhere. prior to this change, applications attempting to use sbrk to do their own heap management simply caused untrackable memory corruption; now, they will fail with ENOMEM allowing the errors to be fixed. sbrk(0) is still permitted as a way to get the current brk; some misguided applications use this as a measurement of their memory usage or for other related purposes, and such usage is harmless. eventually sbrk may be re-added if/when malloc is changed to avoid using the brk by using mmap for all allocations.
Diffstat (limited to 'src/linux/sbrk.c')
-rw-r--r--src/linux/sbrk.c 6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/linux/sbrk.c b/src/linux/sbrk.c
index 36437653..1e82d643 100644
--- a/src/linux/sbrk.c
+++ b/src/linux/sbrk.c
@@ -1,9 +1,9 @@
#include <stdint.h>
+#include <errno.h>
#include "syscall.h"
void *sbrk(intptr_t inc)
{
- unsigned long cur = syscall(SYS_brk, 0);
- if (inc && syscall(SYS_brk, cur+inc) != cur+inc) return (void *)-1;
- return (void *)cur;
+ if (inc) return (void *)__syscall_ret(-ENOMEM);
+ return (void *)__syscall(SYS_brk, 0);
}
generated by cgit v1.2.1 (git 2.18.0) at 2025年09月08日 05:36:19 +0000

AltStyle によって変換されたページ (->オリジナル) /