Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement PosixSignal API #54136

Merged
merged 65 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
11a94bb
Implement PosixSignal API
tmds Jun 9, 2021
ae4d67e
PosixSignalRegistration: implement finalizer
tmds Jun 14, 2021
72a2475
Support using positive PosixSignal values as raw signal numbers
tmds Jun 14, 2021
17045d8
Reduce nr of TargetFrameworks
tmds Jun 14, 2021
61a0fba
#ifdef SIGRTMAX
tmds Jun 14, 2021
b5ae07a
Don't throw Win32Exception (for now)
tmds Jun 14, 2021
52e1f17
Rename PosixSignalRegistration.cs to PosixSignalRegistration.Unsuppor…
tmds Jun 16, 2021
26f22b3
Spawn new Thread only for specific signals
tmds Jun 16, 2021
0bd03f9
Add PosixSignal.SIGCONT, SIGWINCH, SIGTTIN, SIGTTOU, SIGTSTP
tmds Jun 17, 2021
e8d01c8
SystemNative_DefaultSignalHandler: remove SuppressGCTransition attribute
tmds Jun 17, 2021
6cc2d89
Update comment in SystemNative_InitializeTerminalAndSignalHandling
tmds Jun 17, 2021
5892f0d
Run original handler except for cancelable signals.
tmds Jun 17, 2021
f337677
Cleanup ControlCHandlerRegistrar
tmds Jun 17, 2021
c3dce04
Handle TryGetTarget returning false due to finalized PosixSignalRegis…
tmds Jun 17, 2021
db75bba
Use Thread.UnsafeStart
tmds Jun 17, 2021
96ded59
Remove SuppressGCTransition from methods that take a lock
tmds Jun 17, 2021
55f1abe
Support canceling terminal configuration on SIGCHLD/SIGCONT
tmds Jun 18, 2021
7a2594c
Throw for errno using Interop.CheckIO
tmds Jun 18, 2021
9c27d6e
Rename DefaultSignalHandler to HandleNonCanceledPosixSignal
tmds Jun 18, 2021
b5ed74d
Register Console SIGTTOU with SA_RESETHAND
tmds Jun 21, 2021
76b8704
Allocate storage for tracking signals dynamically
tmds Jun 21, 2021
5f5deb3
Propagate sigaction errors when enabling PosixSignal
tmds Jun 21, 2021
03c03b8
Add some tests
tmds Jun 21, 2021
6f0c69b
Fix entrypoints
tmds Jun 21, 2021
d873120
Fix compilation
tmds Jun 21, 2021
bc1590c
Add some more tests
tmds Jun 21, 2021
e8827ce
Move tests to PosixSignalRegistrationTests.Unix file
tmds Jun 21, 2021
511f604
Add SignalCanCancelTermination test
tmds Jun 21, 2021
1d15e42
ConfigureTerminalForChildProcesses: split Unix and iOS
tmds Jun 21, 2021
a760612
Fix iOS compilation failure
tmds Jun 21, 2021
dddc5bc
Skip signals that cause xunit to exit with non zero
tmds Jun 21, 2021
d4c8e24
Try fix Android compilation
tmds Jun 21, 2021
12150ab
Remove SIGSTOP from UninstallableSignalsThrow because it doesn't thro…
tmds Jun 22, 2021
469b6fe
Cleanup
tmds Jun 22, 2021
38a4d76
Handle case where all handlers got disposed by the time we want to ca…
tmds Jun 22, 2021
8841d41
GenerateReferenceAssemblySource
tmds Jun 22, 2021
c2ef9eb
Replace PosixSignalRegistration.Unsupported with .Windows/.Browser file
tmds Jun 22, 2021
575dd7d
Remove assert(g_hasTty) from UninitializeTerminal
tmds Jun 23, 2021
3756ac2
Initialize signal handling when ifndef HAS_CONSOLE_SIGNALS
tmds Jun 23, 2021
778350f
Fix broken Cancel
tmds Jun 23, 2021
ed39929
Use SIGRTMAX as highest usable signal number.
tmds Jun 23, 2021
3c02835
SIGRTMAX is not defined on all platforms, fall back to NSIG
tmds Jun 23, 2021
8ccfd3e
Resend signal only when restored to SIG_DFL
tmds Jun 23, 2021
481f40e
SignalCanCancelTermination test: increase timeout
tmds Jun 23, 2021
669e09f
Increase timeout to 10min
tmds Jun 23, 2021
2cb8cda
Update expected SIGQUIT exit code for mono
tmds Jun 24, 2021
459f3e6
Change isMono check
tmds Jun 24, 2021
834350f
Use PlatformDetection.IsMonoRuntime
tmds Jun 29, 2021
c8cb449
Add IsSignalThatTerminates method
tmds Jun 29, 2021
cba68f3
Add some documentation xml
tmds Jun 29, 2021
19d30d6
Console.ManualTests: test terminal echo during and after child proces…
tmds Jun 29, 2021
e4cef47
Maintain flags and mask of original handler
tmds Jun 30, 2021
aa549a3
PR feedback
tmds Jun 30, 2021
324db13
SystemNative_HandleNonCanceledPosixSignal: update handling based on d…
tmds Jun 30, 2021
8e830fe
Apply suggestions from code review
tmds Jul 1, 2021
85439d6
Don't call sa_sigaction/sa_handler twice from SystemNative_HandleNonC…
tmds Jul 1, 2021
b8a0b5d
Don't remove WeakReferences while iterating.
tmds Jul 1, 2021
18b7139
Move static fields to the top of the class
tmds Jul 1, 2021
d136c5b
Remove -Wcast-qual ignore
tmds Jul 1, 2021
be93c17
PosixSignalContext: add XML docs
tmds Jul 1, 2021
4de318a
Fix Android compilation
tmds Jul 1, 2021
6898402
Fix Android compilation, take II
tmds Jul 1, 2021
b8234bd
Fix comment
tmds Jul 7, 2021
f1aee19
Add PosixSignalContext constructor test
tmds Jul 7, 2021
005cddd
SystemNative_HandleNonCanceledPosixSignal: add SIG_IGN case
tmds Jul 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Sys
{
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetPosixSignalHandler")]
[SuppressGCTransition]
internal static extern unsafe void SetPosixSignalHandler(delegate* unmanaged<int, PosixSignal, int> handler);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_EnablePosixSignalHandling", SetLastError = true)]
internal static extern bool EnablePosixSignalHandling(int signal);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_DisablePosixSignalHandling")]
tmds marked this conversation as resolved.
Show resolved Hide resolved
internal static extern void DisablePosixSignalHandling(int signal);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_HandleNonCanceledPosixSignal")]
internal static extern bool HandleNonCanceledPosixSignal(int signal, int handlersDisposed);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPlatformSignalNumber")]
[SuppressGCTransition]
tmds marked this conversation as resolved.
Show resolved Hide resolved
internal static extern int GetPlatformSignalNumber(PosixSignal signal);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ internal static partial class Interop
internal static partial class Sys
{
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_RegisterForSigChld")]
internal static extern unsafe void RegisterForSigChld(delegate* unmanaged<int, void> handler);
internal static extern unsafe void RegisterForSigChld(delegate* unmanaged<int, int, int> handler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ internal static partial class Interop
{
internal static partial class Sys
{
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_RestoreAndHandleCtrl")]
internal static extern void RestoreAndHandleCtrl(CtrlCode ctrlCode);
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetDelayedSigChildConsoleConfigurationHandler")]
[SuppressGCTransition]
internal static extern unsafe void SetDelayedSigChildConsoleConfigurationHandler(delegate* unmanaged<void> callback);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ internal static partial class Interop
internal static partial class Sys
{
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetTerminalInvalidationHandler")]
[SuppressGCTransition]
internal static extern unsafe void SetTerminalInvalidationHandler(delegate* unmanaged<void> handler);
}
}
9 changes: 6 additions & 3 deletions src/libraries/Native/Unix/System.Native/entrypoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,8 @@ static const Entry s_sysNative[] =
DllImportEntry(SystemNative_GetOSArchitecture)
DllImportEntry(SystemNative_GetProcessArchitecture)
DllImportEntry(SystemNative_SearchPath)
DllImportEntry(SystemNative_RegisterForCtrl)
DllImportEntry(SystemNative_UnregisterForCtrl)
DllImportEntry(SystemNative_RegisterForSigChld)
DllImportEntry(SystemNative_RestoreAndHandleCtrl)
DllImportEntry(SystemNative_SetDelayedSigChildConsoleConfigurationHandler)
DllImportEntry(SystemNative_SetTerminalInvalidationHandler)
DllImportEntry(SystemNative_InitializeTerminalAndSignalHandling)
DllImportEntry(SystemNative_SNPrintF)
Expand Down Expand Up @@ -251,6 +249,11 @@ static const Entry s_sysNative[] =
DllImportEntry(SystemNative_PWrite)
DllImportEntry(SystemNative_PReadV)
DllImportEntry(SystemNative_PWriteV)
DllImportEntry(SystemNative_EnablePosixSignalHandling)
DllImportEntry(SystemNative_DisablePosixSignalHandling)
DllImportEntry(SystemNative_HandleNonCanceledPosixSignal)
DllImportEntry(SystemNative_SetPosixSignalHandler)
DllImportEntry(SystemNative_GetPlatformSignalNumber)
};

EXTERN_C const void* SystemResolveDllImport(const char* name);
Expand Down
23 changes: 4 additions & 19 deletions src/libraries/Native/Unix/System.Native/pal_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,11 @@ static bool g_hasTty = false; // cache we are not a tty

static volatile bool g_receivedSigTtou = false;

static void ttou_handler(int signo)
static void ttou_handler()
{
(void)signo;
g_receivedSigTtou = true;
}

static void InstallTTOUHandler(void (*handler)(int), int flags)
{
struct sigaction action;
memset(&action, 0, sizeof(action));
action.sa_handler = handler;
action.sa_flags = flags;
int rvSigaction = sigaction(SIGTTOU, &action, NULL);
assert(rvSigaction == 0);
(void)rvSigaction;
}

static bool TcSetAttr(struct termios* termios, bool blockIfBackground)
{
if (g_terminalUninitialized)
Expand All @@ -131,7 +119,7 @@ static bool TcSetAttr(struct termios* termios, bool blockIfBackground)
// stdout. We set SA_RESETHAND to avoid that handler's write loops infinitly
// on EINTR when the process is running in background and the terminal
// configured with TOSTOP.
InstallTTOUHandler(ttou_handler, (int)SA_RESETHAND);
InstallTTOUHandlerForConsole(ttou_handler);

g_receivedSigTtou = false;
}
Expand All @@ -147,8 +135,7 @@ static bool TcSetAttr(struct termios* termios, bool blockIfBackground)
rv = true;
}

// Restore default SIGTTOU handler.
InstallTTOUHandler(SIG_DFL, 0);
UninstallTTOUHandlerForConsole();
}

// On success, update the cached value.
Expand Down Expand Up @@ -205,8 +192,6 @@ static bool ConfigureTerminal(bool signalForBreak, bool forChild, uint8_t minCha

void UninitializeTerminal()
{
assert(g_hasTty);

// This method is called on SIGQUIT/SIGINT from the signal dispatching thread
// and on atexit.

Expand Down Expand Up @@ -473,7 +458,7 @@ int32_t SystemNative_InitializeTerminalAndSignalHandling()
{
static int32_t initialized = 0;

// Both the Process and Console class call this method for initialization.
// The Process, Console and PosixSignalRegistration classes call this method for initialization.
if (pthread_mutex_lock(&g_lock) == 0)
{
if (initialized == 0)
Expand Down
Loading