0

I try to make a header file in C that virtualizes all function calls from ucontext.h library.

Everything is working fine except for function makecontext() when I try to call my_makecontext() I get this message:

not enough storage for stack: Success
Aborted (core dumped)

But when I use makecontext instead of my function everything is working fine.

I am struggling to solve it.

A snippet of my code is:

test_file_for_my_funcs.c

//Doesn't work
//makecontext(&context.uctx_source,(void*)Write,1,*length);
//makecontext(&context.uctx_target,(void*)Read,0);
mycoroutines_create(&context.uctx_source,(void *)Write,length);
mycoroutines_create(&context.uctx_target,(void *)Read,length);

mycoroutines.h

int mycoroutines_create(ucontext_t *coroutine,void (body)(void *),void *arg)
{
makecontext(coroutine,(void *)body,1,(int *)arg);
if(errno != 0){
                perror("Error reported by makecontext()");
                return -1;         }
  else {
    perror("not enough storage for stack");
    abort();
  }
  return 0;
}
fdermishin
  • 3,519
  • 3
  • 24
  • 45
mixos
  • 1
  • 1
  • 1
    Never check `errno` unless the previous function failed. And the `makecontext` function doesn't (according to [this manual page](http://man7.org/linux/man-pages/man3/makecontext.3.html) fail so you should now check `errno` at all. – Some programmer dude Dec 15 '18 at 16:29
  • 1
    Irregardless of if `makecontext` can fail or not, think about your logic for your error handling: Either there's an error, or else there's an error. You have no path in the function that leads to a "no error" situation. – Some programmer dude Dec 15 '18 at 16:31

0 Answers0