add Linux 6.8 cpuinfo flags:
Intel 0x00000007:1 eax:17 fred Flexible Return and Event Delivery;
AMD 0x8000001f eax:4 sev_snp SEV secure nested paging;
document unused and some unprinted bits that could look like omissions;
fix typos and misalignments;
Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
This reverts commit a51147467e.
Dumb thinko on my part. What was supposed to be an optimization
actually broke caseinsensitive globbing in that the entire input
of globbed expressions were downcased.
Drop the unused CCHAR() macro nevertheless.
Fixes: a51147467e ("Cygwin: glob: perform ignore_case_with_glob on input")
Reported-by: Michael Goldshteyn <mgold10000@gmail.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
If pipe reader is a non-cygwin app first, and cygwin process reads
the same pipe after that, the pipe has been set to bclocking mode
for the cygwin app. However, the commit 9e4d308cd5 assumes the
pipe for cygwin process always is non-blocking mode. With this patch,
the pipe mode is reset to non-blocking when cygwin app is started.
Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255644.html
Fixes: 9e4d308cd5 ("Cygwin: pipe: Adopt FILE_SYNCHRONOUS_IO_NONALERT flag for read pipe.")
Reported-by: wh <wh9692@protonmail.com>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Since commit 15e82eef3a ("Cygwin: getgrent: fix local SAM enumeration
on domain member machines") we skip enumerating local BUILTIN accounts
if we also enumerate AD. However, there are two local accounts which
are only available in local SAM, not in AD. Don't skip enumerating
those.
Fixes: 15e82eef3a ("Cygwin: getgrent: fix local SAM enumeration on domain member machines")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Add FS_PINNED_FL and FS_UNPINNED_FL flags and handle them with
mode bits 'p' and 'u' in chattr(1) and lsattr(1).
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Add FILE_OPEN_NO_RECALL to NtOpenFile calls trying to fetch
or write file security descriptors so as not to recall them
from offline storage inadvertently.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Chances are high that Cygwin recalls offline files from remote
storage, even if the file is only accessed during stat(2) or
readdir(3).
To avoid this
- make sure Cygwin is placeholder-aware,
- open files in path_conv handling, as well as in stat(2)/readdir(3)
scenarios with FILE_OPEN_NO_RECALL, and
- during symlink checking or testing for executablility, don't even
try to open the file if one of the OFFLINE attributes is set.
Reported-by: Marcin Wisnicki <mwisnicki@gmail.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This isn't strictly required, but it avoids confusion in ctags.
Ctags fails to record the next function or method following the
EXPORT_ALIAS expression.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This patch eliminates verbose NtQueryObject() calls in the procedure
to get query_hdl by storing pipe name into fhandler_base::pc when
the pipe is created. fhandler_pipe::temporary_query_hdl() uses the
storedpipe name rather than the name retrieved by NtQueryObject().
Suggested-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Non-cygwin app may call ReadFile() for empty pipe, which makes
NtQueryObject() for ObjectNameInformation block in fhandler_pipe::
get_query_hdl_per_process. Therefore, do not to try to get query_hdl
for non-cygwin apps.
Addresses: https://github.com/msys2/msys2-runtime/issues/202
Fixes: b531d6b06e ("Cygwin: pipe: Introduce temporary query_hdl.")
Reported-by: Alisa Sireneva, Johannes Schindelin <Johannes.Schindelin@gmx.de>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
The open() call for console sometimes fails if the console owner
process is closing the console by close() at the same time. This
is due to mismatch state of con.owner variable and attaching state
to the console. With this patch, checking con.owner and attaching
to con.owner sequence in open(), and resetting con.owner and freeing
console sequence in close() are guarded by output_mutex to avoid
such a race issue.
Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255575.html
Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible from other terminals.")
Reported-by: Kate Deplaix <kit-ty-kate@outlook.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Start at index 0 and use 32 bytes as minimal allocation size.
Reduce NBUCKETS, we don't have such big objects on the
cygheap anyway.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The upcoming POSIX issue 8 will require that posix_getdents after
fork() will pick up at the right spot, independently of being
called in the parent or in the child process. Remove the expression
clearing out the attached DIR after fork.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Transfer code lseeking on posix_getdents() directory descriptor
into its own static function and rework it so SEEK_END, SEEK_DATA
and SEEK_HOLE work here as expected, too.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
In the condition that console setup for CTTY and close run at the
sametime, accessing shared console memory which is already unmapped
may occur. With this patch, to avoid this race issue, shared console
memory which belongs to contorolling terminal (CTTY) is kept mapped
as before.
Addresses: https://cygwin.com/pipermail/cygwin/2024-February/255561.html
Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible from other terminals.")
Reported-by: Kate Deplaix <kit-ty-kate@outlook.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
These errno values are no longer used by Cygwin. Change the entries
to empty strings instead of NULL to avoid crashes in existing
binaries directly accessing the table. Enhance strerror_worker()
such that empty strings also result in "Unknown error ..." messages.
Also add a static_assert check for the _sys_errlist[] size.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
Use constexpr instead of const for errmap[] to allow static_assert
checks on its values.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
If a removable (USB) device is disconnected after opening its raw
device, R/W attempts fail with ERROR_NO_SUCH_DEVICE(433). If the
raw device of a partition is used, ERROR_MEDIA_CHANGED(1110) is
returned instead. Both are mapped to ENODEV(19) because <errno.h>
does not offer a value which better matches ERROR_MEDIA_CHANGED.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
Windows only allows to set the primary group to a group already
present in the TOKEN_GROUP list. Cygwin OTOH fakes success at
setgid() time, to allow a subsequent call to setuid() to do
the actual account switching. To have a sane behaviour in the
command line tool, check group membership and disallow to switch
to groups other than those already present in the user token.
Fixes: 8bd56ec873 ("Cygwin: newgrp: first full version")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Fix an error message accessing argv[1] even after it has been
potentially moved. Print group name from group DB instead.
Fixes: 8bd56ec873 ("Cygwin: newgrp: first full version")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The %p format specifier is handled immediately. It requires
that tm_hour is already set. This falls flat in case the am/pm
marker preceeds the time specification. Locales with am/pm
marker preceeding time spec by default exist (e. g. ko_KR).
Also, the code expects that tm_hour might be set to an invalid
value because the %p specifier is used in conjunction with %H.
But this usage is invalid in itself and now catched as error
condition after commit 343a2a5581 ("Cygwin: strptime: make
sure to fail on invalid input digits").
Change the %H/%I/%p handling according to GLibC, i. e.
- fix tm_hour for pm only if the time value has been specified
as 12 hour time %I, and
- perform the fixup only after the entire input has been scanned.
This decouples the fixup from the %p position relativ to %I.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
conv_num returns NULL if the input is invalid, e. g., the
numbers are out of range. However, the code fails to test
this in a lot of places.
Rather than adding checks all over the place, rename conv_num
to __conv_num and create a wrapper macro conv_num to perform
the task of error checking.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Don't skip output of local SAM groups on domain member machines.
They can have valid, user-defined groups in their SAM. Just
skip builtin groups if we're enumerating AD as well.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Capability SIDs (S-1-15-3-...) have been introduced with
Windows 10 1909. They don't resolve with LookupAccountSid.
We don't need them and they don't map gracefully into out
POSIX account namespace. Also, add code to make sure to
filter them out *iff* they become resolvable at one point.
While at it, slightly reorder code for non-resolving SIDs
by authority values.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Add a missing check for the struct timeval pointer being NULL.
Reported-by: 109224573 <109224573@qq.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Previously, three similar callback fuctions were used in console
code. This patch unifies these functions to ease maintenance cost.
Fixes: 8aad3a7ede ("Cygwin: console: Fix a problem that minor ID is incorrect in ConEmu.")
Suggested-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
All three warnings produced with -Og are false positives.
But given we're using -Werror unconditionally it's better
to be safe than sorry.
Reported-by: Kevin Ushey <kevinushey@gmail.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
https://cygwin.com/pipermail/cygwin/2024-February/255397.html
reports a crash on ARM64 probably related to checking x86_64
code on the x86_64 emulator on AArch64.
At least for testing, pull the code checking the host HW
up to be called before trying to evaluate assembler code.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Previously, minor device number of console was not assigned correctly
in ConEmu environment. This is because console window of ConEmu is
not enumerated by EnumWindows(). This patch fixes the issue.
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
In pty master_thread, 6 handles are duplicated when CallNamedPipe()
requests that. Though some of them are not used so should be closed,
they were not. This causes handle leak potentially.
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
If non-cygwin process is started in pty, closing from_master_nat
pipe handle was missing in fhandler_pty_slave::input_transfer().
This occured because the handle was duplicated but not closed.
https://github.com/msys2/msys2-runtime/issues/198
Fixes: 29431fcb5b ("Cygwin: pty: Inherit typeahead data between two input pipes.")
Reported-by: Hakkin Lain
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
The definition of PTR has been dropped from newer versions
of ansidecl.h.
Convert definition of print_section_name to use void * instead,
as required by bfd_map_over_sections.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
...in a non-Cygwin child process. Backported from MSYS2.
Downstream commit message follows.
In https://github.com/msys2/msys2-runtime/pull/18, we discussed a change
that would allow default Windows error handling of spawned processes to
kick in (such as registered JIT debuggers). We even agreed that it would
make sense to hide this functionality behind a flag, `winjitdebug`.
However, when this got upstreamed as 21ec498d7f (cygwin: use
CREATE_DEFAULT_ERROR_MODE in spawn, 2020-12-09), that flag was deemed
unnecessary.
But it would appear that it _is_ necessary: As reported in
https://github.com/msys2/MSYS2-packages/pull/2414#issuecomment-810841296
this new behavior is pretty disruptive e.g. in CI scenarios.
So let's introduce that `winjitdebug` flag (settable via the environment
variable `MSYS`) at long last.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Currently, if_nametoindex() and if_indextoname() handle interface names
such as "ethernet_32777", while if_nameindex() returns the names such
as "{5AF7ACD0-D52E-4DFC-A4D0-54D3E6D6B2AC}". This patch unifies the
interface names to the latter.
Fixes: c356901f0d ("Rename if_indextoname to cygwin_if_indextoname (analag for if_nametoindex)")
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
If disable_master_thread flag is set between the code checking that
flag not be set and the code acquiring input_mutex, input record is
processed once after setting disable_master_thread flag. This patch
prevents that.
Fixes: d4aacd50e6 ("Cygwin: console: Add missing input_mutex guard.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
If non-cygwin process is executed in console, the exit code is not
set correctly. This is because the stub process for non-cygwin app
crashes in fhandler_console::set_disable_master_thread() due to NULL
pointer dereference. This bug was introduced by the commit:
3721a756b0 ("Cygwin: console: Make the console accessible from
other terminals."), that the pointer cons is accessed before fixing
when it is NULL. This patch fixes the issue.
Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible from other terminals.")
Reported-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
cmdline has to be initialized, otherwise the return value is
undefined in case generating the command line fails.
Fixes: 732afede93 ("Cygwin: redefine CW_CMDLINE to CW_CMDLINE_ALLOC")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
IsBadStringPtr is deprecated and just gives a wrong sense
of memory safety. Replace with check for NULL pointer.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
On Linux, __progname and program_invocation_short_name are just
different exported names of the same string. Do the same in Cygwin.
This requires to tweak the mkglobals_h so as not to touch the
EXPORT_ALIAS expression. Also, use the base variable
program_invocation_short_name throughout. __progname is just
the export for getopt.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Since it's possible to change the __argv array, we should not rely
on __argv[0] actually representing the windows executable path in
any way. Use the real path stored in global_progname instead.
Fixes: 521953a83a ("* common.din: Export GetCommandLine{A,W}.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
So far ps(1) always prints the full path of the executable under
the COMMAND heading.
With -f, print the command line instead.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Make sure to
- append a trailing \0 as with Windows multistrings, so the end of
the string can be recognized by the caller, and
- allocate cmdline on the user heap so the caller can free the
multistring after usage.
Fixes: 831d6fa520 ("* external.cc (cygwin_internal): Implement CW_CMDLINE.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
- 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>
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>
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>
- 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>
Remove a stray __END_DECLS. It didn't hurt in the only
(plain C) file including this header, but still...
Fixes: 030a762535 ("Cygwin: fix arc4random after fork(2)")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
After using fork(), arc4random does not reseed itself, which
causes the results to become predictable. Activate droppingfork-recognition
Fixes: e0fc33322d ("Delete Cygwin's arc4random in favor of new Newlib implementation")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
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>
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>
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.
Commit 3f3bd10104 ("* 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: 3f3bd10104 ("* Throughout, use __try/__except/__endtry blocks [...]")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
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>
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)
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".
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>
- len must not be <= 0
- offset + len must not exceed off_t (max. file size)
Fixes: e01c50c7b0 ("Cygwin: introduce fallocate(2)")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
- len must not be <= 0
- offset + len must not exceed off_t (max. file size)
Fixes: 7636b58590 ("* autoload.cc (NtSetInformationFile): Define.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
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>
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>
In preparation of using the FileFsSectorSizeInformation info class,
add a couple of missing definitions.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Commit a3ae2a7348 ("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: a3ae2a7348 ("Cygwin: don't autoload some kernel32 functions")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
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>
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>
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>
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: 603ef545bd ("* fhandler.cc (fhandler_base::open): Never open files with FILE_OVERWITE/FILE_OVERWRITE_IF.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
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>
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>
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: 7636b58590 ("* autoload.cc (NtSetInformationFile): Define.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
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: edfa581d3c ("Cygwin: lseek: implement SEEK_DATA and SEEK_HOLE for files")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
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>
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>
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>
This makes rand(3) ISO C compliant and adds locking to avoid
race conditions.
Reported-by: Bruno Haible <bruno@clisp.org>
Fixes: 8a0efa53e4 ("import newlib-2000-02-17 snapshot")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Minor updates to profiler and gmondump, which share some code:
- fix operation of error() so it actually works as intended
- resize 4K-size auto buffer reservations to BUFSIZ (==1K)
- remove trailing '\n' from 2nd arg on error() calls everywhere
- provide consistent annotation of Windows error number displays
Fixes: 9887fb27f6126 ("Cygwin: New tool: profiler")
Fixes: 087a3d76d7335 ("Cygwin: New tool: gmondump")
Signed-off-by: Mark Geisert <mark@maxrnd.com>
Add locking to the random(3) family of functions to gain
thread-safety per POSIX. Use NetBSD version of the file as
role-model.
Reported-by: Bruno Haible <bruno@clisp.org>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The new directory '/dev/disk/by-partuuid' provides symlinks for each
MBR or GPT disk partition:
'MBR_SERIAL-OFFSET' -> '../../sdXN'
'GPT_GUID' -> '../../sdXN'
Signed-off-by: Christian Franke <christian.franke@t-online.de>
The new directory '/dev/disk/by-id' provides symlinks for each
disk and its partitions:
'BUSTYPE-[VENDOR_]PRODUCT_SERIAL[-partN]' -> '../../sdX[N]'.
This is based on strings provided by STORAGE_DEVICE_DESCRIPTOR.
If this information is too short, a 128-bit hash of the
STORAGE_DEVICE_UNIQUE_IDENTIFIER raw data is added.
Administrator privileges are not required.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
The exception handling inside of Cygwin functions marked as SIGFE
covers exceptions and lets the library code handle them gracefully.
If these functions want to raise an exception, they have to send a
signal explicitely via raise(3).
That's not what we want in feraiseexcept(). It triggers a floating
point exception explicitely by calling the i387 op "fwait". Being
marked as SIGFE, this exception will be suppressed and the normal
exception handling won't kick in.
Fix this by moving feraiseexcept into the NOSIGFE realm.
Fixes: 0f81b5d4bc ("* Makefile.in (DLL_OFILES): Add new fenv.o module.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
cwdstuff::set has a code snippet handling the case where a process
can't create a handle to a directory, e. g., due to permissions.
Commit 88443b0a22 ("cwdstuff: Don't leave from setting the CWD
prematurely on init") introduced a special case to handle this
situation at process initialization. It also introduces an early
mutex release, which is not required, but ok, because we're in the
init phase. Releasing the mutex twice is no problem since the mutexes
are recursive.
Fast forward to commit 0819679a7a ("Cygwin: cwd: use SRWLOCK
instead of muto"). The mechanical change from a recursive mutex
to a non-recursive SRWLOCK failed to notice that this very specific
situation will release the SRWLOCK twice.
Remove the superfluous release action. While at it, don't set dir to
NULL, but h, since dir will get the value of h anyway later on.
Setting h to NULL may not be necessary, but better safe than sorry.
Reported-by: tryandbuy >tryandbuy@proton.me>
Fixes: 88443b0a22 ("cwdstuff: Don't leave from setting the CWD prematurely on init")
Fixes: 0819679a7a ("Cygwin: cwd: use SRWLOCK instead of muto")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The commit 322c7150b2 restricts buffer size with a fixed length,
however, the minimum buffer size should be varied by the sample rate.
With this patch, it is estimated using sample rate, sample width
and number of channels so that the buffer length is not less than
80 msec which is almost the minimum value of Win MME to work.
Fixes: 322c7150b2 ("Cygwin: dsp: Avoid setting buffer that is too small.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
The buffer size that is too small causes choppy sound. That is not
practical at all. With this patch, the minimum value of the buffer
size (i.e. fragstotal * fragsize) is restricted to 16384 bytes.
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
If specified, set version timestamp to this value.
Enable deterministic archives for ar and ranlib.
Set cygwin1.dll PE and export table header timestamps to zero.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
Given the downsides of NFS symlinks as FIFOs, drop the code
added to recognize them as such.
Fixes: 622fb0776e ("Cygwin: enable usage of FIFOs on NFS")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Creating real NFS symlinks for device files has a major downside:
The way we store device info requires to change the symlink target
in case of calling chmod(2). This falls flat in two ways:
- It requires to remove and recreate the symlink, so it doesn't
exist for a short period of time, and
- removing fails badly if there's another open handle to the symlink.
Therefore, change this to create FIFOs as shortcut files, just as on
most other filesystems. Make sure to recognize these new shortcuts
on NFS (for devices only) in path handling and readdir.
Fixes: 622fb0776e ("Cygwin: enable usage of FIFOs on NFS")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
MSFT NFSv3 fakes DOS attributes based on file type and permissions.
Rather than just faking FILE_ATTRIBUTE_DIRECTORY for dirs, fetch the
"real" DOS attributes returned by NFS.
This allows to handle the "R/O" attribute on shortcut files and thus
reading and creating device shortcut files on NFS.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Add a missing "void" to the prototype for __cpuset_zero_s().
Reported-by: Marco Mason <marco.mason@gmail.com>
Addresses: https://cygwin.com/pipermail/cygwin/2023-September/254423.html
Signed-off-by: Mark Geisert <mark@maxrnd.com>
Fixes: c6cfc99648d6 (Cygwin: sys/cpuset.h: add cpuset-specific external functions)
fhandler_base::fchown casts any fhandler landing here to a
fhandler_disk_file. That's ugly and dangerous. Duplicate
the path_conv info into an explicitly create fhandler_disk_file
instead and call fchmod on that.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
By handling native NFS FIFOs as actual FIFOs, chmod on a FIFO
suddenly called fhandler_base::fchmod, which is insufficient
to handle FIFO files on any filesystem.
Note that this does not fix Cygwin FIFOs on NFS or AFS yet.
Fixes: 622fb0776e ("Cygwin: enable usage of FIFOs on NFS")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
With this patch, the response time of select()/poll() has been
improved by utilizing semaphore (select_sem) just like pipe and
fifo. In addition, notification of exceptional conditions has
been added.
Fixes: 2c06014f12 ("Cygwin: dsp: Implement select()/poll().")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>