1*220aa0f4SKonstantin Belousov /*-
2*220aa0f4SKonstantin Belousov * SPDX-License-Identifier: BSD-3-Clause
3*220aa0f4SKonstantin Belousov *
4*220aa0f4SKonstantin Belousov * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
5*220aa0f4SKonstantin Belousov * All rights reserved.
6*220aa0f4SKonstantin Belousov *
7*220aa0f4SKonstantin Belousov * Copyright 2024 The FreeBSD Foundation
8*220aa0f4SKonstantin Belousov *
9*220aa0f4SKonstantin Belousov * Portions of this software were developed by Konstantin Belousov
10*220aa0f4SKonstantin Belousov * <kib@FreeBSD.org> under sponsorship from the FreeBSD Foundation.
11*220aa0f4SKonstantin Belousov *
12*220aa0f4SKonstantin Belousov * Redistribution and use in source and binary forms, with or without
13*220aa0f4SKonstantin Belousov * modification, are permitted provided that the following conditions
14*220aa0f4SKonstantin Belousov * are met:
15*220aa0f4SKonstantin Belousov * 1. Redistributions of source code must retain the above copyright
16*220aa0f4SKonstantin Belousov * notice, this list of conditions and the following disclaimer.
17*220aa0f4SKonstantin Belousov * 2. Redistributions in binary form must reproduce the above copyright
18*220aa0f4SKonstantin Belousov * notice, this list of conditions and the following disclaimer in the
19*220aa0f4SKonstantin Belousov * documentation and/or other materials provided with the distribution.
20*220aa0f4SKonstantin Belousov * 3. Neither the name of the author nor the names of any co-contributors
21*220aa0f4SKonstantin Belousov * may be used to endorse or promote products derived from this software
22*220aa0f4SKonstantin Belousov * without specific prior written permission.
23*220aa0f4SKonstantin Belousov *
24*220aa0f4SKonstantin Belousov * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
25*220aa0f4SKonstantin Belousov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26*220aa0f4SKonstantin Belousov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27*220aa0f4SKonstantin Belousov * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28*220aa0f4SKonstantin Belousov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29*220aa0f4SKonstantin Belousov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30*220aa0f4SKonstantin Belousov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31*220aa0f4SKonstantin Belousov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32*220aa0f4SKonstantin Belousov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33*220aa0f4SKonstantin Belousov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34*220aa0f4SKonstantin Belousov * SUCH DAMAGE.
35*220aa0f4SKonstantin Belousov */
36*220aa0f4SKonstantin Belousov
37*220aa0f4SKonstantin Belousov #include "namespace.h"
38*220aa0f4SKonstantin Belousov #include <errno.h>
39*220aa0f4SKonstantin Belousov #include <signal.h>
40*220aa0f4SKonstantin Belousov #include <pthread.h>
41*220aa0f4SKonstantin Belousov #include "un-namespace.h"
42*220aa0f4SKonstantin Belousov
43*220aa0f4SKonstantin Belousov #include "thr_private.h"
44*220aa0f4SKonstantin Belousov
45*220aa0f4SKonstantin Belousov __weak_reference(_Tthr_sigqueue, _pthread_sigqueue);
46*220aa0f4SKonstantin Belousov __weak_reference(_Tthr_sigqueue, pthread_sigqueue);
47*220aa0f4SKonstantin Belousov
48*220aa0f4SKonstantin Belousov int
_Tthr_sigqueue(pthread_t pthread,int sig,const union sigval value)49*220aa0f4SKonstantin Belousov _Tthr_sigqueue(pthread_t pthread, int sig, const union sigval value)
50*220aa0f4SKonstantin Belousov {
51*220aa0f4SKonstantin Belousov struct pthread *curthread;
52*220aa0f4SKonstantin Belousov int e, ret;
53*220aa0f4SKonstantin Belousov
54*220aa0f4SKonstantin Belousov if (sig < 0 || sig > _SIG_MAXSIG)
55*220aa0f4SKonstantin Belousov return (EINVAL);
56*220aa0f4SKonstantin Belousov
57*220aa0f4SKonstantin Belousov curthread = _get_curthread();
58*220aa0f4SKonstantin Belousov ret = 0;
59*220aa0f4SKonstantin Belousov
60*220aa0f4SKonstantin Belousov if (curthread == pthread) {
61*220aa0f4SKonstantin Belousov if (sig > 0) {
62*220aa0f4SKonstantin Belousov e = sigqueue(pthread->tid, sig | __SIGQUEUE_TID,
63*220aa0f4SKonstantin Belousov value);
64*220aa0f4SKonstantin Belousov if (e == -1)
65*220aa0f4SKonstantin Belousov ret = errno;
66*220aa0f4SKonstantin Belousov }
67*220aa0f4SKonstantin Belousov } else if ((ret = _thr_find_thread(curthread, pthread,
68*220aa0f4SKonstantin Belousov 0)) == 0) {
69*220aa0f4SKonstantin Belousov if (sig > 0) {
70*220aa0f4SKonstantin Belousov e = sigqueue(pthread->tid, sig | __SIGQUEUE_TID,
71*220aa0f4SKonstantin Belousov value);
72*220aa0f4SKonstantin Belousov if (e == -1)
73*220aa0f4SKonstantin Belousov ret = errno;
74*220aa0f4SKonstantin Belousov }
75*220aa0f4SKonstantin Belousov THR_THREAD_UNLOCK(curthread, pthread);
76*220aa0f4SKonstantin Belousov }
77*220aa0f4SKonstantin Belousov
78*220aa0f4SKonstantin Belousov return (ret);
79*220aa0f4SKonstantin Belousov }
80