mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-05 19:35:52 +03:00
* hurd/Makefile: add new tests * hurd/test-sig-rpc-interrupted.c: check xstate save and restore in the case where a signal is delivered to a thread which is waiting for an rpc. This test implements the rpc interruption protocol used by the hurd servers. It was so far passing on Debian thanks to the local-intr-msg-clobber.diff patch, which is now obsolete. * hurd/test-sig-xstate.c: check xstate save and restore in the case where a signal is delivered to a running thread, making sure that the xstate is modified in the signal handler. * hurd/test-xstate.h: add helpers to test xstate * sysdeps/mach/hurd/i386/bits/sigcontext.h: add xstate to the sigcontext structure. + sysdeps/mach/hurd/i386/sigreturn.c: restore xstate from the saved context * sysdeps/mach/hurd/x86/trampoline.c: save xstate if supported. Otherwise we fall back to the previous behaviour of ignoring xstate. * sysdeps/mach/hurd/x86_64/bits/sigcontext.h: add xstate to the sigcontext structure. * sysdeps/mach/hurd/x86_64/sigreturn.c: restore xstate from the saved context Signed-off-by: Luca Dariz <luca@orpolo.org> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Message-ID: <20250319171118.142163-1-luca@orpolo.org>
95 lines
2.4 KiB
C
95 lines
2.4 KiB
C
/* Test the state save/restore procedures during signal handling.
|
|
|
|
Copyright (C) 2025 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<https://www.gnu.org/licenses/>. */
|
|
|
|
|
|
#include <assert.h>
|
|
#include <pthread.h>
|
|
#include <signal.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include <mach/message.h>
|
|
#include <mach/gnumach.h>
|
|
#include <mach/mach_traps.h>
|
|
#include <mach-shortcuts.h>
|
|
#include <mach_init.h>
|
|
#include <hurd/io.h>
|
|
#include <hurd/io_reply.h>
|
|
|
|
#include <support/check.h>
|
|
#include <support/xthread.h>
|
|
|
|
#include "test-xstate.h"
|
|
|
|
static volatile bool loopflag = true;
|
|
|
|
void handler (int signum, siginfo_t *info, void *context)
|
|
{
|
|
char buf3[XSTATE_BUFFER_SIZE];
|
|
memset (buf3, 0x77, XSTATE_BUFFER_SIZE);
|
|
SET_XSTATE (buf3);
|
|
printf ("signal %d setting a different CPU state\n", signum);
|
|
loopflag = false;
|
|
}
|
|
|
|
/* Helper thread to send a signal to the main thread */
|
|
void* signal_sender (void *arg)
|
|
{
|
|
sigset_t ss;
|
|
assert (! sigemptyset (&ss));
|
|
assert (! sigaddset (&ss, SIGUSR1));
|
|
assert (! sigprocmask (SIG_BLOCK, &ss, NULL));
|
|
|
|
TEST_COMPARE (kill (getpid (), SIGUSR1), 0);
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static int do_test (void)
|
|
{
|
|
#if ! XSTATE_HELPERS_SUPPORTED
|
|
FAIL_UNSUPPORTED ("Test not supported on this arch.");
|
|
#endif
|
|
|
|
struct sigaction act = { 0 };
|
|
act.sa_sigaction = &handler;
|
|
TEST_COMPARE (sigaction (SIGUSR1, &act, NULL), 0);
|
|
|
|
pthread_t thsender = xpthread_create (NULL, signal_sender, NULL);
|
|
|
|
char buf1[XSTATE_BUFFER_SIZE], buf2[XSTATE_BUFFER_SIZE];
|
|
memset (buf1, 0x33, XSTATE_BUFFER_SIZE);
|
|
|
|
SET_XSTATE (buf1);
|
|
|
|
while (loopflag)
|
|
;
|
|
|
|
GET_XSTATE (buf2);
|
|
TEST_COMPARE_BLOB (buf1, sizeof (buf1), buf2, sizeof (buf2));
|
|
|
|
xpthread_join (thsender);
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
#include <support/test-driver.c>
|