Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Sleazy jmp_buf hacks
@ 1998-04-01  5:00 David Gadbois
  0 siblings, 0 replies; only message in thread
From: David Gadbois @ 1998-04-01  5:00 UTC (permalink / 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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1998-04-01  5:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-04-01  5:00 Sleazy jmp_buf hacks David Gadbois

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox