aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin
AgeCommit message (Collapse)AuthorFilesLines
2024-01-31Cygwin: posix_getdents: implement per SUS Base Specifications Issue 8 draftCorinna Vinschen8-8/+128
- Basically maintain a hidden DIR* inside fhandlers. - lseek has to be tweaked to allow basic seeking on the directory descriptor. - the current implementation does not keep the dir positions between duplicated descriptor in sync. In fact, every descriptor keeps its own copy of the DIR* and after dup/fork/exec, the directory position is reset to 0, i. e., to the start of the directory, as if rewinddir() has been called on the new descriptors. While this behaviour isn't yet covered by the Issue 8 draft, a bug report along these lines exists and will probably be picked up for TC1. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31Cygwin: devices.h: drop useless mode checkCorinna Vinschen1-4/+1
use IFTODT to generate type from mode. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31Cygwin: dirent.h: make definition of struct __DIR opaqueCorinna Vinschen2-16/+32
The content of DIR should never have been exposed into userspace. Move struct __DIR to local dirent.h and only keep forward declaration in exported dirent.h. This allows to tweak the structure in future, for instance, to add thread-safety. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31Cygwin: implement fdclosedirCorinna Vinschen4-7/+33
fdclosedir is BSD-only but already present in dirent.h for a couple of years. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31Cygwin: implement dirent.d_reclenCorinna Vinschen3-8/+23
This change is in preparation of adding posix_getdents() from the upcoming POSIX Base Specification Issue 8. - Add d_reclen - Add GLibC compatible test macros for dirent members - Bump dirent version - Set d_reclen to the fixed size of the dirent struct We can do that because the size is a multiple of 8, so it fits snugly in the buffer filled by posix_getdents and keep the alignement. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31Cygwin: export getlocalename_lCorinna Vinschen3-1/+11
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31Cygwin: path: convert symlink_info to classCorinna Vinschen1-140/+165
encapsulate everything Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31Cygwin: files: slightly simplify suffix handlingCorinna Vinschen3-32/+17
- drop appending .exe.lnk to files - drop exe_suffixes, it's the same as stat_suffixes for a long time Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-31Cygwin: bump DLL version to 3.6.0cygwin-3.6.0-devCorinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-29Cygwin: machine/_arc4random.h: Fix copy/paste bugCorinna Vinschen1-1/+0
Remove a stray __END_DECLS. It didn't hurt in the only (plain C) file including this header, but still... Fixes: 030a762535c1 ("Cygwin: fix arc4random after fork(2)") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-29Cygwin: fix arc4random after fork(2)Corinna Vinschen2-0/+17
After using fork(), arc4random does not reseed itself, which causes the results to become predictable. Activate droppingfork-recognition Fixes: e0fc33322d50 ("Delete Cygwin's arc4random in favor of new Newlib implementation") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-29Cygwin: redefine how to recognize forkee stateCorinna Vinschen5-16/+27
So far the global variable in_forkee only indicated if the process is the child process during fork(2) itself. However, we need an indicator accessible from plain C code in newlib, allowing to check for a process being a forked process all the time, after fork(2) succeeded. Redefine bool in_forkee to int __in_forkee to allow exposing it to newlib. Redefine how it indicates fork state (not forked, forking, forked). Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-25Cygwin: Add a timeout to ensure we don't wait forever for dumperJon Turney1-2/+6
2024-01-24Cygwin: pthread: Fix handle leak in pthread_once.Takashi Yano1-0/+3
If pthread_once() is called with pthread_once_t initialized using PTREAD_ONCE_INIT, pthread_once does not release pthread_mutex used internally. This patch fixes that by calling pthread_mutex_destroy() in the thread which has called init_routine. Reviewed-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-01-23Cygwin: Don't terminate via dumperJon Turney1-4/+3
A process which is exiting due to a core dumping signal doesn't propagate the correct exist status after dumping core, because 'dumper' itself forcibly terminates the process. Use 'dumper -n' to avoid killing the dumped process, so we continue to the end of signal_exit(), to exit with the 128+signal exit status. Busy-wait in exec_prepared_command() in an attempt to reliably notice the dumper attaching, so we don't get stuck there. Also: document these important facts for custom uses of error_start.
2024-01-23Cygwin: seekdir: don't set errnoCorinna Vinschen1-1/+0
Commit 3f3bd1010455 ("* Throughout, use __try/__except/__endtry blocks [...]") introduced setting EINVAL, marked as "Diagnosis". The reason for this is lost in time and space, but looks very much like a debug helper which was supposed to be removed before release. It's rather pointless, so remove it. Fixes: 3f3bd1010455 ("* Throughout, use __try/__except/__endtry blocks [...]") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-18Cygwin: replace all `fgrep' with `grep -F'Corinna Vinschen3-6/+6
Unfortunately fgrep is now deprecated in a very pushy way. Make sure to use grep -F instead all around, even in docs and comments/ Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-17Cygwin: copy doc changes from commit 241b50a7abe2 to release notesCorinna Vinschen1-4/+4
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-16Cygwin: Treat api_fatal() similarly to a core-dumping signalJon Turney3-5/+20
Provide the same debugging opportunities for api_fatal() as we do for a core-dumping signal: 1) Break into any attached debugger 2) Start JIT debugger (if configured) (keeping these under DEBUGGING doesn't seem helpful) 3) Write a coredump (if rlim_core > 1MB) 4) Write a stackdump (if that failed, or 0 < rlim_core <= 1MB)
2024-01-16Cygwin: Define and use __WCOREFLAGJon Turney2-3/+4
Also fix a typo in description of exit status
2024-01-16Cygwin: Disable writing core dumps by default.Jon Turney2-1/+4
Change the default core limit from unlimited to 0 (disabled)
2024-01-16Cygwin: Make 'ulimit -c' control writing a coredumpJon Turney4-19/+91
Pre-format a command to be executed on a fatal error to run 'dumper' (using an absolute path). Factor out executing a pre-formatted command, so we can use that for invoking the JIT debugger in try_to_debug() (if error_start is present in the CYGWIN env var) and to invoke dumper when a fatal error occurs. On a fatal error, if the core file size limit is greater than 1MB, invoke dumper to write a core dump. Otherwise, if that limit is greater than 0, write a .stackdump file, as previously. Adjust and clarify the associated documentation. Also: Fix so that the error_start JIT debugger is now invoked, even when ulimit -c is zero. Also: Fix uses of console_printf() inside exec_prepared_command(). It's output is written via the Windows console device, so needs to use Windows-style line endings. Also: consistently return non-zero from try_to_debug() if we debugged. Future work: Truncate or remove the file written, if it exceeds the maximum size set by the ulimit. Future work: Using the words "fatal error" could probably be improved on. This means exiting on one of the "certain signals whose default action is to cause the process to terminate and produce a core dump file".
2024-01-15Cygwin: introduce close_range(2)Christian Franke4-1/+47
This function closes or sets the close-on-exec flag for a specified range of file descriptors. It is available on FreeBSD and Linux. Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-01-11Cygwin: path.cc: fix comment starting with // but ending in */Corinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-08Cygwin: check remote drives for being SSDs as wellCorinna Vinschen1-1/+1
This enables automatic sparse file support for remote SSDs. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-12-05Cygwin: fallocate(2): fix debug outputCorinna Vinschen1-1/+1
Fixes: e01c50c7b0a6 ("Cygwin: introduce fallocate(2)") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-12-05Cygwin: fallocate(2): fix offset and length sanity checkCorinna Vinschen1-1/+3
- len must not be <= 0 - offset + len must not exceed off_t (max. file size) Fixes: e01c50c7b0a6 ("Cygwin: introduce fallocate(2)") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-12-05Cygwin: posix_fallocate(3): fix offset and length sanity checkCorinna Vinschen1-1/+3
- len must not be <= 0 - offset + len must not exceed off_t (max. file size) Fixes: 7636b5859062 ("* autoload.cc (NtSetInformationFile): Define.") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-12-04Cygwin: fallocate(2): drop useless zeroing pointerCorinna Vinschen1-3/+1
The out pointer is only used if data_chunk_count is > 0, so there's no reason to set it to NULL in the error case. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-12-01Cygwin: drop stray fs_info::check_ssd declarationCorinna Vinschen1-2/+0
This is just a leftover from development Fixes: 8b01c5d6903f ("Cygwin: fs_info: check for SSD") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-30Cygwin: sparse support: enable automatic sparsifying of files on SSDsCorinna Vinschen2-2/+5
Given that SSDs don't have a seek penalty, we can enable automatic sparsifying of files on SSDs, even if the "sparse" mount option is not set. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-30Cygwin: fs_info: check for SSDCorinna Vinschen2-0/+18
During fs_info::update, check for the file being on an SSD. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-30Cygwin: ntdll.h: add missing NtQueryVolumeInformationFile definitionsCorinna Vinschen1-0/+27
In preparation of using the FileFsSectorSizeInformation info class, add a couple of missing definitions. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-30Cygwin: ntdll.h: add missing POBJECT_NAME_INFORMATIONCorinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-30Cygwin: revert autoloading of DiscardVirtualMemoryCorinna Vinschen1-0/+1
Commit a3ae2a734892 ("Cygwin: don't autoload some kernel32 functions") erroneously removed DiscardVirtualMemory from the list of autloaded functions. DiscardVirtualMemory is not available on Windows 8.1. Fixes: a3ae2a734892 ("Cygwin: don't autoload some kernel32 functions") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-28Cygwin: fallocate(2): handle FALLOC_FL_PUNCH_HOLE and FALLOC_FL_ZERO_RANGECorinna Vinschen5-68/+302
Split fhandler_disk_file::fallocate into multiple methods, each implementing a different aspect of fallocate(2), thus adding FALLOC_FL_PUNCH_HOLE and FALLOC_FL_ZERO_RANGE handling. For more correctly implementing posix_fallocate(3) semantics, make sure to re-allocate holes in the given range if the file is sparse. While at it, change the way checking when to make a file sparse. The rule is now, make file sparse if the hole created by the action spans at least one sparse block, taking the allocation granularity of sparse files into account. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-28Cygwin: pwrite(2): sparsify fileCorinna Vinschen1-0/+20
write(2) sparsifies a file after an lseek far enough beyond EOF. Let pwrite(2) sparsify as well if offset is far enough beyond EOF. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-28Cygwin: fallocate(2): fix evaluating return valueCorinna Vinschen1-1/+6
fallocate is not supposed to return an errno code, it has to return -1 and set errno. Fixes: dd90ede40510 ("Cygwin: introduce fallocate(2)") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-28Cygwin: open(2): reset sparseness on O_TRUNCated filesCorinna Vinschen2-0/+12
open(2) implements O_TRUNC by just reducing the size of the file to 0, to make sure EAs stay available. Turns out, file sparseness is not removed this way either, so add code to do just that. Fixes: 603ef545bdbd ("* fhandler.cc (fhandler_base::open): Never open files with FILE_OVERWITE/FILE_OVERWRITE_IF.") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-28Cygwin: introduce fallocate(2)Corinna Vinschen6-7/+88
First cut of the new, Linux-specific fallocate(2) function. Do not add any functionality yet, except of basic handling of FALLOC_FL_KEEP_SIZE. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-28Cygwin: fcntl.h: Use cdefs.h macrosCorinna Vinschen1-6/+5
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-28Cygwin: fhandler: rename ftruncate method to fallocateCorinna Vinschen6-16/+21
also, take mode flags parameter instead of just a bool. Introduce __FALLOC_FL_TRUNCATE mode flag as internal flag to indictae being called from ftruncate(2). This is in preparation of an upcoming change introducing the Linx-specific fallocate(2) call. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-28Cygwin: posix_fallocate: return ENODEVCorinna Vinschen3-1/+8
The fhandler method ftruncate returns either EISDIR if it has been called on directories, or EINVAL if called on files other than regular files. This matches what ftruncate(2) is supposed to return, but it doesn't match posix_fallocate(3), which is supposed to return ENODEV in both cases. To accomplish that, return ENODEV from fhandler_base::ftruncate() and convert it to EINVAL in ftruncate(2). In posix_fallocate(3), convert EISDIR to ENODEV. Fixes: 7636b58590621 ("* autoload.cc (NtSetInformationFile): Define.") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-25Cygwin: lseek: check for file sparseness, not for mount point sparsenessCorinna Vinschen1-1/+1
The code introducing the lseek(2) code for the GNU extensions SEEK_DATA and SEEK_HOLE accidentally checks if the mount point has the "sparse" flag set and, if not, emulates SEEK_DATA/SEEK_HOLE per the Linux specs. However, the mount point "sparse" flag only determines whether files should be made sparse or not. Files may be sparse independently of that, obviously. Fix that by checking for the FILE_ATTRIBUTE_SPARSE_FILE attribute instead. Fixes: edfa581d3c5a ("Cygwin: lseek: implement SEEK_DATA and SEEK_HOLE for files") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-21Cygwin: /dev/disk: Append '#N' if the same name appears more than onceChristian Franke1-21/+33
No longer drop ranges of identical link names. Append '#0, #1, ...' to each name instead. Enhance charset allowed in label names. No longer ignore null volume serial numbers. Signed-off-by: Christian Franke <christian.franke@t-online.de>
2023-11-20Cygwin: /dev/disk/by-uuid: Fix NTFS serial number print formatChristian Franke1-1/+1
Signed-off-by: Christian Franke <christian.franke@t-online.de>
2023-11-17Cygwin: Document /dev/disk/by-* subdirectoriesChristian Franke1-5/+11
Signed-off-by: Christian Franke <christian.franke@t-online.de>
2023-11-17Cygwin: Add /dev/disk/by-label and /dev/disk/by-uuid symlinksChristian Franke2-21/+141
The new directories '/dev/disk/by-label' and '/dev/disk/by-uuid' provide symlinks for each disk related volume label and serial number: 'VOLUME_LABEL' -> '../../sdXN' 'VOLUME_SERIAL' -> '../../sdXN' Signed-off-by: Christian Franke <christian.franke@t-online.de>
2023-11-17Cygwin: Add /dev/disk/by-drive and /dev/disk/by-voluuid symlinksChristian Franke2-20/+126
The new directory '/dev/disk/by-drive' provides symlinks for each disk related drive letter: 'x' -> '../../sdXN' The new directory '/dev/disk/by-voluuid' provides symlinks for each disk related storage volume: 'MBR_SERIAL-OFFSET' -> '../../sdXN' 'VOLUME_GUID' -> '../../sdXN' Both directories provide Windows specific information and do not exist on Linux. Signed-off-by: Christian Franke <christian.franke@t-online.de>
2023-11-14Cygwin: rand(3): implement in terms of random(3)Corinna Vinschen2-0/+11
This makes rand(3) ISO C compliant and adds locking to avoid race conditions. Reported-by: Bruno Haible <bruno@clisp.org> Fixes: 8a0efa53e4491 ("import newlib-2000-02-17 snapshot") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>