Ignore:
Timestamp:
2013-11-07T11:04:00+01:00 (5 months ago)
Author:
moo
Message:

updated relocate impl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/processor/foot.m4

    r1446 r1448  
    136136} 
    137137dnl }}} 
     138#define ptradd(type, ptr, ptrdiff) ((type) ((char *) (ptr) + (ptrdiff))) 
     139#define ptrsub(ptr1, ptr2) ((char *) (ptr1) - (char *)(ptr2)) 
    138140define(`DEFINE_RELOCATE_API', ` 
    139 EXPORTED_FUNCTION(`void xc_processor_relocate_$1($1 *src, $1 *old_start, $1 *new_start TSRMLS_DC)') dnl {{{ 
     141EXPORTED_FUNCTION(`void xc_processor_relocate_$1($1 *old_src, $1 *old_start, $1 *new_src, $1 *new_start TSRMLS_DC)') dnl {{{ 
    140142{ 
    141     /* 
    142     $1 *xc_addressof(offset) { 
    143         return (char *) offset + (ptrdiff_t) old_start; 
    144     } 
    145     */ 
    146     ptrdiff_t ptrdiff = /* offset + */ (ptrdiff_t) old_start; 
     143    ptrdiff_t offset_from_old_start = 0; /* unkown X used later */ 
     144    $1 *const old_address = ptradd($1 *, offset_from_old_start, (ptrdiff_t) old_start); 
     145    ptrdiff_t offset = ptrsub(old_address, old_src); 
     146    $1 *const new_address = ptradd($1 *, new_src, offset); 
    147147 
    148     /* 
    149     ptrdiff_t *xc_offsetof(offset) { 
    150         return (char *) xc_addressof(offset) - src; 
    151     } 
     148    /* diff to new_ptr */ 
     149    ptrdiff_t ptrdiff = (ptrdiff_t) new_address; 
     150    ptrdiff_t relocatediff = (ptrdiff_t) ptradd($1 *, new_start, offset); 
    152151 
    153     $1 *xc_newoffset(offset) { 
    154         return new_start + xc_offsetof(offset); 
    155     } 
    156     */ 
    157     ptrdiff_t relocatediff = new_start + (/* offset + */ ptrdiff - (ptrdiff_t) src); 
    158  
    159     xc_relocate_$1(src, ptrdiff, relocatediff TSRMLS_CC); 
     152    xc_relocate_$1(new_src, ptrdiff, relocatediff TSRMLS_CC); 
    160153} 
    161154dnl }}} 
Note: See TracChangeset for help on using the changeset viewer.