From: David Gadbois <gadbois@cyc.com>
Subject: Sleazy jmp_buf hacks
Date: 1998/04/01 [thread overview]
Message-ID: <%HyU.271$Tp.385823@news.giganews.com> (raw)
I am trying to port a run-time system that hacks jmp_bufs in order to
implement coroutines. The idea is to set up a jmp_buf and modify it
so that longjmp()ing to it runs a given function in a new stack. It
appears that Alpha OSF/1 3.0 longjmp() does not restore the Procedure
Value register (27), which callees in the standard calling convention
use to get at their global pointer. Is this analysis correct? Is
there some workaround?
#include <stdlib.h>
#include <stdio.h>
#include <setjmp.h>
static void fun(void) {
printf("Eureka!\n");
exit(0);
}
#define STACK_SIZE (1L << 20L)
int main() {
jmp_buf env;
setjmp(env);
env[30] /* JB_RA */ = (long) fun;
env[31] /* JB_PV */ = (long) fun; /* Doesn't get restored! */
env[34] /* JB_SP */ = ((long) malloc(STACK_SIZE)) + STACK_SIZE;
longjmp(env, 1);
}
Thanks,
--David Gadbois
reply other threads:[~1998-04-01 5:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox