public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* problems with dlopen
@ 2001-12-07  8:26 Henning Moll
  2001-12-07  8:34 ` Cliff Hones
  0 siblings, 1 reply; 4+ messages in thread
From: Henning Moll @ 2001-12-07  8:26 UTC (permalink / raw)
  To: cygwin

Hello!

Why does this code fail with segfault?
I think the problem is that dlopen calls malloc itself? Is that right?
Any suggestions how to fix it?

--snip--
#include <stdlib.h>
#include <dlfcn.h>

static void *(*orig_malloc) (size_t) = 0;

void *
malloc(size_t p)
{
        static int state = 0;
        void * handle;

        switch (state)
        {
                case 0:
                        handle = dlopen("cygwin1.dll", RTLD_NOW);
                        orig_malloc = (void *(*)(size_t)) dlsym (handle, "malloc");
                        state = 1;
                        /*fall through*/
                case 1:
                        return (*orig_malloc) (p);
        }
}

int
main()
{
        return 0;
}

  

--snip--

Best regards,
Henning


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: problems with dlopen
  2001-12-07  8:26 problems with dlopen Henning Moll
@ 2001-12-07  8:34 ` Cliff Hones
  2001-12-07  8:56   ` Re[2]: " Henning Moll
  0 siblings, 1 reply; 4+ messages in thread
From: Cliff Hones @ 2001-12-07  8:34 UTC (permalink / raw)
  To: DrScott; +Cc: cygwin

> Why does this code fail with segfault?
> I think the problem is that dlopen calls malloc itself? Is that right?
> Any suggestions how to fix it?

If your suspicion is correct, then simply moving "state = 1" to before
the call of dlopen should do the trick, i.e.:

                case 0:
                        state = 1;
                        handle = dlopen("cygwin1.dll", RTLD_NOW);
                        orig_malloc = (void *(*)(size_t)) dlsym (handle, "malloc");
                        /*fall through*/
-- Cliff

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re[2]: problems with dlopen
  2001-12-07  8:34 ` Cliff Hones
@ 2001-12-07  8:56   ` Henning Moll
  2001-12-07  9:07     ` Christopher Faylor
  0 siblings, 1 reply; 4+ messages in thread
From: Henning Moll @ 2001-12-07  8:56 UTC (permalink / raw)
  To: Cliff Hones; +Cc: cygwin

Hallo Cliff,

Friday, December 07, 2001, 5:26:33 PM, you wrote:

> If your suspicion is correct, then simply moving "state = 1" to before
> the call of dlopen should do the trick, i.e.:

>                 case 0:
>                         state = 1;
>                         handle = dlopen("cygwin1.dll", RTLD_NOW);
>                         orig_malloc = (void *(*)(size_t)) dlsym (handle, "malloc");
>                         /*fall through*/
> -- Cliff

You're right, that was an error.
Unfortunately it doesn't solve the problem. Again, the same error
while executing 'dlopen'.
Now i think the problem ist not a recursive call of 'malloc' (for the
moment), because i should be able to detect such recursive behaviour
by setting a breakpoint in my own malloc... Hmm, and there is no
recursion before the segfault.
Sure, after the current problem is removed, dlopen may call malloc to
get some memory. For that purpose i'll try to implement an additional
state which then use a static memory array to provide the requested
memory.

Again, any suggestions?

-- 
Best regards,
Henning


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: problems with dlopen
  2001-12-07  8:56   ` Re[2]: " Henning Moll
@ 2001-12-07  9:07     ` Christopher Faylor
  0 siblings, 0 replies; 4+ messages in thread
From: Christopher Faylor @ 2001-12-07  9:07 UTC (permalink / raw)
  To: cygwin

On Fri, Dec 07, 2001 at 05:56:43PM +0100, Henning Moll wrote:
>Again, any suggestions?

Look at the cygwin source code?

cgf

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-12-07 16:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-07  8:26 problems with dlopen Henning Moll
2001-12-07  8:34 ` Cliff Hones
2001-12-07  8:56   ` Re[2]: " Henning Moll
2001-12-07  9:07     ` Christopher Faylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).