xref: /netbsd-src/tests/rump/kernspace/sendsig.c (revision 0eaaa024ea5a271b8f91fe07fe846a86f31dd9b9)
1*0eaaa024Sad /*	$NetBSD: sendsig.c,v 1.2 2020/05/23 23:42:44 ad Exp $	*/
2054b6364Spooka 
3054b6364Spooka /*-
4054b6364Spooka  * Copyright (c) 2011 The NetBSD Foundation, Inc.
5054b6364Spooka  * All rights reserved.
6054b6364Spooka  *
7054b6364Spooka  * Redistribution and use in source and binary forms, with or without
8054b6364Spooka  * modification, are permitted provided that the following conditions
9054b6364Spooka  * are met:
10054b6364Spooka  * 1. Redistributions of source code must retain the above copyright
11054b6364Spooka  *    notice, this list of conditions and the following disclaimer.
12054b6364Spooka  * 2. Redistributions in binary form must reproduce the above copyright
13054b6364Spooka  *    notice, this list of conditions and the following disclaimer in the
14054b6364Spooka  *    documentation and/or other materials provided with the distribution.
15054b6364Spooka  *
16054b6364Spooka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17054b6364Spooka  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18054b6364Spooka  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19054b6364Spooka  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20054b6364Spooka  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21054b6364Spooka  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22054b6364Spooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23054b6364Spooka  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24054b6364Spooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25054b6364Spooka  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26054b6364Spooka  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27054b6364Spooka  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28054b6364Spooka  */
29054b6364Spooka 
30054b6364Spooka #include <sys/cdefs.h>
31054b6364Spooka #if !defined(lint)
32*0eaaa024Sad __RCSID("$NetBSD: sendsig.c,v 1.2 2020/05/23 23:42:44 ad Exp $");
33054b6364Spooka #endif /* !lint */
34054b6364Spooka 
35054b6364Spooka #include <sys/param.h>
36054b6364Spooka #include <sys/proc.h>
37054b6364Spooka 
38054b6364Spooka #include <rump/rump.h>
39054b6364Spooka 
40054b6364Spooka #include "kernspace.h"
41054b6364Spooka 
42054b6364Spooka /*
43054b6364Spooka  * loop until a non-system process appears and we can send it a signal
44054b6364Spooka  */
45054b6364Spooka void
rumptest_sendsig(char * signo)46054b6364Spooka rumptest_sendsig(char *signo)
47054b6364Spooka {
48054b6364Spooka 	struct proc *p;
49054b6364Spooka 	bool sent = false;
50054b6364Spooka 	int sig;
51054b6364Spooka 
52054b6364Spooka 	sig = strtoull(signo, NULL, 10);
53054b6364Spooka 	rump_boot_setsigmodel(RUMP_SIGMODEL_RAISE);
54054b6364Spooka 
55*0eaaa024Sad 	mutex_enter(&proc_lock);
56054b6364Spooka 	while (!sent) {
57054b6364Spooka 		PROCLIST_FOREACH(p, &allproc) {
58054b6364Spooka 			if (p->p_pid > 1) {
59054b6364Spooka 				mutex_enter(p->p_lock);
60054b6364Spooka 				psignal(p, sig);
61054b6364Spooka 				mutex_exit(p->p_lock);
62054b6364Spooka 				sent = true;
63054b6364Spooka 				break;
64054b6364Spooka 			}
65054b6364Spooka 		}
66*0eaaa024Sad 		kpause("w8", false, 1, &proc_lock);
67054b6364Spooka 	}
68*0eaaa024Sad 	mutex_exit(&proc_lock);
69054b6364Spooka 
70054b6364Spooka 	/* restore default */
71054b6364Spooka 	rump_boot_setsigmodel(RUMP_SIGMODEL_PANIC);
72054b6364Spooka }
73054b6364Spooka 
74054b6364Spooka void
rumptest_localsig(int signo)75054b6364Spooka rumptest_localsig(int signo)
76054b6364Spooka {
77054b6364Spooka 	struct proc *p = curproc;
78054b6364Spooka 
79054b6364Spooka 	mutex_enter(p->p_lock);
80054b6364Spooka 	psignal(p, signo);
81054b6364Spooka 	mutex_exit(p->p_lock);
82054b6364Spooka }
83