Andy Polyakov wrote:

Now let's imagine we pick Microsoft compiler. I'd suggest to perform an
MT build and link it dynamically with MSVCRT.DLL. Idea is to use MSVCRT
primarily for BIO and other strictly internal purposes (keep in mind
that MSCVRT.DLL can be redistributed). At the same time I'd sanitize
functions appearing in "grep 'FILE \*' include/openssl/*" and replace
calls to stdio with wrappers, which would treat FILE * as opaque
pointer. Idea is to link these wrappers to corresponding stdio functions
provided by compiler environment at run-time. How? We could require user
application to be linked with a module of own design, which exports a
symbol, and then we could refer to this symbol from DllMain in
libeay32.dll for the purposes of linking the wrappers with vendor stdio.
For example. Supplied code to be compiled and linked with user
application could look as following (this is just an example!):

static void *link_table[]={stdin,stout,stderr,fprintf,fread,fclose};
void ** __declspec(dllexport) get_link_table() { return link_table; }

While DllMain in libeay32.dll could:

h=GetModuleHandle(NULL);//.exe image used to create the calling process
proc=GetProcAddress(h,"get_link_table");
if (proc==NULL) report_or_log_error_and_exit();
tbl=(*proc)(); // use tbl to feed the wrappers

It should be enough to simply add the supplied module to the target
project to make magic happen and work with any run-time environment or
flag combination. There is a minor problem with Borland, which insists
on different function name decoration and uses different .LIB format,
but it seems that it can be easily resolved with IMPLIB... Thoughts? A.


I like it! :-)

Three comments:

   * Do we really need to have the "get_link_table" function?  I think
     we should be able to import just the link table itself
   * We can define the link table in a header file and have the user
     simply include the header file in only one place OR provide a
     #define prior to the #include to define the link table in only one
     place
   * The link table should contain a table format version number so
     that in case we need to grow the table in the future it will be
     possible to do so and produce the appropriate compatibility errors.

- Jeff



Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to