longjmp

C++: Safe to use longjmp and setjmp?

Hi, Is it safe to use longjmp and setjmp in C++ on linux/gcc with regards to the following? Exception handling (I'm not implementing exception handling using longjmp/setjmp. I want to know what side effects longjmp/setjmp will have on standard exception handling) *this pointer Signals Smart pointers (boost's shared and intrusive point...

pthreads, setjmp, longjmp. How can you tell when a function is finished running?

I am writing a user space thread library. I have a struct that manages each thread. My threads are very simple, they take a function ptr and its arguments, and just run that function one time. Each thread has a jmp_buf and I use setjmp and longjmp to switch between threads. One thing I cant figure out is how to tell when this function i...

C user space library modifying jmp_buf doesnt make my function go to the correct address

Im trying to modify a jmp_buf so it executes a function (after i setjmp and longjmp back in). I have a struct called t that stores information about each thread. start_routine is a function pointer that should be executed. /* this is inside an init() function setting stuff up */ void init(void *(*start_routine)(void*), void *arg) { ...

longjmp() from signal handler

I'm using the following code to try to read an input from user and timeout and exit if more than 5 seconds pass. This is accomplished through a combination of setjmp/longjmp and the SIGALRM signal. Here's the code: #include <stdio.h> #include <setjmp.h> #include <unistd.h> #include <string.h> #include <sys/signal.h> jmp_buf buffer; /...

What does each entry in the Jmp_buf structure hold?

I am running ubuntu 9.10 (karmic koala), and I took a look at the jmp_buf structure which is simply an array of 12 ints. When I use setjmp, and pass in a jmp_buf structure -- 4 out of 12 entries are saved off. These 4 entries are the stack pointer, frame pointer, program counter and return address. What are the other 8 entries for? Are t...

Warning "might be clobbered" on C++ object with setjmp

#include <setjmp.h> #include <vector> int main(int argc, char**) { std::vector<int> foo(argc); jmp_buf env; if (setjmp(env)) return 1; } Compiling the above code with GCC 4.4.1, g++ test.cc -Wextra -O1, gives this confusing warning: /usr/include/c++/4.4/bits/stl_vector.h: In function ‘int main(int, char**)’: /usr/include/c++/4.4...

Implementing preemptive microthreads using signal handlers and setjmp/longjmp

I want to implement POSIX compliant microthreads in Linux environment. Basic idea is as follows: Using technique described here, assign new stack space for each fiber. Using setitimer, create timer that will send signals in constant time interval. Signal handler for this timer will act as a scheduler and switch between fibers. The pr...

Can I undo or remove an atexit command?

If I place atexit( fn ); on the exit stack, it will get executed when the program exits: returns from main() or via exit(). Can I remove it from the stack? Why do I want to do this, you ask? I was experimenting with a simple try-catch mechanism using atexit, setjmp and longjmp. It would be just perfect if I could undo-atexit(fn); - ev...

Multitasking using setjmp, longjmp

Hi, is there a way to implement multitasking using setjmp and longjmp ...

In C: sending func pointers, calling the func with it, playing with EIP, jmp_buf and longjmp

I need to make sure i understand some basic stuff first: how do i pass function A as a parameter to function B? how do i call function A from inside B ? Now for the big whammy: I'm trying to do something along the lines of this: jmp_buf buf; buf.__jmpbuf[JB_PC] = functionA; longjmp(buf,10); Meaning that I want to use longjmp in o...

question with longjmp

I want to use longjmp to simulate goto instruction.I have an array DS containing elements of struct types (int , float, bool ,char). I want to jump to the place labled "lablex" where x is DS[TOP].int_val. how can I handle this? sample code : ... jmp_buf *bfj; ... stringstream s;s<<"label"<<DS[TOP].int_val; bfj = (jmp_buf *) s.str(); lo...

stating jmp_buf as pointer

I'm tring to define jmp_buf as pointer and using it in nested longjmp(s).as follow: ... jmp_buf *bfj; ... and then writing if else: if( setjmp(*bfj) == 0){ DS[SP-2].int_val=(int)bfj;; //to store the bfj }else {} and somewhere else using the stored bfj to longjmp bfj = (jmp_buf *)DS[TOP].int_val; longjmp(*bfj,1); where DS[TOP]...

How to insulate a job/thread from crashes

I'm working on a library where I'm farming various tasks out to some third-party libraries that do some relatively sketchy or dangerous platform-specific work. (In specific, I'm writing a mathematical function parser that calls JIT-compilers, like LLVM or libjit, to build machine code.) In practice, these third-party libraries have a t...