gpt4 book ai didi

sbrk(0) 会失败吗?

转载 作者:行者123 更新时间:2023-12-02 14:23:00 24 4
gpt4 key购买 nike

我想知道是否有人已经看到 sbrk(0) 失败?

我的意思是,如果你能达到这个功能,你显然之前就有访问内存的权限,所以检查当前的中断位置应该没问题,对吧?

编辑:例如,我应该考虑错误异常吗?

最佳答案

documents指出:

   sbrk() increments the program's data space by increment bytes.
Calling sbrk() with an increment of 0 can be used to find the current
location of the program break.

...

On success, sbrk() returns the previous program break. (If the break
was increased, then this value is a pointer to the start of the newly
allocated memory). On error, (void *) -1 is returned, and errno is
set to ENOMEM.

如果你看glibc您将看到的实现:

extern void *__curbrk;
...
void *
__sbrk (intptr_t increment)
{
...
if (increment == 0)
return __curbrk;
...

它不可能失败,因为如果 increment 为零,它只会返回 __curbrk 的当前值。

关于sbrk(0) 会失败吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21559658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com