In dll_crt0_0, both threadinterface->Init and sigproc_init allocate
windows object handles using unpredictable memory regions, which may
collide with dynamically loaded dlls when they were relocated.
Make fhandler_base::clear_readahead virtual, and implement
fhandler_fifo::clear_readahead. This is called by
dtable::fixup_after_exec; it clears the readahead in each client.
Starting w/ the intro of S4U, seteuid32() calls lsaprivkeyauth(), then
s4uauth(). s4uauth calls LsaRegisterLogonProcess().
LsaRegisterLogonProcess fails w/ STATUS_PORT_CONNECTION_REFUSED, if the
proper privileges are not held.
Because of RtlNtStatusToDosError(), this status would be mapped to
ERROR_ACCESS_DENIED, which in turn would map to EACCES. Therefore it is
useless to add this status to errmap[] (errno.cc), as s4auauth() should
return EPERM as errno here (i.e. if process is not privileged).
Hence the kludge.
Before the intro of S4U, seteuid32() called lsaprivkeyauth(), then
lsaauth(), then create_token(). Before the intro of Vista, the latter
would have called NtCreateToken().
NtCreateToken() would have failed w/ STATUS_PRIVILEGE_NOT_HELD for a
process w/o the proper privileges. In that case, calling seteuid32()
would have returned EPERM (as required).
Since the intro of Vista, and if the process had been started from an
UNelevated shell, create_token() does NOT reach NtCreateToken()!
As create_token() failed to properly set errno in that case, calling
seteuid32() would return errno as set by lsaauth(), i.e. EACCES, not
in agreement w/ Posix (a bug which was present for years).
(lsaauth() called LsaRegisterLogonProcess() which would fail)
If a FIFO is opened with O_RDWR access, create the pipe with
read/write access, and make the first client have the handle of that
pipe as its I/O handle.
Adjust fhandler_fifo::raw_read to account for the result of trying to
read from that client if there's no data.
fhandler_fifo::clone called fhandler_base::clone on each client
fhandler. But those fhandlers are actually fhandler_fifo objects, so
when fhandler_base::clone calls copyto, it's actually
fhandler_fifo::copyto that gets called. This can lead to mysterious
crashes.
Fix this by simply calling clone (which translates to
fhandler_fifo::clone) on each client fhandler.
Add static functions peek_fifo, thread_fifo, start_thread_fifo, and
fifo_cleanup to select.cc. These are based on the corresponding pipe
functions, the main difference being that peek_fifo loops through the
connected clients to see if any of them have data available for
reading.
Add the fhandler_fifo methods select_read, select_write, and
select_except.
Add accessor methods get_nclients, get_handle, and is_connected that
are needed by peek_fifo.
Add a hit_eof method that tries to detect whether any clients are
connected. Before concluding that there are none, it gives the
listen_client thread time to update the client data.
Introduce a 'fifo_client_handler' structure that can be used by a
reader to communicate with a writer using an instance of the named
pipe. An fhandler_fifo opened for reading creates a thread that does
the following:
- maintains a list of fifo_client_handlers
- listens for_clients trying to connect
- creates new pipe instances as needed so that there's always at
least one available for connecting.
The pipe instances are initially created in blocking mode, but they
are set to be non-blocking after a connection is made.
fhandler_fifo::raw_read now loops through the connected clients and
reads from the first one that has data available.
New fhandler_fifo methods: add_client, listen_client,
listen_client_thread, check_listen_client_thread.
Replace the create_pipe method by create_pipe_instance, which allows
unlimited pipe instances.
New helper functions: create_event, set_pipe_non_blocking.
Make fhandler_fifo a derived class of fhandler_base instead of
fhandler_base_overlapped.
Replace the create_pipe macro, which is based on
fhandler_pipe::create, by new create_pipe and open_pipe methods.
These use NT functions instead of Win32 functions. Replace fifo_name
by get_pipe_name, which returns a pointer to a UNICODE_STRING.
Remove the fnevent macro, which would now be needed only once.
Add a raw_write method, adapted from fhandler_base::raw_write.
Adapt all functions to the changes above.
Switching to Cywin-only PIDs introduced a new problem when collecting
Cygwin processes for `ps -W': A process can show up multiple times
again, if the Cygwin procinfo has been opened for a just execing
process. The execed process then shows up twice, once as Cygwin
process, but with the wrong Windows PID of the execing process,
once as Windows-only process.
The mechanism used to exclude these stray processes didn't work with
the new Cygwin pid handling anymore. To fix this
* check if the incoming Windows PID is the same as the PID in the
procinfo. If not, we have the PID of the execing process while
procinfo was already changed,
* always check if the process has already been handled, not only
for processes we got a procinfo for,
* simplify adding pid to pidlist since pid is now always correct.
While at it, fix comments and comment formatting.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
These missing includes were causing build warnings, but also a real bug in
which the "size" parameter to "write" was being passed in 32-bit, whereas it
ought to be 64-bit. This led to intermittent bad behaviour.
strace only printed the Windows PID in event output so far.
Especially now that Windows and Cygwin PID are decoupled, the
strace user might like to see the Cygwin pid in event output as
well. However, at process startup, the process might not have
a Cygwin PID yet.
To mitigate this, always print the Windows PID and only add the
Cygwin pid if it exists.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
commit c0d7d3e1a2 removed the usage of the
LCMAP_BYTEREV flag in the call to LCMapStringW to workaround a strange
bug in LCMapStringW. This patch didn't take a userspace call of
wcsxfrm{_l} with NULL buffer and 0 size to evaluate the required buffer
size into account. This introduced a crash trying to byte swap the
NULL buffer. This patch fixes that problem.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The GCN port outputs stdout and stderr via a shared-memory interface.
Previously the buffer was limited to 1000 write operations, which was enough
for testing purposes, but easy to exhaust.
This patch implements a new circular buffering system allowing a greater
amount of output. The interface must allow hundreds of hardware threads to
output simultaneously. The new limit is UINT32_MAX write operations.
Unfortunately, there's no way to tell if the host side has also been updated.
This code will misbehave unless the gcn-run from GCC is also updated (although
it's fine the other way around), but that patch has already been committed.
OK?
Andrew Stubbs
Mentor Graphics / CodeSourcery
3.0.0 changed uname but missed to align /proc/version
which then used the old uname function on the new uname
struct.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Author: Sandra Loosemore <sandra@codesourcery.com>
Date: Wed Mar 13 20:22:16 2019 -0700
Add semihosting documentation for nios2 and m68k.
QEMU maintainers have asked for a specification of the nios2
semihosting interface. Since it's essentially a copy of the m68k
implementation, this patch adds a document for that target as well.
Always use NtQuerySystemInformation(SystemProcessIdInformation).
This drops two code paths calling NtQueryInformationProcess or
GetModuleFileNameExW and only requires to open the process
to fetch system time info.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
There's a long-standing bug in ps -W. It only shows processes which ps
can open with PROCESS_QUERY_LIMITED_INFORMATION permissions. However,
that fails for a lot of system processes. Due to that, output is
basically restricted to processes in the same session, as well as Cygwin
processes... which isn't *quite* what ps -W was supposed to do.
Basically we only need to open the process to fetch the image name. If
that fails, utilize the undocumented SystemProcessIdInformation info
class introduced with Windows Vista, which allows to fetch the image
name by specifying the PID. Restructure the code a bit.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
When logging in via ssh with an unprivileged account,
PdhAddEnglishCounter returns with status 0x800007D0,
PDH_CSTATUS_NO_MACHINE. We didn't find any workaround
but the changes to improve debugging output may help
in future. Using UNICODE instead of ANSI functions is
a result of trying to fix this problem.
Also drop the prototype workaround for PdhAddEnglishCounterA.
It's not required anymore since Mingw-w64's pdh.h catched up.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Create process with standard rights, plus
PROCESS_QUERY_LIMITED_INFORMATION for authenticated users. This
allows to fetch basic process information and thus /proc/<PID>/stat
to succeed on foreign processes.
While at it, fix formatting in CreateProcess calls.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
There's no good reason to return blank if some of the info
couldn't be collected. Drop useless call collecting
SystemProcessorPerformanceInformation. Always return some
valid start_time, even if we couldn't collect ProcessTimes.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The OpenProcess call to generate /proc/<PID>/stat info requests
PROCESS_VM_READ, but that's not required. Drop it.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Creating /proc/<PID>/cmdline requires permissions to communicate
with the target process via its signal pipe. If that fails, the
output is "<defunct>" which doesn't make sense most of the time.
Rather, call format_process_exename in this case to get more useful
process name info, albeit not the full cmdline.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The winpid symlinks got created with no query permissions, so
only admins could see all Cygwin processes. Create symlinks
so everyone has query permissions instead.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Canceling the timer thread runs under lock. The thread uses the same
lock to guard its timer_tracker struct access. If the timing is bad,
timer_settime or timer_delete grab the lock at the same time, the timer
expires. In the end, cancel waits for the thread sync while the thread
waits for ther lock to be released.
Fix this by not waiting for the thread sync under lock.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
On setting the timer, the thread is accidentally only canceled when
disarming the timer. This leaks one thread per timer_settimer call.
Move the thread cancellation where it belongs.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
We don't support setting groups via /etc/groups anymore. Also, the
initgroups group list is created via S4U, so we have "Interactive" vs.
"Network" token, an artificial and entirely irrelevant difference.
So, "verifying" the lsaprivkeyauth token may lead to rejecting a prefectly
valid token. Just remove the verify_token call.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Revert "Cywin: user profile: unload impersonation user profile on exit"
Revert "Cygwin: seteuid: allow inheriting impersonation user profile handle"
Revert "Cygwin: user profile: add debug output to unload_user_profile"
Revert "Cygwin: user profile: Make an effort to unload unused user profiles"
This reverts commit bcb33dc4f0.
This reverts commit dd3730ed9c.
This reverts commit 8eee25241e.
This reverts commit 71b8777a71.
This patchset actually results in the following problem:
- After a couple of ssh logon/logoff attempts, an interactive session
of the same user loging in, is broken.
Apparently UnloadUserProfile manages to unload the user's profile
even while a parallel interactive session still uses the user's
profile.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Per MSDN VirtualQueryEx requires PROCESS_QUERY_INFORMATION.
Testing showed that PROCESS_QUERY_LIMITED_INFORMATION is sufficient
since Windows 8.1. The assumption that Windows 8 is the same as
Windows 8 was not correct, it requires PROCESS_QUERY_INFORMATION
as well.
Fix that by splitting the Windows 8 wincaps into one for Windows 8
and one for Windows 8.1. Set needs_query_information for Windows 8.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
If the user domain is the primary domain, LDAP is supposed to
use the default naming context. This is accomplished by setting
domain name to NULL in the call to cyg_ldap::fetch_ad_account.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>