1d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes/*
239bac055674d23770b9a724221b728e443196ea7Elliott Hughes * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
3d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * All rights reserved.
4d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes *
5d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * Redistribution and use in source and binary forms, with or without
6d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * modification, are permitted provided that the following conditions
7d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * are met:
8d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * 1. Redistributions of source code must retain the above copyright
9d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes *    notice, this list of conditions and the following disclaimer.
10d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * 2. Redistributions in binary form must reproduce the above copyright
11d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes *    notice, this list of conditions and the following disclaimer in the
12d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes *    documentation and/or other materials provided with the distribution.
13d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * 3. The name of the author may not be used to endorse or promote products
14d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes *    derived from this software without specific prior written permission.
15d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes *
16d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes */
27d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes
28d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes#include "tests.h"
2939bac055674d23770b9a724221b728e443196ea7Elliott Hughes#include <asm/unistd.h>
30d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes
3139bac055674d23770b9a724221b728e443196ea7Elliott Hughes#if defined __powerpc64__ \
3239bac055674d23770b9a724221b728e443196ea7Elliott Hughes || (defined __sparc__ && defined __arch64__)
3339bac055674d23770b9a724221b728e443196ea7Elliott Hughes/* Old sigreturn is defined but not implemented in the kernel. */
3439bac055674d23770b9a724221b728e443196ea7Elliott Hughes# undef __NR_sigreturn
35d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes#endif
36d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes
3739bac055674d23770b9a724221b728e443196ea7Elliott Hughes#ifdef __NR_sigreturn
3839bac055674d23770b9a724221b728e443196ea7Elliott Hughes
3939bac055674d23770b9a724221b728e443196ea7Elliott Hughes# include <signal.h>
4039bac055674d23770b9a724221b728e443196ea7Elliott Hughes# include <stdio.h>
4139bac055674d23770b9a724221b728e443196ea7Elliott Hughes# include <stdlib.h>
4239bac055674d23770b9a724221b728e443196ea7Elliott Hughes
4339bac055674d23770b9a724221b728e443196ea7Elliott Hughes# ifdef ASM_SIGRTMIN
4439bac055674d23770b9a724221b728e443196ea7Elliott Hughes#  define RT_0 ASM_SIGRTMIN
4539bac055674d23770b9a724221b728e443196ea7Elliott Hughes# else
4639bac055674d23770b9a724221b728e443196ea7Elliott Hughes/* Linux kernel >= 3.18 defines SIGRTMIN to 32 on all architectures. */
4739bac055674d23770b9a724221b728e443196ea7Elliott Hughes#  define RT_0 32
4839bac055674d23770b9a724221b728e443196ea7Elliott Hughes# endif
4939bac055674d23770b9a724221b728e443196ea7Elliott Hughes
5039bac055674d23770b9a724221b728e443196ea7Elliott Hughesstatic void
5139bac055674d23770b9a724221b728e443196ea7Elliott Hugheshandler(int sig)
52d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes{
53d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes}
54d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes
5539bac055674d23770b9a724221b728e443196ea7Elliott Hughesint
5639bac055674d23770b9a724221b728e443196ea7Elliott Hughesmain(void)
5739bac055674d23770b9a724221b728e443196ea7Elliott Hughes{
5839bac055674d23770b9a724221b728e443196ea7Elliott Hughes	static sigset_t set;
59d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes	sigemptyset(&set);
6039bac055674d23770b9a724221b728e443196ea7Elliott Hughes	sigaddset(&set, SIGINT);
61d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes	sigaddset(&set, SIGUSR2);
62d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes	sigaddset(&set, SIGCHLD);
63d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes	sigaddset(&set, RT_0 +  3);
64d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes	sigaddset(&set, RT_0 +  4);
65d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes	sigaddset(&set, RT_0 +  5);
66d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes	sigaddset(&set, RT_0 + 26);
67d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes	sigaddset(&set, RT_0 + 27);
6839bac055674d23770b9a724221b728e443196ea7Elliott Hughes	if (sigprocmask(SIG_SETMASK, &set, NULL))
6939bac055674d23770b9a724221b728e443196ea7Elliott Hughes		perror_msg_and_fail("sigprocmask");
7039bac055674d23770b9a724221b728e443196ea7Elliott Hughes	sigemptyset(&set);
7139bac055674d23770b9a724221b728e443196ea7Elliott Hughes
7239bac055674d23770b9a724221b728e443196ea7Elliott Hughes	/* This should result to old sigreturn. */
7339bac055674d23770b9a724221b728e443196ea7Elliott Hughes	if (signal(SIGUSR1, handler) == SIG_ERR)
7439bac055674d23770b9a724221b728e443196ea7Elliott Hughes		perror_msg_and_fail("sigaction");
7539bac055674d23770b9a724221b728e443196ea7Elliott Hughes
7639bac055674d23770b9a724221b728e443196ea7Elliott Hughes	if (raise(SIGUSR1))
7739bac055674d23770b9a724221b728e443196ea7Elliott Hughes		perror_msg_and_fail("raise");
7839bac055674d23770b9a724221b728e443196ea7Elliott Hughes
7939bac055674d23770b9a724221b728e443196ea7Elliott Hughes	static const char *const sigs =
8039bac055674d23770b9a724221b728e443196ea7Elliott Hughes		(SIGUSR2 < SIGCHLD) ? "INT USR2 CHLD" : "INT CHLD USR2";
8139bac055674d23770b9a724221b728e443196ea7Elliott Hughes	static const char *const rt_sigs = "RT_3 RT_4 RT_5 RT_26 RT_27";
8239bac055674d23770b9a724221b728e443196ea7Elliott Hughes	printf("sigreturn({mask=[%s %s]}) = 0\n", sigs, rt_sigs);
8339bac055674d23770b9a724221b728e443196ea7Elliott Hughes
8439bac055674d23770b9a724221b728e443196ea7Elliott Hughes	puts("+++ exited with 0 +++");
85d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes	return 0;
86d35df493b4e7684c50d2d2fa032ee3a7ac228009Elliott Hughes}
8739bac055674d23770b9a724221b728e443196ea7Elliott Hughes
8839bac055674d23770b9a724221b728e443196ea7Elliott Hughes#else
8939bac055674d23770b9a724221b728e443196ea7Elliott Hughes
9039bac055674d23770b9a724221b728e443196ea7Elliott HughesSKIP_MAIN_UNDEFINED("__NR_sigreturn")
9139bac055674d23770b9a724221b728e443196ea7Elliott Hughes
9239bac055674d23770b9a724221b728e443196ea7Elliott Hughes#endif
93