This is the mail archive of the cygwin-developers mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Add cygwin_internal CW_GET_MODULE_PATH_FOR_ADDR


On Oct 15 18:58, Corinna Vinschen wrote:
> On Oct 15 10:51, Corinna Vinschen wrote:
> > On Oct 15 01:00, Charles Wilson wrote:
> > > >tweak:
> > > >
> > > >- Call GetModuleFileNameW instead of GetModuleFileName.
> > > 
> > > After we told Bruno to not use any windowsisms?  Sure, it's a lot
> > > simpler -- but it violates our recommendations for cygwin clients.
> > 
> > I don't think it makes sense to add a cygwin_internal call for this
> > functionality.  The idea was to use the same code as Linux here and to
> > avoid any Cygwinism.  If using /proc/$PID/maps is not enough, then
> > that's not possible.  So in turn, there's no practical difference between
> > 
> >   #ifdef __CYGWIN__
> >     cygwin_internal (CW_GET_MODULE_PATH_FOR_ADDR,
> > 		     addr, buf, sizeof (buf))
> >     shared_library_fullname = strdup (buf);
> >   #endif
> > 
> > and
> > 
> >   #ifdef __CYGWIN__
> >     GetModuleFileNameW (module_handle, buf, sizeof (buf)))
> >     shared_library_fullname = (char *) cygwin_create_path (CCP_WIN_W_TO_POSIX,
> > 							   buf);
> >   #endif
> > 
> > In both cases you have to use a Cygwinism and you have to guard the
> > code using #ifdef __CYGWIN__.
> 
> Btw., if you don't want to use /proc/$PID/maps, but still want to get rid
> of DLLMain and do the job in the relocate function, then a fast Cygwinism
> would be something like this:
> 
>   MEMORY_BASIC_INFORMATION mbi;
>   wchar_t buf[PATH_MAX];
> 
>   VirtualQuery (&relocate, &mbi, sizeof mbi);
>   GetModuleFileNameW (mbi.BaseAddress, buf, sizeof buf);
>   shared_library_fullname = (char *) cygwin_create_path (CCP_WIN_W_TO_POSIX,
> 							 buf);

No, scratch that.  The BaseAddress is not exactly the same as the
HMODULE value and GetModuleFileName only handles exact values in
contrast to the NtQueryVirtualMemory function.  And even if you
subtract 0x1000, it would only work if the code is in the first
segment of the module.  Since .text is usually the first segment,
this should usually work, but that's not good enough.

Anyway, while toying around with this I found a bug in the
dos_drive_mappings::fixup_if_match method.  It only handles local
drive paths but breaks UNC network paths.  I'll fix that.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]