Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2019-02-03forkables: hardlink without WRITE_ATTRIBUTES firsttopic/forkablesMichael Haubenwallner
When the current process has renamed (to bin) a readonly dll, we get STATUS_TRANSACTION_NOT_ACTIVE for unknown reason when subsequently creating the forkable hardlink. A workaround is to open the original file with FILE_WRITE_ATTRIBUTES access, but that fails with permission denied for users not owning the original file. * forkable.cc (dll::create_forkable): Retry hardlink creation using the original file's handle opened with FILE_WRITE_ATTRIBUTES access when the first attempt fails with STATUS_TRANSACTION_NOT_ACTIVE.
2019-02-03forkables: inline dll_list::forkables_supportedMichael Haubenwallner
And LONG fits better for shared_info member forkable_hardlink_support.
2019-02-03forkables: simplify disabling via shmMichael Haubenwallner
* Rename cygwin_shared->prefer_forkable_hardlinks to forkable_hardlink_support, with values 0 for Unknown, 1 for Supported, -1 for Unsupported. Upon first dll loaded ever, dll_list::forkable_ntnamesize checks the /var/run/cygfork directory to both exist and reside on NTFS, setting cygwin_shared->forkable_hardlink_support accordingly. * Replace enum forkables_needs by bool forkables_created: Set to True by request_forkables after creating forkable hardlinks.
2019-02-03forkables: use dynloaded dll's IndexNumber as dirnameMichael Haubenwallner
2019-02-03forkables: Keep hardlinks disabled via shared mem.Michael Haubenwallner
To avoid the need for each process to check the filesystem to detect that hardlink creation is impossible or disabled, cache this fact in shared memory. Removing cygfork directory while in use does disable hardlinks creation. To (re-)enable hardlinks creation, the cygfork directory has to exist before the first cygwin process does fork. * forkable.cc (dll_list::forkable_ntnamesize): Short cut forkables needs to impossible when disabled via shared memory. (dll_list::update_forkables_needs): When detecting hardlink creation as impossible (not on NTFS) while still (we are the first one checking) enabled via shared memory, disable the shared memory value. (dll_list::request_forkables): Disable the shared memory value when hardlinks creation became disabled, that is when the cygfork directory was removed. * include/cygwin/version.h: Bump CYGWIN_VERSION_SHARED_DATA 6. * shared_info.h (struct shared_info): Add member prefer_forkable_hardlinks. Update CURR_SHARED_MAGIC. * shared.cc (shared_info::initialize): Initialize prefer_forkable_hardlinks to 1 (Yes).
2019-02-03forkables: On fork failure, retry with hardlinks.Michael Haubenwallner
To support in-cygwin package managers, the fork() implementation must not rely on .exe and .dll files to stay in their original location, as the package manager's job is to replace these files. Instead, when the first fork try fails, and we have NTFS, we use hardlinks to the original binaries in /var/run/cygfork/ to create the child process during the second fork try, along the main.exe.local file to enable the "DotLocal Dll Redirection" feature for the dlls. The (probably few) users that need an update-safe fork manually have to create the /var/run/cygfork/ directory for now, using: mkdir --mode=a=rwxt /var/run/cygfork * child_info.h: Bump CURR_CHILD_INFO_MAGIC. (enum child_status): Add _CI_SILENTFAIL flag. (struct child_info): Add silentfail setter and getter. * winsup.h (child_copy): Add bool silentfail parameter. * cygheap.cc: Pass silentfail parameter to child_copy. * dcrt0.cc: Ditto. * dll_init.h (struct dll): Define public inline method forkedntname. (struct dll_list): Declare private method find_by_forkedntname. * dll_init.cc (struct dll_list): Implement find_by_forkedntname. (dll_list::alloc): Use find_by_forkedntname when in load after fork. (dll_list::load_after_fork_impl): Load dlls using dll::forkedntname. * fork.cc (frok::parent): Set silentfail child info flag. Pass silentfail parameter to child_copy. Use forkedntname of dlls.main_executable. (fork): When first dofork run failed and did not use forkables, run dofork again with_forkables set to true. (child_copy): Use debug_printf if silentfail is true, system_printf otherwise.
2019-02-03forkables: Create forkable hardlinks, yet unused.Michael Haubenwallner
In preparation to protect fork() against dll- and exe-updates, create hardlinks to the main executable and each loaded dll in subdirectories of /var/run/cygfork/, if that one exists on the NTFS file system. The directory names consist of the user sid, the main executable's NTFS IndexNumber, and the most recent LastWriteTime of all involved binaries (dlls and main executable). Next to the main.exe hardlink we create the empty file main.exe.local to enable dll redirection. The name of the mutex to synchronize hardlink creation/cleanup also is assembled from these directory names, to allow for synchronized cleanup of even orphaned hardlink directories. The hardlink to each dynamically loaded dll goes into another directory, named using the NTFS IndexNumber of the dll's original directory. * Makefile.in (DLL_OFILES): Add forkable.o. * dll_init.h (struct dll): Declare member variables fbi, fii, forkable_ntname. Declare methods nominate_forkable, create_forkable. (struct dll_list): Declare enum forkables_needs. Declare member variables forkables_dirx_size, forkables_dirx_ntname, forkables_mutex_name, forkables_mutex. Declare private methods forkable_ntnamesize, prepare_forkables_nomination, update_forkables_needs, update_forkables, create_forkables, denominate_forkables, close_mutex, try_remove_forkables, set_forkables_inheritance, request_forkables. Declare public static methods ntopenfile, read_fii, read_fbi. Declare public methods release_forkables, cleanup_forkables. Define public inline method setup_forkables. * dll_init.cc (dll_list::alloc): Allocate memory to hold the name of the hardlink in struct dll member forkable_ntname. Initialize struct dll members fbi, fii. (dll_list::load_after_fork): Call release_forkables method. * fork.cc: Rename public fork function to static dofork, add with_forkables as bool pointer parameter. Add new fork function calling dofork. (struct frok): Add bool pointer member with_forkables, add as constructor parameter. (frok::parent): Call dlls.setup_forkables before CreateProcessW, dlls.release_forkables afterwards. * pinfo.cc (pinfo::exit): Call dlls.cleanup_forkables. * syscalls.cc (_unlink_nt): Rename public unlink_nt function to static _unlink_nt, with 'shareable' as additional argument. (unlink_nt): New, wrap _unlink_nt for original behaviour. (unlink_nt_shareable): New, wrap _unlink_nt to keep a binary file still loadable while removing one of its hardlinks. * forkable.cc: New file. Implement static functions mkdirs, rmdirs, rmdirs_synchronized, stat_real_file_once, format_IndexNumber, rootname, sidname, exename, lwtimename. Define static array forkable_nameparts. (struct dll): Implement nominate_forkable, create_forkable. (struct dll_list): Implement static methods ntopenfile, read_fii, read_fbi. Implement forkable_ntnamesize,
2019-02-03dll_list: Track main executable and cygwin1.dll.Michael Haubenwallner
Even for the main executable and cygwin1.dll store the file name as full NT path. Create the child process using the main executable's file name converted from the full NT path stored before. * dll_init.cc (dll_list::alloc): Search for DLL_SELF type entry with module name like for DLL_LINK, use full NT path to search for DLL_LOAD type only. For DLL_SELF type do not indicate having a destructor to be called. (dll_list::find): Ignore DLL_SELF type entries. (dll_list::init): Ditto. Call track_self method. (dll_list::track_self): New. (dll_list::load_after_fork): Call track_self method. * dll_init.h (enum dll_type): Add DLL_SELF, for the main executable and cygwin1.dll. (struct dll_list): Declare private method track_self. Declare member variable main_executable. * fork.cc (frok::parent): Use ntname from dlls.main_executable to create child process, converted to short path using dll_list::buffered_shortname.
2019-02-03dll_list: Store dll file name as full NT path.Michael Haubenwallner
Store loaded dll's file name as full NT path. * dll_init.h (struct dll): Rename member variable name to ntname. (struct dll_list): Declare private static member variable nt_max_path_buffer. Declare public static methods form_ntname, form_shortname. Define public static methods nt_max_path_buf, buffered_shortname. (dll_list::operator []): Use PCWCHAR rather than const PWCHAR. (dll_list::find_by_modname): Ditto. * dll_init.cc (in_load_after_fork): Define earlier in file. (struct dll_list): Rename member variable name to ntname. Define nt_max_path_buffer variable. Implement static methods form_ntname, form_shortname. (dll_list::operator []): Use PCWCHAR rather than const PWCHAR. (dll_list::find_by_modname): Ditto. (reserve_at): Ditto. (release_at): Ditto. (dll_list::alloc): Use nt_max_path_buf method instead of local buffer. Store module file name as full NT path, convert using the form_ntname static method. (dll_list::load_after_fork): Call load_after_fork_impl only when reload_on_fork is set. * fork.cc (frok::child): Call dlls.load_after_fork even without need to dynamically load dlls. (frok::parent): Move syscall_printf into the retry loop.
2019-02-02Cygwin: tweak Cygwin PID change release noteCorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02Cygwin: kill(1): introduce a -W optionCorinna Vinschen
Allow to kill processes using Windows PIDs on the command line. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02Cygwin: spawn: create and maintain winpid symlinksCorinna Vinschen
- If the execve'ed process is a non-Cygwin process, we have to create the matching winpid symlink and remove the old one ourselves. - If we spawn a child, the winpid symlink has to be maintained by the child process, otherwise it disappears if the parent process exits. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02Cygwin: pinfo: simplify create_winpid_symlinkCorinna Vinschen
The arguments are not used anyway, so drop them. When called, procinfo->dwProcessId is already set right, so we don't have to access myself_initial. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02Cygwin: Makefile.in: Fix previous version info generation fixCorinna Vinschen
Commit 231ad6941f9ade7bde67d27929da5a776ebd9457 looks good... as long as you never build Cygwin from scratch. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02Cygwin: processes: fix handling of native Windows processesCorinna Vinschen
Since commit b5e1003722cb14235c4f166be72c09acdffc62ea, native Windows processes not started by Cygwin processes don't have a Cygwin PID anymore. This breaks ps -W and kill -f <WINPID>. Introduce MAX_PID (65536 for now). Cygwin processes as well as native Windows processes started from a Cygwin process get a PID < MAX_PID. All other native Windows processes get a faked Cygwin PID >= MAX_PID. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02Cygwin: Makefile.in: Fix another dependency problem in version infoCorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-01Cygwin: processes: use dedicated Cygwin PID rather than Windows PIDCorinna Vinschen
Using the Windows PID as Cygwin PID has a few drawbacks: - the PIDs on Windows get reused quickly. Some POSIX applications choke on that, so we need extra code to avoid too quick PID reuse. - The code to avoid PID reuse keeps parent process handles and (depending on a build option) child processes open unnecessarily. - After an execve, the process has a split personality: Its Windows PID is a new PID, while its Cygwin PID is the PID of the execve caller process. This requires to keep two procinfo shared sections open, the second just to redirect process info requests to the first, correct one. This patch changes the way Cygwin PIDs are generated: - Cygwin PIDs are generated independently of the Windows PID, in a way expected by POSIX processes. The PIDs are created incrementally in the range between 2 and 65535, round-robin. - On startup of the first Cygwin process, choose a semi-random start PID for the first process in the lower PID range to make the PIDs slightly unpredictable. This may not be necessary but it seems kind of inviting to know that the first Cygwin process always starts with PID 2. - Every process not only creates the shared procinfo section, but also a symlink in the NT namespace, symlinking the Windows PID to the Cygwin PID. This drops the need for the extra procinfo section after execve. - Don't keep other process handles around unnecessarily. - Simplify the code creating/opening the shared procinfo section and make a clear distinction between interfaces getting a Cygwin PID and interfaces getting a Windows PID. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-01Cygwin: remove outdated vfork docCorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-01Cygwin: /proc: don't exit prematurely from /proc/PID/statusCorinna Vinschen
If a process is just exiting, requesting memory info may fail with STATUS_PROCESS_IS_TERMINATING. Right now the code just bails out if fetching mem info fails. However, the rest of the info is still valuable for procps, so just carry on. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-01Cygwin: Add pthread exception handling patch to release notesCorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-30Cygwin: x86_64: pthreads: Install exception handler after switching stackCorinna Vinschen
After creating a pthread, the stack gets moved to the desired memory location. While the 32 bit thread wrapper copies the exception handler information to the new stack (so we have at least *some* exception handler present), the x86_64 code didn't perform any exception handler magic. Fix that. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-30Cygwin: fork: fix child process permissions, take 2Corinna Vinschen
VirtualQueryEx, called by fixup_mmaps_after_fork, requires PROCESS_QUERY_INFORMATION permissions per MSDN. However, testing shows that PROCESS_QUERY_LIMITED_INFORMATION is sufficient when running the same code on Windows 8.1 or Windows 10. Fix the code to give the forked child always PROCESS_QUERY_INFORMATION perms on Windows Vista/7 and respective server releases. Revert now unneeded patch to check_token_membership as well. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-30Cygwin: raise: change to call pthread_killCorinna Vinschen
POSIX requires that raise(3) is equivalent to pthread_kill(pthread_self(), sig); in multi-threaded applications. Our raise just called kill(sig). Fix that. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-29Cygwin: execve: reduce parent handle to non-inheritable SYNCHRONIZECorinna Vinschen
Keeping an inheritable handle open results in that handle being spilled over into grandchild processes, which is not desired. Duplicate original parent handle into a non-inheritable one with minimal SYNCHRONIZE permissions and close the original handle. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-29Cygwin: fork/exec: fix child process permissionsCorinna Vinschen
- Exec'ed/spawned processes don't need PROCESS_DUP_HANDLE. Remove that permission from the parent handle. - PROCESS_QUERY_LIMITED_INFORMATION doesn't work for Windows 7 if the process is started as a service. Add PROCESS_QUERY_INFORMATION for pre-Windows 8 in that case. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-29Cygwin: Makefile.in: Improve dependency for version infoCorinna Vinschen
The version info only depends on the object files. This results in the version info not being rebuild immediately if a source file is changed. Rather, the version info is only rebuilt on the next make run. Fix that by making the version info build rule dependent on the source files. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-28Cygwin: procfd: improve debug outputCorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-28Cygwin: seteuid: disable unused funcs and lsaauth subdirCorinna Vinschen
If S4U proves to be usable alone, remove this code entirely. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-28Cygwin: spawn: revert incorrect restriction of permissionsCorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-27Cygwin: fork: restrict parent handle perms and drop handle after useCorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26Cygwin: seteuid: use Kerberos/MsV1_0 S4U authentication by defaultCorinna Vinschen
- This simple and official method replaces cyglsa and "create token" methods. No network share access, same as before. - lsaauth and create_token are disabled now. If problems crop up, they can be easily reactivated. If no problems crop up, they can be removed in a while, together with the lsaauth subdir. - Bump Cygwin version to 3.0. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26Cygwin: uname: Raise size of utsname fields and revamp uname(2) outputCorinna Vinschen
New format: sysname: CYGWIN_NT-${osversion}-${os_build_number}[-WOW64] nodename: `gethostname` release: ${cygwin_version}-${API minor}.${arch}[.snap] version: YYYY-MM-DD HH:MM UTC machine: ${arch} _GNU_SOURCE: domainname: `getdomainname` !_GNU_SOURCE: __domainname: `getdomainname` Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26Cygwin: netdb.h: fix __GNU_VISIBLE testsCorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26Cygwin: create_token: Return NULL, not INVALID_HANDLE_VALUECorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26Cygwin: syscalls.cc: fix formattingCorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26Cygwin: lsaauth: Drop outdated test for loading Secur32.dllCorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24Cygwin: seteuid: work with password-less user switch as wellCorinna Vinschen
The previous patch failed with password-less auth because in that case the return code from get_server_groups wasn't tested. Fix that. Also make sure that get_server_groups does not check if the account is disabled or locked out when just fetching the group list for initgroups or getgrouplist. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24Cygwin: seteuid: refuse changing uid to disabled or locked out userCorinna Vinschen
So far seteuid could change uid to any existing account, given sufficient permissions of the caller. This is kind of bad since it disallows admins to refuse login to disabled or locked out accounts. Add check for the account's UF_ACCOUNTDISABLE or UF_LOCKOUT flags and don't let the user in, if one of the flags is set. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24Cygwin: net: unify gethostname/getdomainnameCorinna Vinschen
Use info from same source (GetNetworkParams). Also move getdomainname near gethostname in source. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24Cygwin: gethostname: fix fetching hostname from non-winsock functionCorinna Vinschen
If gethostname() fails we call GetComputerNameEx with ComputerNameDnsFullyQualified. This is wrong, gethostname should return the hostname only, not the FQDN. Fix this by calling GetComputerNameEx with ComputerNameDnsHostname. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24Cygwin: version: Use UTC timestamp as build timeCorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-23Cygwin: cygthread: set thread name before calling thread funcCorinna Vinschen
When reusing a cygthread, the stub method fails to set the thread name to the new name. The name is only set when actually creating the thread. Fix that by moving the SetThreadName call right in front of the thread function call. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-23Remove matherr, and SVID and X/Open math library configurationsJozef Lawrynowicz
Default math library configuration is now IEEE
2019-01-22Cygwin: posix timers: fix overrun count always being 1 too bigCorinna Vinschen
Combine with a bit of cleanup: - Drop overrun_event_running in favor of overrun_count being -1. - Fix include guard in posix_timer.h. - Drop ununsed function timespec_to_us. - Don't use Interlocked functions without need. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22Cygwin: posix timers: fix error handling in public APICorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22Cygwin: posix timers: allocate timer_tracker on system heap.Corinna Vinschen
Allocating on the cygheap would copy information of the tracker into the child process. A forked child knows the timer id and could simply still access the (free'd but still valid) timer_tracker on the heap, which is dangerous and very certainly doesn't reflect POSIX semantics. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22Cygwin: timerfd: Add support for CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARMCorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22Cygwin: posix timers: Add support for CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARMCorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22Cygwin: clocks: Add CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARM clocksCorinna Vinschen
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22Cygwin: posix timers: reimplement using OS timerCorinna Vinschen
- Rename files timer.* to posix_timer.*. - Reimplement using an OS timer rather than a handcrafted wait loop. - Use a Slim R/W Lock for synchronization. - Drop timer chaining. It doesn't server a purpose since all timers are local only. - Rename ttstart to itimer_tracker to better reflect its purpose. It's not the anchor for a timer chain anymore anyway. - Drop fixup_timers_after_fork. Everything is process-local, nothing gets inherited. - Rename timer_tracker::disarm_event to disarm_overrun_event for better readability. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>