aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/syscalls.cc
AgeCommit message (Collapse)AuthorFilesLines
2024-11-19Cygwin: check_dir_not_empty: Avoid leaving the allocated buffer.Bernhard Übelacker1-4/+6
The pointer pfni gets allocated the buffer at the begin, and is used in the NtQueryDirectoryFile call before the loops. In the loop the pointer pfni is also used as iterator. Therefore it holds no longer the initial buffer at the call to NtQueryDirectoryFile in the while conditition at the bottom. Fixes: 28fa2a72f8106 ("* syscalls.cc (check_dir_not_empty): Check surplus directory entries") Co-authored-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Bernhard Übelacker <bernhardu@mailbox.org>
2024-03-07Cygwin: move EXPORT_ALIAS expressions to end of sourceCorinna Vinschen1-15/+9
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>
2024-03-01Cygwin: lseek: improve seeking posix_getdents descriptorsCorinna Vinschen1-22/+61
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>
2024-01-31Cygwin: posix_getdents: implement per SUS Base Specifications Issue 8 draftCorinna Vinschen1-3/+26
- 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-15Cygwin: introduce close_range(2)Christian Franke1-0/+42
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>
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-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: introduce fallocate(2)Corinna Vinschen1-0/+34
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: fhandler: rename ftruncate method to fallocateCorinna Vinschen1-2/+2
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 Vinschen1-0/+4
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-09-04Revert "Cygwin: mknod: disable creating special files on NFS"Corinna Vinschen1-6/+0
This reverts commit d085592daa5f89ccc9f5b86b2ca26199e7516d61. This reenables creating Cygwin FIFOs on NFS. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-25Cygwin: mknod: disable creating special files on NFSCorinna Vinschen1-0/+6
This simply doesn't work (yet?) but leaves unusable files behind. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-09Cygwin: lseek: propagate new SEEK_DATA and SEEK_HOLE to fhandlerCorinna Vinschen1-1/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-26Cygwin: Fix and streamline AT_EMPTY_PATH handlingCorinna Vinschen1-36/+11
The GLIBC extension AT_EMPTY_PATH allows the functions fchownat and fstatat to operate on dirfd alone, if the given pathname is an empty string. This also allows to operate on any file type, not only directories. Commit fa84aa4dd2fb4 broke this. It only allows dirfd to be a directory in calls to these two functions. Fix that by handling AT_EMPTY_PATH right in gen_full_path_at. A valid dirfd and an empty pathname is now a valid combination and, noticably, this returns a valid path in path_ret. That in turn allows to remove the additional path generation code from the callers. Fixes: fa84aa4dd2fb ("Cygwin: fix errno values set by readlinkat") Reported-by: Johannes Schindelin <johannes.schindelin@gmx.de> Tested-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-26Cygwin: use new _AT_NULL_PATHNAME_ALLOWED flagCorinna Vinschen1-5/+4
Convert gen_full_path_at to take flag values from the caller, rather than just a bool indicating that empty paths are allowed. This is in preparation of a better AT_EMPTY_PATH handling in a followup patch. Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-26Cygwin: gen_full_path_at: drop never reached codeCorinna Vinschen1-5/+0
The check if the local variable p is NULL is useless. The preceeding code always sets p to a valid pointer, or it crashes if path_ret is invalid (which would be a bug in Cygwin). Fixes: c57b57e5c43a ("* cygwin.din: Sort.") Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-21Cygwin: Fix uninitialized use of fh in strace output in stat_worker()Jon Turney1-2/+3
Move strace output to fix uninitalized use of fh introduced in previous commit. ../../../../src/winsup/cygwin/syscalls.cc: In function ‘int stat_worker(path_conv&, stat*)’: ../../../../src/winsup/cygwin/syscalls.cc:1971:69: error: ‘fh’ may be used uninitialized [-Werror=maybe-uninitialized] Fixes: 42b44044b34d ("Cygwin: Fix Windows file handle leak in stat("file", -1)") Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2023-07-21Cygwin: Fix Windows file handle leak in stat("file", -1)Jon Turney1-3/+4
Don't leak a Windows file handle if stat() is called with a valid filename, but invalid stat buffer pointer. We do not destroy fh (which closes a Windows handle it has opened) if an exception happens in the __try block. Avoid this by re-ordering things so that we don't construct the fhandler object until after we've attempted to use the struct stat buffer. Fixes: 73151c54d581 ("syscalls.cc (stat_worker): Don't call build_fh_pc with invalid pc.") Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2023-04-18Cygwin: align renameat2 to Linux behaviourCorinna Vinschen1-5/+13
In contrast to rename default behaviour, Linux' renameat2 returns -1 with errno set to EEXIST, if oldfile and newfile refer to the same file, and the RENAME_NOREPLACE flag is set. Follow suit, given this is a Linux-only function anyway. Fixes: f665b1cef30f ("cygwin: Implement renameat2") Reported-by: Bruno Haible <bruno@clisp.org> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-04-18Cygwin: fix errno values set by readlinkatCorinna Vinschen1-20/+22
readlinkat(fd, "", ...) is supposed to return ENOENT per POSIX, but Cygwin returns EBADF. At the same time, we have to maintain the special feature of glibc that readlinkat(fd, "", ...) operates on fd, if fd is pointing at a symlink opened with O_PATH|O_NOFOLLOW. And, while fixing that, readlinkat(fd, path, ...) *still* has to set errno to EBADF, if fd is an invalid descriptor *and* path is a relative path. This required to change the evaluation order in the helper function gen_full_path_at. Last but not least, in case of the aforementioned glibc-like special handling for symlink descriptors, we have to make sure that errors from gen_full_path_at are not spilled into that special handling. Fixes: 6cc05784e16a ("Cygwin: readlinkat: allow pathname to be empty") Reported-by: Bruno Haible <bruno@clisp.org> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-21Cygwin: log disabling posix semanticsYoshinao Muramatsu1-1/+7
Add log when workaround occurs Signed-off-by: Yoshinao Muramatsu <ysno@ac.auone-net.jp>
2023-03-21Cygwin: fix rename in containerYoshinao Muramatsu1-0/+10
Renaming files returns STATUS_INVALID_PARAMETE on a bind mounted file system in hyper-v container with FILE_RENAME_POSIX_SEMANTICS. Disable the use_posix_semantics flag and retry. Signed-off-by: Yoshinao Muramatsu <ysno@ac.auone-net.jp>
2023-03-21Cygwin: fix unlink in containerYoshinao Muramatsu1-1/+4
Deleting files returns STATUS_INVALID_PARAMETE on a bind mounted file system in hyper-v container with FILE_DISPOSITION_POSIX_SEMANTICS. Therefore fall back to default method. This code is suggested by Johannes Schindelin on github and I change it more simple. Signed-off-by: Yoshinao Muramatsu <ysno@ac.auone-net.jp>
2023-03-21Cygwin: don't use unlink/rename POSIX semantics on certain NTFSCorinna Vinschen1-5/+9
If a host NTFS is mapped into a Hyper-V isolated container, the OPEN_BY_FILE_ID filesystem flag is missing, just as if that NTFS is a remote drive. However, NtQueryVolumeInformationFile claims the drive is a local drive. We can use this fact to learn that the process is running under Hyper-V, and that the Hyper-V isolated process can't use rename/unlink with POSIX semantics. Strange enough, the POSIX_UNLINK_RENAME filesystem flag is still set... Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-20Cygwin: unlink: drop unlink_nt/unlink_nt_shareable wrappersCorinna Vinschen1-18/+6
Useless indirection. Rename _unlink_nt back to unlink_nt and call the function directly with `sharable' flag as needed. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-03-07Cygwin: ctty: Remove old 'kludge' code.Takashi Yano1-11/+0
Remove old 'kludge' code which does not seem necessary anymore. The comment of the 'kludge' is as follows. * syscalls.cc (setsid): On second thought, in the spirit of keeping things kludgy, set ctty to -2 here as a special flag, and... (open): ...only eschew setting O_NOCTTY when that case is detected. Fixes: c38a2d837303 Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-03-07Cygwin: ctty: Replace ctty constant with more descriptive macros.Takashi Yano1-4/+2
This patch replaces ctty constants with more descriptive macros (CTTY_UNINITIALIZED and CTTY_RELEASED) rather than -1 and -2 as well as checking sign with CTTY_IS_VALID(). Fixes: 3b7df69aaa57 (Cygwin: ctty: Add comments for the special values: -1 and -2.) Suggested-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-01-10Cygwin: ctty: Add comments for the special values: -1 and -2.Takashi Yano1-1/+3
_pinfo::ctty has two special values other than the device id of the allocated ctty: -1: CTTY is not initialized yet. Can be associated with the TTY which is associated with the session leader. -2: CTTY has been released by setsid(). Can be associate only with new TTY which is not associated with any other session as CTTY, but cannot be associate with the TTYs already associated with other sessions. This patch adds the comments in some source files. Suggested-by: Corinna Vinschen <corinna@vinschen.de> Signedoff-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2022-10-28Cygwin: stop handling files with .com suffix like .exe filesCorinna Vinschen1-1/+0
.com is a remnant from the past. There are only five executables left: chcp.com format.com mode.com more.com tree.com Calling them on the command line already requires to use the suffix anyway. So drop useless .com test from the execve test for scripts (they are handled earlier in the same function as executables) and do not handle them like .exe suffixes in other functions. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-23Cygwin: cwd: use SRWLOCK instead of mutoCorinna Vinschen1-6/+6
To reduce thread contention, use reader/writer locks as required. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-04Cygwin: syscalls.cc: remove ".dll" from blessed_executable_suffixesKen Brown1-6/+0
This reverts commit d9e9c7b5a7. The latter added ".dll" to the blessed_executable_suffixes array because on 32-bit Windows, the GetBinaryType function would report that a 64-bit DLL is an executable, contrary to the documentation of that function. That anomaly does not exist on 64-bit Windows, so we can remove ".dll" from the list. Reverting the commit does, however, change the behavior of the rename(2) syscall in the following unlikely situation: Suppose we have an executable foo.exe and we make the call rename ("foo", "bar.dll"); Previously, foo.exe would be renamed to bar.dll. So bar.dll would then be an executable without the .exe extension. The new behavior is that foo.exe will be renamed to bar.dll.exe. [Exception: If there already existed an executable (not a DLL!) with the name bar.dll, then .exe will not be appended.]
2022-08-04Cygwin: syscalls.cc: drop masking macros for standard IO functionsCorinna Vinschen1-25/+2
The actual reason for these wrappers are lost in time, there's no hint even in the pre-2000 ChangeLog files. Apparently they were masking the prototypes or, alternatively, macros from newlib to clash with the definitions in syscalls.cc. They are not needed anymore, so just drop them. This uncovered that the buffer pointer to pwrite is erronously non-const. Fix this on the way out. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-04Cygwin: Drop export aliases and masking macros for stdio64 functionsCorinna Vinschen1-12/+0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-03Cygwin: drop macro and code for CYGWIN_VERSION_OLD_STDIO_CRLF_HANDLINGCorinna Vinschen1-6/+0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-03Cygwin: drop requirement to build newlib's stdio64Corinna Vinschen1-2/+2
Given that 64 bit Cygwin defines all file access types (off_t, fpos_t, and derived types) as 64 bit anyway, there's no reason left to rely on the stdio64 part of newlib. Use base functions and base types. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-07-28Cygwin: rename __cygwin_environ and drop env redirection via cur_environ()Corinna Vinschen1-1/+1
Back in early Cygwin development a function based access to the environment was exported, the internal environ in Cygwin was called __cygwin_environ and cur_environ() was used to access the environment indirectly . The history of that necessity is not documented, but kept in i686 for backward compatibility. The x86_64 port eventually used __cygwin_environ directly and exported it as DATA under the usual name environ. We don't need the i686 workaround anymore, so just rename __cygwin_environ to environ, drop the cur_environ() macro and simply export environ under its own name. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-07-14Cygwin: fix or delete a few comments to drop 32 bit referencesCorinna Vinschen1-4/+0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-07-14Cygwin: drop tmpfile export alias for 32 bit systemsCorinna Vinschen1-4/+0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-07-13Add _REENT_ERRNO(ptr)Matt Joyce1-2/+2
Add a _REENT_ERRNO() macro to encapsulate the access to the _errno member of struct reent. This will help to replace the structure member with a thread-local storage object in a follow up patch. Replace uses of __errno_r() with _REENT_ERRNO(). Keep __errno_r() macro for potential users outside of Newlib.
2022-05-29Cygwin: remove regparm.hKen Brown1-2/+2
This file defines the macros __reg1, __reg2, and __reg3, which are defined to be empty on 64-bit Cygwin. Remove all occurrences of these macros.
2022-05-29Cygwin: simplify some function namesKen Brown1-75/+46
Remove "32" or "64" from each of the following names: acl32, aclcheck32, aclfrommode32, aclfrompbits32, aclfromtext32, aclsort32, acltomode32, acltopbits32, acltotext32, facl32, fchown32, fcntl64, fstat64, _fstat64, _fstat64_r, ftruncate64, getgid32, getgrent32, getgrgid32, getgrnam32, getgroups32, getpwuid32, getpwuid_r32, getuid32, getuid32, initgroups32, lseek64, lstat64, mknod32, mmap64, setegid32, seteuid32, setgid32, setgroups32, setregid32, setreuid32, setuid32, stat64, _stat64_r, truncate64. Remove prototypes and macro definitions of these names. Remove "#ifndef __INSIDE_CYGWIN__" from some headers so that the new names will be available when compiling Cygwin. Remove aliases that are no longer needed. Include <unistd.h> in fhandler_clipboard.cc for the declarations of geteuid and getegid.
2022-05-29Cygwin: remove some 32-bit-only function definitionsKen Brown1-195/+0
Remove the definitions of the following: acl, aclcheck, aclfrommode, aclfrompbits, aclfromtext, aclsort, acltomode, acltopbits, acltotext, chown, fchown, _fcntl, fstat, _fstat_r, ftruncate, getegid, geteuid, getgid, getgrent, getgrgid, getgrnam, getgroups, getpwduid, getpwuid, getpwuid_r, getuid, initgroups, lacl, lacl32, lchown, lseek, lstat, mknod, mmap, setegid, seteuid, setgid, setgroups, setregid, setreuid, setuid, stat, _stat_r, truncate. [For most of these, the corresponding 64-bit entry points are obtained by exporting aliases. For example, acl is an alias for acl32, and truncate is an alias for truncate64.] Remove the following structs and all code using them (which is 32-bit only): __stat32, __group16, __flock32, __aclent16_t. Remove the typedefs of __blkcnt32_t __dev16_t, __ino32_t, which are used only in code that has been removed. Put the typedefs of __uid16_t and __gid16_t in one header, instead of one header if __INSIDE_CYGWIN__ is defined and a different header otherwise.
2022-05-23Cygwin: fix mknod (64-bit only)Ken Brown1-0/+4
The current definition of mknod in syscalls.cc has a third argument of type __dev16_t instead of dev_t. Fix this on 64-bit Cygwin by making the existing mknod 32-bit only and then exporting mknod as an alias for mknod32. (No fix is needed on 32-bit because mknod is redirected to mknod32 via NEW_FUNCTIONS in Makefile.am.) Addresses: https://cygwin.com/pipermail/cygwin-developers/2022-May/012589.html
2022-05-13Cygwin: drop create_token and dependent functionsCorinna Vinschen1-19/+4
Given we only called create_token on W7 WOW64 anyway, we can now drop this function and all other functions only called from there entirely. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-05-13Cygwin: wincap: drop wow64 flag and all conditions depending on itCorinna Vinschen1-2/+1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-05-13Add global __sglue object for all configurationsMatt Joyce1-1/+1
Added a new global __sglue object for all configurations. Decouples the global file object list from the _GLOBAL_REENT structure by using this new object instead of the __sglue member of _GLOBAL_REENT in __sfp() and _fwalk_sglue().
2022-05-13stdio: Replace _fwalk_reent() with _fwalk_sglue()Sebastian Huber1-4/+2
Replaced _fwalk_reent() with _fwalk_sglue(). The change adds an extra __sglue object as a parameter, which will allow the passing of a global __sglue object separate from the __sglue member of struct _reent. The global __sglue object will be added in a follow-on patch.
2022-03-31Replace _fwalk() calls with _fwalk_reent()Sebastian Huber1-3/+3
Remove the _fwalk() implementation to avoid duplicated code with _fwalk_reent().