dynamic vtables in c-program's on ia64

W.Stuehlmeyer@t-online.de W.Stuehlmeyer@t-online.de
Wed Jun 5 03:36:00 GMT 2002


Hello,

i have dynamically created c-programs with vtable structures.

Example:

typedef struct IMallocVtbl
{
    HRESULT ( *QueryInterface) (IMalloc * pThis, const IID & riid, void
** ppvObject);
    ULONG ( *AddRef) (IMalloc * pThis);
    ULONG ( *Release) (IMalloc * pThis);
    void * ( *Alloc) (IMalloc * pThis, ULONG cb);
...
} IMallocVtbl;

typedef struct CMalloc
{
    IMallocVtbl *lpVtbl;
} CMalloc;
IMallocVtbl * g_lpVtblMalloc = 0;


CMalloc g_CMalloc;
IMalloc * g_pMalloc = (IMalloc *) &g_CMalloc;

IMallocVtbl CRetailMallocVtbl =
{
    CMalloc_QueryInterface,
    CMalloc_AddRef,
    CMalloc_Release,
    CRetailMalloc_Alloc,
...
};

HRESULT MallocInitialize(BOOL fForceLocalAlloc)
{
...
    g_lpVtblMalloc = &CRetailMallocVtbl;
    g_CMalloc.lpVtbl = g_lpVtblMalloc;

    return hr;
}

extern "C" LPVOID CoTaskMemAlloc(ULONG ulcb)
{
  if (g_CMalloc.lpVtbl == 0) {
    MallocInitialize(0);
  }

  //
  // SEGMENTATION VIOLATION
  //
  return g_pMalloc->Alloc(ulcb);
}

I create a function address pointer in CRetailMallocVtbl.
With gcc 3.0.x it works fine, but gcc 3.1 has a new ABI and
g_pMalloc->Alloc(ulcb) needs a <function address; GP address pointer>
pair on a itanium machine.

I have no idea how could create a GP adress pointer or a function
address/GP address pair from a C. I found no information on
www.codesourcecery.org how
could i create these address pairs.

How can i solve this problem?

Only IMallocVtbl could be modified ( typedef struct IMallocVtbl ... and
IMallocVtbl CRetailMallocVtbl = ..) via macros in a header file.



More information about the Gcc-help mailing list