aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/dlfcn.cc
AgeCommit message (Collapse)AuthorFilesLines
2022-05-29Cygwin: remove miscellaneous 32-bit codeKen Brown1-23/+0
2021-07-09Cygwin: Define PSAPI_VERSION as 1 before including psapi.hJon Turney1-1/+0
The default PSAPI_VERSION is controlled by WIN32_WINNT, which we set to 0x0a00 when building utils since 48a76190 (and is the default in w32api >= 9.0.0) In order for the built executables to run on Windows Vista, we must also define PSAPI_VERSION as 1 (otherwise '#define GetModuleFileNameExA K32GetModuleFileNameExA' causes a 'The procedure entry point K32GetModuleFilenameExA could not be located in the dynamic link library kernel32.dll' error at run time). Also drop uneeded psapi.h from dlfcn.cc (31ddf45d), resource.cc (34a6eeab) and ps.cc (1def2148).
2019-02-07forkables: inline dll_list::forkables_supportedMichael Haubenwallner1-1/+1
And LONG fits better for shared_info member forkable_hardlink_support.
2017-11-27cygwin: convert most #ifndef __x86_64__ to #ifdef __i386__Corinna Vinschen1-2/+2
Address the real offender Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-22dlfcn: Remove stray debug outputnewlib-snapshot-20170323Corinna Vinschen1-1/+0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-21Cygwin: dlfcn: Fix reference countingCorinna Vinschen1-8/+30
The original dll_init code was living under the wrong assumption that dll_dllcrt0_1 and in turn dll_list::alloc will be called for each LoadLibrary call. The same wrong assumption was made for cygwin_detach_dll/dll_list::detach called via FreeLibrary. In reality, dll_dllcrt0_1 gets only called once at first LoadLibrary and cygwin_detach_dll once at last FreeLibrary. In effect, reference counting for DLLs was completely broken after fork: parent: l1 = dlopen ("lib1"); // LoadLibrary, LoadCount = 1 l2 = dlopen ("lib1"); // LoadLibrary, LoadCount = 2 fork (); // LoadLibrary in the child, LoadCount = 1! child: dlclose (l1); // FreeLibrary actually frees the lib x = dlsym (l2); // SEGV * Move reference counting to dlopen/dlclose since only those functions have to keep track of loading/unloading DLLs in the application context. * Remove broken accounting code from dll_list::alloc and dll_list::detach. * Fix error handling in dlclose. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-08Implement dladdr() (partially)Jon Turney1-0/+34
Note that this always returns with dli_sname and dli_saddr set to NULL, indicating no symbol matching addr could be found. Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2016-09-08dlopen: on x/lib search x/bin if exe is in x/binnewlib-snapshot-20160923Michael Haubenwallner1-1/+42
On 09/02/2016 11:03 AM, Corinna Vinschen wrote: > On Sep 2 10:46, Michael Haubenwallner wrote: >> On 09/01/2016 03:32 PM, Corinna Vinschen wrote: >>> You could just use the global variable program_invocation_name. If in >>> doubt, use the Windows path global_progname and convert it to full POSIX >>> via cygwin_conv_path. >> >> Patch updated, using global_progname now. > > Looks good and you're right to do it this way since I just noticed > that program_invocation_name may return a relative pathname. Yep. > Btw., in other calls which require the full POSIX path we use > mount_table->conv_to_posix_path instead of cygwin_conv_path (see > e. g. fillout_pinfo()). It's a bit faster. Maybe something for a > followup patch. No problem - attached. This renders the original patch 4/4 valid again. > Note for some later improvement: I really wonder why we don't store > the absolute POSIX path of the current executable globally yet... Same here. Thanks! /haubi/ >From f7255edd33cb4abe34f27188aab8dccdfa5dd2a0 Mon Sep 17 00:00:00 2001 From: Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com> Date: Wed, 31 Aug 2016 18:05:11 +0200 Subject: [PATCH 3/4] dlopen: on x/lib search x/bin if exe is in x/bin citing https://cygwin.com/ml/cygwin-developers/2016-08/msg00020.html > Consider the file /usr/bin/cygz.dll: > - dlopen (libz.so) success > - dlopen (/usr/bin/libz.so) success > - dlopen (/usr/lib/libz.so) fails * dlfcn.c (dlopen): For dlopen("x/lib/N"), when the application executable is in "x/bin/", search for "x/bin/N" before "x/lib/N".
2016-09-08dlopen: switch to new pathfinder classMichael Haubenwallner1-109/+201
Instead of find_exec, without changing behaviour use new pathfinder class with new allocator_interface around tmp_pathbuf and new vstrlist class. * pathfinder.h (pathfinder): New file. * vstrlist.h (allocator_interface, allocated_type, vstrlist): New file. * dlfcn.cc (dlopen): Avoid redundant GetModuleHandleExW with RTLD_NOLOAD and RTLD_NODELETE. Switch to new pathfinder class, using (tmp_pathbuf_allocator): New class. (get_full_path_of_dll): Drop.
2016-06-23Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout optioncygwin-2_5_2-releaseCorinna Vinschen1-3/+0
Bump GPLv2+ to GPLv3+ for some files, clarify BSD 2-clause. Everything else stays under GPLv3+. New Linking Exception exempts resulting executables from LGPLv3 section 4. Add CONTRIBUTORS file to keep track of licensing. Remove 'Copyright Red Hat Inc' comments. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-06-01dlopen: Add dot to filename if no slash is presentCorinna Vinschen1-1/+1
We're appending a dot to the filename before calling LoadLibrary to override ".dll" automagic. This only worked for paths, not for simple filenames since it required a slash in the pathname. Fix that. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-02-11 * dlfcn.cc (check_path_access): Drop FE_NATIVE from find_exec call.Corinna Vinschen1-3/+3
(gfpod_helper): Drop equality sign from environment variable name in call to check_path_access. * exec.cc (execlp): Drop equality sign from environment variable name in call to find_exec. (execvp): Ditto. (execvpe): Ditto. * path.h (enum fe_types): Drop FE_NATIVE. (find_exec): Rename third paramter in declaration from search. Drop equality sign from default value. * spawn.cc (perhaps_suffix): Add PC_POSIX to path_conv::check call. (find_exec): Simplify function. Iterate over POSIX pathlist rather than Windows pathlist. Drop handling of FE_NATIVE flag. Always fill posix path of incoming path_conv buf, unless FE_NNF flag is given. (av::setup): Drop equality sign from environment variable name in call to find_exec. Call unshift with normalized_path. * winf.cc (av::unshift): Drop conv parameter and code converting Windows to POSIX path. * winf.h (av::unshift): Accommodate prototype.
2014-10-27 * dlfcn.cc (dlopen): Drop patch accommodating SetDllDiretory fromCorinna Vinschen1-28/+1
2014-10-14.
2014-10-17 * cygheap.cc (cygheap_fixup_in_child): Call set_dll_dir.Corinna Vinschen1-4/+4
(init_cygheap::init_installation_root): Just memmove contents of installation_root instead of calling GetModuleFileNameW again. Copy installation_root to installation_dir before stripping of "bin" dir. Don't call SetDllDirectory here. Explain what we do. (setup_cygheap): New function taking over initial cygheap setup from memory_init. Additionally call set_dll_dir. * cygheap.h (struct init_cygheap): Add installation_dir member. (init_cygheap::set_dll_dir): Define. (setup_cygheap): Declare. * dcrt0.cc: Throughout drop parameter from memory_init call. (dll_crt0_0): Call setup_cygheap prior to memory_init. * dlfcn.cc (dlopen): Change comment to point to the right function. * shared.cc (memory_init): Drop parameter. Drop cygheap setup. * shared_info.h (memory_init): Change declaration accordingly.
2014-10-14 * cygheap.cc (init_cygheap::init_installation_root): Install Cygwin'sCorinna Vinschen1-1/+32
installation dir as DLL search path, instead of ".". * cygheap.h (class cwdstuff): Add parameter names in function declarations for readability. (cwdstuff::get): Ad inline implementation fetching the CWD as wide char string. * dlfcn.cc (dlopen): Add searching for dependent DLLs in DLL installation dir or CWD, if all else failed. Add comment to explain scenarios this is accommodating.
2014-10-12 * dlfcn.cc (gfpod_helper): Only check for POSIX dir separator, same asCorinna Vinschen1-1/+1
in get_full_path_of_dll.
2014-10-12 * dlfcn.cc (set_dl_error): Drop useless __stdcall.Corinna Vinschen1-14/+13
(check_path_access): Ditto. Drop FE_CWD from call to find_exec. (gfpod_helper): Call path_conv::check for all paths containing a dir separator to more closely follow the Linux search algorithm. (get_full_path_of_dll): Drop useless __stdcall. (dlopen): Simplify RTLD_NOLOAD case by calling GetModuleHandleEx instead of GetModuleHandle/LoadLibrary.
2014-10-10 * dlfcn.cc (dlopen): Disable old 32 bit code on 64 bit.Corinna Vinschen1-0/+4
* dcrt0.cc (check_sanity_and_sync): Ditto. * dll_init.cc (dll_dllcrt0_1): Fix typo in comment.
2013-04-23 * Merge in cygwin-64bit-branch.Corinna Vinschen1-28/+4
2013-01-21Throughout, update copyrights to reflect dates which correspond to main-branchChristopher Faylor1-2/+2
checkins. Regularize copyright format.
2011-09-01 * dlfcn.cc (gfpod_helper): Helper function to search DLL usingCorinna Vinschen1-6/+46
a given DLL name. Change default search path to allow /usr/bin. (get_full_path_of_dll): Find DLLs even if the caller used a ".so" suffix or a "lib" prefix for the DLL.
2011-08-16 * dlfcn.cc (dlopen): Reimplement RTLD_NODELETE for Windows 2000 usingCorinna Vinschen1-6/+21
internal datastructures. Explain the code. * ntdll.h (struct _LDR_DATA_TABLE_ENTRY): Define. (struct _PEB_LDR_DATA): Define. (struct _PEB): Change PVOID LoaderData to PPEB_LDR_DATA Ldr. * fhandler_process.cc (format_process_maps): Call NtQueryVirtualMemory with valid return length pointer. Explain why.
2011-08-16 * autoload.cc (GetModuleHandleExW): Define.Corinna Vinschen1-11/+25
* dlfcn.cc: Throughout mark exported symbols as extern "C". (dlopen): Unignore flags argument. Define ret to NULL. Fix typo in comment. Support Glibc flags RTLD_NOLOAD and RTLD_NODELETE. * include/dlfcn.h: Clean up comments. (RTLD_NODELETE): Define. (RTLD_NOLOAD): Define. (RTLD_DEEPBIND): Define.
2011-06-06whitespace eliminationChristopher Faylor1-1/+1
2011-05-11 * autoload.cc (EnumProcessModules): Remove.Corinna Vinschen1-15/+37
* dlfcn.cc (dlopen): Make sure errno is set if an error occurs. (dlsym): Rewrite using RtlQueryProcessDebugInformation instead of EnumProcessModules. * ntdll.h (struct _DEBUG_MODULE_ARRAY): Define. (RtlCreateQueryDebugBuffer): Declare. (RtlDestroyQueryDebugBuffer): Declare. (RtlQueryProcessDebugInformation): Declare.
2010-06-14 * dlfcn.cc (get_full_path_of_dll): Revert patch from 2010-04-29.Corinna Vinschen1-2/+2
2010-04-29 * dlfcn.cc (get_full_path_of_dll): Handle non-existent file.Corinna Vinschen1-2/+2
2010-02-28Update some copyrights.Christopher Faylor1-12/+4
* cygtls.cc (_cygtls::call): Invoke new exception protection here. (_cygtls::init_thread): Remove conditionalized exception handler setup. (exception_list): Delete declaration. (_cygtls::init_exception_handler): Delete obsolete function. * cygtls.h: Remove (now) unneeded include. (_cygtls): Make this a real C++ class. (_cygtls::handle_exceptions): Remove. (_cygtls::init_exception_handler): Remove. (_cygtls::call2): Make private. (myfault::faulted): Remove unneeded parentheses. * dcrt0.cc (dll_crt0_1): Remove exception handler setup. * dlfcn.cc (dlopen): Ditto. (dlclose): Ditto. * dll_init.cc (dll_dllcrt0_1): Ditto. (dll_list::detach): Use new exception handler protection. * exceptions.cc (dump_exception): Rename to prevent confusion with new class. (exception::handle): Rename from _cygtls::handle_exceptions. Accommodate new exception class. Accommodate rename to dump_exception. * tlsoffsets.h: Regenerate.
2010-02-26* cygtls.h (_cygtls::init_exception_handler): Eliminate argument.Christopher Faylor1-3/+12
(_cygtls::andreas): Convert to a pointer. (san): Convert to a real class with methods. Use a linked list to keep track of previous handlers on the "stack". (myfault): Rewrite to use new san class rather than calling directly into _cygtls. * cygtls.cc (_cygtls::init_exception_handler): Just assume that we're always using the standard exception handler. (_cygtls::init_thread): Reflect loss of argument to init_exception_handler. * dcrt0.cc (dll_crt0_1): Ditto. * dfcn.cc (dlopen): Ditto. (dlclose): Reset the exception handler after FreeLibrary. * dll_init.cc (dll_list::detach): Make sure that the exception handler is initialized before calling destructors. * exceptions.cc (_cygtls::handle_exceptions): Accommodate new andreas pointer. * thread.cc (verifyable_object_isvalid): Pass objectptr to faulted for explicit NULL pointer checking. * tlsoffsets.h: Regenerate.
2010-02-24* dlfcn.cc (dlopen): Make sure exception handler is really loaded after dynamicChristopher Faylor1-0/+3
load.
2009-11-02 * dlfcn.cc (get_full_path_of_dll): Drop enforcing a .dll suffix.Corinna Vinschen1-9/+6
(dlopen): If last path component has no dot, append one to override automatic .dll suffix in LoadLibrary.
2009-08-13 * cxx.cc (default_cygwin_cxx_malloc): Enhance commenting.Corinna Vinschen1-0/+21
* dll_init.cc (dll_dllcrt0_1): Likewise. * dlfcn.cc (dlopen): Prevent dlopen()'d DLL from installing any cxx malloc overrides. * include/cygwin/cygwin_dll.h (__dynamically_loaded): New variable. * lib/_cygwin_crt0_common.cc (_cygwin_crt0_common): Check it and only install cxx malloc overrides when statically loaded. Extend comments.
2009-04-16 * dlfcn.cc (get_full_path_of_dll): Just return a bool value. DropCorinna Vinschen1-23/+23
local path_conv in favor of getting it as parameter. Add local string buffer instead of getting it as parameter. (dlopen): Accommodate get_full_path_of_dll change. Fetch WCHAR Windows path from path_conv variable and call LoadLibraryW.
2009-03-19 * dlfcn.cc (get_full_path_of_dll): Revert patch from 2008-07-16.Corinna Vinschen1-2/+2
2008-07-16 Add case-sensitivity.Corinna Vinschen1-1/+1
Unconditionally handle mount points case-sensitive. Unconditionally handle virtual paths case-sensitive. Unconditionally handle registry paths case-insensitive. Otherwise, accommodate case-sensitivity of given path throughout. * cygheap.cc (cygheap_root::set): Get additional caseinsensitive parameter and store it. * cygheap.h (struct cygheap_root_mount_info): Add member caseinsensitive. * dlfcn.cc (get_full_path_of_dll): Drop PC_NOFULL parameter from call to path_conv::check. * environ.cc (pcheck_case): Remove. (check_case_init): Remove. (known): Drop "check_case" option. * exceptions.cc (open_stackdumpfile): Add comment. * fhandler.cc (fhandler_base::get_default_fmode): Call pathmatch instead of strcasematch. * fhandler_disk_file.cc: Accommodate case-sensitivity of given path throughout. (__DIR_mounts::check_mount): Unconditionally check virtual paths case-sensitive. (fhandler_disk_file::link): Drop case clash handling. (fhandler_disk_file::open): Ditto. (fhandler_disk_file::readdir_helper): Drop managed mount code. * mount.cc: Remove managed mount code and datastructures. (struct opt): Remove "managed" option. Add "posix=0" and "posix=1" options. (fillout_mntent): Remove "managed" output. Add "posix" output. * path.cc (struct symlink_info): Remove case_clash member and case_check method. (pcheck_case): Remove. (path_prefix_p): Take additional bool parameter "caseinsensitive". (pathnmatch): Ditto. (pathmatch): Ditto. (mkrelpath): Ditto. (fs_info::update): Set caseinsensitive flag according to file system name and FILE_CASE_SENSITIVE_SEARCH flag. Add comment. (tfx_chars_managed): Remove. (transform_chars): Drop "managed" parameter. Always use tfx_chars. (get_nt_native_path): Drop "managed" parameter. Make sure drive letters are always upper case. (getfileattr): Change second parameter to denote caseinsensitivity. (path_conv::check): Initialize caseinsensitive to OBJ_CASE_INSENSITIVE. Set caseinsensitive according to global obcaseinsensitive flag, file system case sensitivity and MOUNT_NOPOSIX mount flag. Drop case_clash and all the related code. (symlink_worker): Drop case clash handling. (symlink_info::set): Drop setting case_clash. (symlink_info::case_check): Remove. (cwdstuff::set): Add comment. (etc::init): Take path_conv instead of PUNICODE_STRING as parameter to allow case sensitivity. * path.h (enum pathconv_arg): Drop PC_SYM_IGNORE. (enum case_checking): Remove. (enum path_types): Drop PATH_ENC, add PATH_NOPOSIX flag. (struct fs_info): Add caseinsensitive flag and accessor methods. (class path_conv): Add caseinsensitive member and define objcaseinsensitive method. Drop case_clash member and isencoded method. (pathmatch): Change prototype according to above change. (pathnmatch): Ditto. (path_prefix_p): Ditto. (get_nt_native_path): Ditto. (class etc): Ditto. (fnunmunge): Remove prototype. * shared.cc (shared_info::init_obcaseinsensitive): Initialize obcaseinsensitive flag from obcaseinsensitive registry value. (shared_info::initialize): Call init_obcaseinsensitive here by the first process creating the shared memory. * shared_info.h (mount_item::fnmunge): Remove. (shared_info::obcaseinsensitive): Rename from obcaseinsensitivity. (shared_info::init_obcaseinsensitive): Declare. * syscalls.cc (try_to_bin): Add comment. * include/sys/mount.h (MOUNT_ENC): Remove flag. (MOUNT_NOPOSIX): Add flag.
2008-04-07Remove unneeded header files from source files throughout.Christopher Faylor1-7/+0
2008-04-01 * Fix copyright dates.Corinna Vinschen1-1/+1
2008-03-11 * dlfcn.cc (get_full_path_of_dll): Allow paths up to PATH_MAX.Corinna Vinschen1-2/+4
(dlopen): Call get_full_path_of_dll with path buffer allocate by tmp_pathbuf.
2007-08-16 * path.h (path_conv::operator char *): Delete.Corinna Vinschen1-1/+1
(path_conv::operator const char *): Delete. * dlfcn.cc: Throughout, replace path_conv::operator char * and path_conv::operator const char * by call to path_conv::get_win32 for easier transition to UNICODE_PATHs. * fhandler_socket.cc: Ditto. * hookapi.cc: Ditto. * path.cc: Ditto. * spawn.cc: Ditto. * syscalls.cc: Ditto. * uinfo.cc: Ditto.
2007-07-10* debug.cc (close_handle): Change debug output format slightly.Christopher Faylor1-3/+1
* dlfcn.cc (dlclose): Don't close handle returned from GetModuleHandle(NULL). * fhandler.h (fhandler_pipe::create): Remove obsolete argument. (fhandler_pipe::create): Ditto. * fhandler.cc (fhandler_pipe::create): Ditto. (fhandler_pipe::create): Ditto.
2006-01-31 * dlfcn.cc (check_path_access): Call find_exec with FE_DLL option.Corinna Vinschen1-1/+1
* path.h (enum fe_types): Add FE_DLL value. * spawn.cc (std_suffixes): Remove. (exe_suffixes): New suffix_info for executing files. (dll_suffixes): New suffix_info for searching shared libraries. (perhaps_suffix): Add opt argument. Use dll_suffixes if FE_DLL option is given, exe_suffixes otherwise. (find_exec): Propagate opt argument to perhaps_suffix. Drop suffix check when testing execute permission. (spawn_guts): Call perhaps_suffix with FE_NADA opt argument.
2005-08-12white spaceChristopher Faylor1-1/+1
2005-06-04* dcrt0.cc (cygwin_dll_init): Now initializes main_environ and cygtls. CommentChristopher Faylor1-2/+2
to explain the caveats of this method. * how-cygtls-works.txt: New file.
2005-05-30* dlfcn.cc (set_dl_error): Use UNIX error rather than Windows error.Christopher Faylor1-1/+1
2005-05-22* spawn.cc (find_exec): Accept a PATH-like string in place of an environmentChristopher Faylor1-1/+2
variable. * dlfcn.cc (get_full_path_of_dll): Search /usr/bin (for windows compatibility) and /usr/lib (for UNIX compatibility) when looking for shared libraries. * environ.cc (conv_envvars): Put back LD_LIBRARY_PATH since it is used by get_full_path_of_dll(). * errno.cc (errmap): Map MOD_NOT_FOUND to ENOENT. * cygmagic: Remove debugging cruft.
2005-05-02white space and minor comment cleanup.Christopher Faylor1-8/+8
2005-04-03 Unify usage of CYG_MAX_PATH throughout. Change buffers fromCorinna Vinschen1-1/+1
size CYG_MAX_PATH + 1 to CYG_MAX_PATH. Change length tests accordingly.
2005-01-12Reorganize header file inclusion throughout so that cygerrno.h comes first.Christopher Faylor1-1/+1
* fhandler.h (select_record::thread_errno): Save any encountered errno here. (select_record::set_select_errno): New function. (select_record::saw_error): New function. (select_record::select_record): Initialize thread_errno to zero. * select.cc (set_handle_or_return_if_not_open): Set thread_errno on failure. (select_stuff::wait): Record errno for later resurrection in calling thread. (peek_serial): Ditto.
2004-09-14 * autoload.cc (EnumProcessModules): Add.Corinna Vinschen1-1/+22
* dlfcn.cc (dlsym): Handle RTLD_DEFAULT using EnumProcessModules(). * include/dlfcn.h (RTLD_DEFAULT): Define to NULL.
2004-09-03Regularize most strace_prints throughout so that %E is always preceded by aChristopher Faylor1-1/+1
comma and elminate most uses of "foo = %s" to "foo %s".