logo       

Re: Q&D implementation of dlfunc(): msg#00030

Subject: Re: Q&D implementation of dlfunc()
I would prefer to see this done in a proper way, or at least have some suitably
abstracted interface to allow MD pointer munging/indexing by these functions
for the purpose of returning function pointers, however using our toolchain on
all of our supported architectures, your change is somewhat straightforward
enough, however I wonder if it wouldn't be better to write this:

rv = (uintptr_t)dlsym(handle, symbol);

But that's just the way I've taken to writing such shims, and your way is as
valid as any, functionally, I suppose.  I would say to write it like that, as
you essentially synthesise the "correct" way to swap data and function pointer
values, on all our architectures.

Here are my conversion functions, stemming from a conversation with Bruce Evans
a while ago:

typedef void (*convptr)();

convptr function_to_data_ptr(convptr function, uintptr_t *data)
{
  memcpy(data, &function, sizeof(convptr));

  return function;
}

convptr data_to_function_ptr(convptr *function, uintptr_t *data)
{
  memcpy(function, data, sizeof(convptr));

  return *function;
}
-- 
J. Mallett <jmallett@xxxxxxxxxxx>                    FreeBSD: The Power To Serve

To Unsubscribe: send mail to majordomo@xxxxxxxxxxx
with "unsubscribe freebsd-standards" in the body of the message



<Prev in Thread] Current Thread [Next in Thread>