0

So I call sbrk like this:

void *return_value = sbrk(1024);

And when I debug it is giving me this error on that specific line:

__GI___sbrk (increment=1024) at sbrk.c:32
32 sbrk.c: No such file or directory.

Why would this be? And what is this error?

EDIT: Example code

int list1[10];
void* return_val;

if (list[1] == 0){
return_val = sbrk(1024);
list1[0] = 32;
}

This is the part of my code where it errors out.

Art smart
  • 11
  • 1
  • 1
    sbrk.c: No such file or directory is because the debugger looks for this source file but you don't have it in debugger source path nor it's absolute – Jean-François Fabre Nov 19 '21 at 19:31
  • 1
    So it’s not wrong implementation wise, sbrk.c just isn’t in the file directory for gdb? @Jean-FrançoisFabre – Art smart Nov 19 '21 at 19:32
  • you don't have the source for sbrk.c. You could find it on github, though. Or here: https://code.woboq.org/userspace/glibc/misc/sbrk.c.html – Jean-François Fabre Nov 19 '21 at 19:33
  • that doesn't answer why it breaks, though. can you try setting 0 instead of 1024 see if it still breaks? I'm pretty sure the memory is corrupt at the point you're calling this code. Try running valgrind or some other tool to detect mem issues – Jean-François Fabre Nov 19 '21 at 19:33
  • @Jean-FrançoisFabre it does not break when set to 0 – Art smart Nov 19 '21 at 19:38
  • try to create a [mcve] with very few code for us to reproduce. As said above I think your code trashes the memory and the next memory function crashes. Happens a lot (crash in `free`, `malloc`...) – Jean-François Fabre Nov 19 '21 at 19:39
  • 1
    @Jean-FrançoisFabre will edit my question and put it under there. – Art smart Nov 19 '21 at 19:41
  • FYI, unless you are implementing `malloc`, you are not allowed to call `sbrk` with a nonzero argument; that could cause crashes all by itself. – zwol Nov 19 '21 at 19:45
  • 1
    @zwol I am implementing malloc – Art smart Nov 19 '21 at 19:46
  • 1
    @Artsmart OK, in that case, have you ensured that glibc's malloc is _never_ invoked? All calls to allocate memory, including from within glibc itself, are routed through your code? (The easiest way to mess this up is to forget to define one of the functions that you must define if you are replacing malloc. There is a list in glibc's documentation somewhere.) – zwol Nov 19 '21 at 19:47
  • 1
    Yes, definitely have not invoked malloc anywhere here. @zwol – Art smart Nov 19 '21 at 19:54
  • What was the last gdb command you gave before you got this message? – Armali Nov 23 '21 at 09:32

0 Answers0