- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 C 程序中使用 brk() 函数。我的目标是通过使用
检查当前程序中断 (pb) 来直接使用它(作为更大测试的一部分)void *current_break = sbrk(0);
执行malloc(用于测试,如果分配的空间足够大,malloc有时应该执行brk)
void* mallow_return = malloc(1);
而不是使用当前地址 + 增量直接执行 brk()(并检查这是否会增加 pb):
int increase = 0x01;
void * newbreak = current_break + increase;
int return_value = brk(&newbreak);
我的问题是,无论是使用大型 malloc (malloc(5000;)) 还是使用(对齐或未对齐)brk() 调用,pb 都不会更改。检查 errno 时我得到一个
Cannot allocate memory!
error (as given by
strerror(errno)
有人能明白为什么我无论如何都无法增加程序中断吗?
感谢您的任何提示!
(系统是:Debian 10 (buster),内核为 4.19)
编辑:根据要求,这是主要功能,包括:
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
void main(int argc, char **argv)
{
printf("[+] Get current program break\n");
void *current_break = sbrk(0);
printf("\t[+] Current break point=\t%#x\n", current_break);
printf("[+] Malloc should call brk as well\n");
void* mallow_return = malloc(1);
printf("[+] Check if malloc changes PB\n");
void *after_break = sbrk(0);
printf("\t[+] After malloc pbreak=\t%#x\n", after_break);
int increase = 0x01;
printf("\t[+] Increasing p-break direclyby %d\n", increase);
void * newbreak = current_break + increase;
printf("\t[+] Setting break point to=\t%#x\n", newbreak);
int return_value = brk(&newbreak);
//check if error was thrown
int errornumber = errno;
if (errornumber != 0)
{
printf("\t[+] Error: %s!\n", strerror(errornumber));
return -1;
}
//check if pb was set now
printf("\t[?] New program break value?\t%#x\n", sbrk(0));
printf("[?] Return value of brk: %d\n", return_value);
return;
}
最佳答案
(感谢@Antii Haapala,他将此作为评论发布。)
我们需要删除此处的&符号:
int return_value = brk(&newbreak);
该行应该很简单
int return_value = brk(newbreak);
关于c - Linux:brk()错误 'Cannot allocate memory',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58373192/
自从升级 NodeJs 以来,我从 Visual Studio 2017 运行 Nodejs 时遇到此错误。 断点也不起作用。有任何解决这个问题的方法吗? 注意:VS版本是15.5.6NodeJS 版
我已经使用 VS 2015 在我的计算机上安装了 nodeJs 并进行了设置。当我尝试运行示例 hello world 应用程序时,它抛出以下错误: verb(node:14096) [DEP0062
当我在 Visual Studio 中运行 Node.js 应用程序时,我收到以下消息:DeprecationWarning: 'node --debug' 和 'node --debug-brk'
根据Linux程序员手册: brk() and sbrk() change the location of the program break, whichdefines the end of the
据我所知,在 brk() 系统调用之后,额外的虚拟内存尚未分配(即页表尚未增长以容纳新的虚拟地址)。我的印象是这些页表被添加为 那么...为什么您需要 brk() 系统调用?为什么内核不能在内存访问进
这是 strace -T -ttt -ff -x -y -o pid.trace -p 2145 的输出。跟踪如下。 1503431273.934716 semop(1204093022, {{0,
我写了一个基本的自定义内存管理分配器,它会获取一 block 内存,预先创建 X 对象,这样每当我需要“创建”一个对象时,我就可以获取一个预先创建的对象并简单地分配数据成员(内存已经分配)。 我使用了
我正在尝试将内存动态分配到堆中,然后在这些内存地址中分配值。我了解如何分配内存,但我如何将例如寄存器中的值分配给第一个动态内存地址? 这是我到目前为止: push rbp mov rb
我正在尝试将内存动态分配到堆中,然后在这些内存地址中分配值。我了解如何分配内存,但我如何将寄存器中的值分配给第一个动态内存地址?这是我目前所拥有的: push rbp mov rbp,
我想知道在内核源代码版本 >= 2.6 中定义了 brk。那是哪个c文件包含它的定义? grep 并没有透露太多。另外 sbrk 是在 glibc 中实现的吗? 最佳答案 它在 mmap.c 中。寻找
我正在尝试在 NASM/x86 程序集中使用 sys_brk 分配一些内存。 sys_break返回break的新地址,这是数据段的末尾,对吧?那么我新分配的内存驻留在哪里?我假设它位于旧中断值和新中
不使用brk是否可以实现malloc库函数?我可以使用 sbrk(0) 找出程序中断的当前位置,然后使用 sbrk(size) 对其进行递增吗? 如果是,那么为什么首先要添加 brk? 最佳答案 br
有人可以解释为什么这个“无休止的”循环会很快出现段错误吗?例如,假设我们有这个功能: #!/bin/bash foo() { foo }; foo 8-10 秒后出现段错误。通过 strace 检
我在很多地方(musl 邮件列表、macOS 论坛等)听说 brk() 和 sbrk() 是不安全的。这些地方很多要么根本不解释,要么解释的很模糊。例如,this链接指出“这些功能从根本上被破坏了”,
虽然我知道 Unix 系统调用 brk 和函数 sbrk 的作用,但我不知道它们代表什么。谁能赐教一下? 最佳答案 它来自于“破值”。 我引用:“更改是通过重置进程的中断值并分配适当的空间量来进行的。
我是新手,任何人都可以通过一个简短的例子说出 brk 和 sbrk 之间的确切区别吗?有没有效率因素可以从两者中选择任何一个?malloc 和 new 内部调用 brk 或 sbrk。 最佳答案 in
我编写了一个小的 hello world 程序,并在其二进制文件上运行 strace,它列出了所有在我的 Hello_world 程序执行过程中调用的系统调用。 strace ./a.out exec
我发现并研究了x86 memory access segmentation fault它在我的代码中不起作用。区别可能在于我不使用单独的 .text 和 .data 段,而是通过创建自定义 ELF h
我正在尝试通过简单的脚本使用 Node 检查器。我有一些控制台日志,因此我可以判断它是否正在运行。我尝试了两种方法: Node 调试 test.js 通过这种方法,调试器在 Chrome 中打开,但不
我正在使用 Node v6.10.0 并试图弄清楚为什么我的 --debug-brk 如此缓慢。如果没有此标志(仅使用 --inspect 或 --debug),它几乎是瞬时的,尽管调试器仍然需要很长
我是一名优秀的程序员,十分优秀!