提交 7a995fe7 编写于 作者: R Rich Felker

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.
上级 5c81b8fe
#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);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册