Skip to content
Felix S. Klock II edited this page Jul 28, 2013 · 3 revisions

"RetaddrToOffset" refers to the protocol(s) used in NativeCodeLarceny variants to convert a native return address (a honest to god word-length pointer) to a numeric offset (where the base of the offset is the start of the current procedure's code vector).

This protocol is necessary when one is storing a return address into a context and a garbage collection may occur (a GC before the return address is fetched back and the context discarded, that is). When the garbage collection happens, it might copy the codevector to a different location on the heap, and the old heap storage becomes unusable. Thus, if you leave your return address in the original address format, you have a dangling reference to dead memory.

There are at least two separate places where we convert return addresses to offsets into the codevector (and vice versa):

  1. In the code to flush the frames of stack cache into the heap storage
  2. In the code calling into the C millicode routines (this is true both for SparcNativeLarceny and IAssassinLarceny).

Ticket #114 has the log of PnkFelix's work discovering the need to add this protocol to IAssassinLarceny.


Exceptions

There are places where the return addresses are not converted into offsets.

  • In SparcNativeLarceny, if reg0 holds 0x0, then the return address is left as an absolute value.
  • In IAssassinLarceny, if reg0 holds a non-procedure value, then the return address is left as an absolute value.
    • (One could think of this as a generalization of the Sparc exception.)
    • PnkFelix wants someone to investigate the cases where reg0 can hold a non-procedure value, and make sure that the garbage collector isn't going to interfere with it.
      • The cases that he managed to find (via instrumentation of the millicode interface) are mostly calls to mem_stkuflow (and thus refill_stack_cache as well).
      • But there was one call to mc_timer_exception where reg0 was not a procedure.
  • In IAssassinLarceny, the call to mc_apply is also left as an absolute address. The reason for this is that mc_apply on [wiki:PetitLarcenyDerivative]s actually replaces the value held for reg0 in place with the closure argument that we are applying; thus, if we attempted to use the protocol, we would have the wrong reg0 for the conversion back to the native address, leading to chaos (usually in the form of an illegal instruction exception).
Clone this wiki locally