2 * Copyright (c) 2003, 2004 Jeffrey M. Hsu. All rights reserved.
3 * Copyright (c) 2003, 2004 The DragonFly Project. All rights reserved.
5 * This code is derived from software contributed to The DragonFly Project
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of The DragonFly Project nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific, prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * $DragonFly: src/sys/kern/uipc_msg.c,v 1.26 2008/10/27 02:56:30 sephe Exp $
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/msgport.h>
40 #include <sys/protosw.h>
41 #include <sys/socket.h>
42 #include <sys/socketvar.h>
43 #include <sys/socketops.h>
44 #include <sys/thread.h>
45 #include <sys/thread2.h>
46 #include <sys/msgport2.h>
48 #include <net/netmsg2.h>
50 #include <net/netisr.h>
51 #include <net/netmsg.h>
54 * Abort a socket and free it. Called from soabort() only.
56 * The SS_ABORTING flag must already be set.
59 so_pru_abort(struct socket
*so
)
61 struct netmsg_pru_abort msg
;
64 KKASSERT(so
->so_state
& SS_ABORTING
);
65 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_ABORT
);
66 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
,
68 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_abort
;
70 (void)lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
74 * Abort a socket and free it, asynchronously. Called from
77 * The SS_ABORTING flag must already be set.
80 so_pru_aborta(struct socket
*so
)
82 struct netmsg_pru_abort
*msg
;
85 KKASSERT(so
->so_state
& SS_ABORTING
);
86 msg
= kmalloc(sizeof(*msg
), M_LWKTMSG
, M_WAITOK
| M_ZERO
);
87 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_ABORT
);
88 netmsg_init(&msg
->nm_netmsg
, &netisr_afree_rport
,
90 msg
->nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_abort
;
92 lwkt_sendmsg(port
, &msg
->nm_netmsg
.nm_lmsg
);
96 * Abort a socket and free it. Called from soabort_oncpu() only.
97 * Caller must make sure that the current CPU is inpcb's owner CPU.
99 * The SS_ABORTING flag must already be set.
102 so_pru_abort_oncpu(struct socket
*so
)
104 so
->so_proto
->pr_usrreqs
->pru_abort(so
);
108 so_pru_accept(struct socket
*so
, struct sockaddr
**nam
)
110 /* Block (memory allocation) in process context. XXX JH */
111 return ((*so
->so_proto
->pr_usrreqs
->pru_accept
)(so
, nam
));
115 struct netmsg_pru_accept msg
;
118 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_ACCEPT
);
119 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
121 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_accept
;
124 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
130 so_pru_attach(struct socket
*so
, int proto
, struct pru_attach_info
*ai
)
133 struct netmsg_pru_attach msg
;
136 port
= so
->so_proto
->pr_mport(NULL
, NULL
, NULL
, PRU_ATTACH
);
137 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
139 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_attach
;
141 msg
.nm_proto
= proto
;
143 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
148 so_pru_bind(struct socket
*so
, struct sockaddr
*nam
, struct thread
*td
)
151 struct netmsg_pru_bind msg
;
154 /* Send mesg to thread for new address. */
155 port
= so
->so_proto
->pr_mport(NULL
, nam
, NULL
, PRU_BIND
);
156 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
158 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_bind
;
161 msg
.nm_td
= td
; /* used only for prison_ip() XXX JH */
162 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
167 so_pru_connect(struct socket
*so
, struct sockaddr
*nam
, struct thread
*td
)
170 struct netmsg_pru_connect msg
;
173 port
= so
->so_proto
->pr_mport(so
, nam
, NULL
, PRU_CONNECT
);
174 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
176 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_connect
;
180 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
185 so_pru_connect2(struct socket
*so1
, struct socket
*so2
)
188 struct netmsg_pru_connect2 msg
;
191 port
= so1
->so_proto
->pr_mport(so1
, NULL
, NULL
, PRU_CONNECT2
);
192 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
193 netmsg_pru_connect2
);
194 msg
.nm_prufn
= so1
->so_proto
->pr_usrreqs
->pru_connect2
;
197 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
202 so_pru_control(struct socket
*so
, u_long cmd
, caddr_t data
, struct ifnet
*ifp
)
204 return ((*so
->so_proto
->pr_usrreqs
->pru_control
)(so
, cmd
, data
, ifp
,
206 #ifdef gag /* does copyin and copyout deep inside stack XXX JH */
208 struct netmsg_pru_control msg
;
211 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_CONTROL
);
212 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
214 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_control
;
220 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
226 so_pru_detach(struct socket
*so
)
229 struct netmsg_pru_detach msg
;
232 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_DETACH
);
233 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
235 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_detach
;
237 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
242 so_pru_disconnect(struct socket
*so
)
245 struct netmsg_pru_disconnect msg
;
248 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_DISCONNECT
);
249 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
250 netmsg_pru_disconnect
);
251 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_disconnect
;
253 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
258 so_pru_listen(struct socket
*so
, struct thread
*td
)
261 struct netmsg_pru_listen msg
;
264 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_LISTEN
);
265 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
267 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_listen
;
269 msg
.nm_td
= td
; /* used only for prison_ip() XXX JH */
270 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
275 so_pru_peeraddr(struct socket
*so
, struct sockaddr
**nam
)
278 struct netmsg_pru_peeraddr msg
;
281 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_PEERADDR
);
282 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
283 netmsg_pru_peeraddr
);
284 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_peeraddr
;
287 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
292 so_pru_rcvd(struct socket
*so
, int flags
)
295 struct netmsg_pru_rcvd msg
;
298 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_RCVD
);
299 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
301 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_rcvd
;
303 msg
.nm_flags
= flags
;
304 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
309 so_pru_rcvoob(struct socket
*so
, struct mbuf
*m
, int flags
)
312 struct netmsg_pru_rcvoob msg
;
315 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_RCVOOB
);
316 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
318 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_rcvoob
;
321 msg
.nm_flags
= flags
;
322 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
327 so_pru_send(struct socket
*so
, int flags
, struct mbuf
*m
, struct sockaddr
*addr
,
328 struct mbuf
*control
, struct thread
*td
)
331 struct netmsg_pru_send msg
;
334 port
= so
->so_proto
->pr_mport(so
, addr
, &m
, PRU_SEND
);
340 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
342 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_send
;
344 msg
.nm_flags
= flags
;
347 msg
.nm_control
= control
;
349 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
354 so_pru_sense(struct socket
*so
, struct stat
*sb
)
357 struct netmsg_pru_sense msg
;
360 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_SENSE
);
361 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
363 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_sense
;
366 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
371 so_pru_shutdown(struct socket
*so
)
374 struct netmsg_pru_shutdown msg
;
377 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_SHUTDOWN
);
378 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
379 netmsg_pru_shutdown
);
380 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_shutdown
;
382 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
387 so_pru_sockaddr(struct socket
*so
, struct sockaddr
**nam
)
390 struct netmsg_pru_sockaddr msg
;
393 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_SOCKADDR
);
394 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
395 netmsg_pru_sockaddr
);
396 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_sockaddr
;
399 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
404 so_pru_sopoll(struct socket
*so
, int events
, struct ucred
*cred
)
407 struct netmsg_pru_sopoll msg
;
410 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_SOPOLL
);
411 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
413 msg
.nm_prufn
= so
->so_proto
->pr_usrreqs
->pru_sopoll
;
415 msg
.nm_events
= events
;
417 msg
.nm_td
= curthread
;
418 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
423 so_pru_ctloutput(struct socket
*so
, struct sockopt
*sopt
)
425 struct netmsg_pru_ctloutput msg
;
429 KKASSERT(!sopt
->sopt_val
|| kva_p(sopt
->sopt_val
));
430 port
= so
->so_proto
->pr_mport(so
, NULL
, NULL
, PRU_CTLOUTPUT
);
431 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
432 netmsg_pru_ctloutput
);
433 /* TBD: move pr_ctloutput to pr_usrreqs */
434 msg
.nm_prufn
= so
->so_proto
->pr_ctloutput
;
437 error
= lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
442 * Protocol control input, typically via icmp.
444 * If the protocol pr_ctlport is not NULL we call it to figure out the
445 * protocol port. If NULL is returned we can just return, otherwise
446 * we issue a netmsg to call pr_ctlinput in the proper thread.
448 * This must be done synchronously as arg and/or extra may point to
452 so_pru_ctlinput(struct protosw
*pr
, int cmd
, struct sockaddr
*arg
, void *extra
)
454 struct netmsg_pru_ctlinput msg
;
457 if (pr
->pr_ctlport
== NULL
)
459 KKASSERT(pr
->pr_ctlinput
!= NULL
);
460 port
= pr
->pr_ctlport(cmd
, arg
, extra
);
463 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
464 netmsg_pru_ctlinput
);
465 msg
.nm_prufn
= pr
->pr_ctlinput
;
468 msg
.nm_extra
= extra
;
469 lwkt_domsg(port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
473 * If we convert all the protosw pr_ functions for all the protocols
474 * to take a message directly, this layer can go away. For the moment
475 * our dispatcher ignores the return value, but since we are handling
476 * the replymsg ourselves we return EASYNC by convention.
480 * Abort and destroy a socket.
483 netmsg_pru_abort(netmsg_t msg
)
485 struct netmsg_pru_abort
*nm
= (void *)msg
;
486 struct socket
*so
= nm
->nm_so
;
489 KKASSERT(so
->so_state
& SS_ABORTING
);
490 so
->so_state
&= ~SS_ABORTING
;
491 error
= nm
->nm_prufn(so
);
494 lwkt_replymsg(&msg
->nm_lmsg
, error
);
499 netmsg_pru_accept(netmsg_t msg
)
501 struct netmsg_pru_accept
*nm
= (void *)msg
;
503 lwkt_replymsg(&msg
->nm_lmsg
, nm
->nm_prufn(nm
->nm_so
, nm
->nm_nam
));
508 netmsg_pru_attach(netmsg_t msg
)
510 struct netmsg_pru_attach
*nm
= (void *)msg
;
512 lwkt_replymsg(&msg
->nm_lmsg
,
513 nm
->nm_prufn(nm
->nm_so
, nm
->nm_proto
, nm
->nm_ai
));
517 netmsg_pru_bind(netmsg_t msg
)
519 struct netmsg_pru_bind
*nm
= (void *)msg
;
521 lwkt_replymsg(&msg
->nm_lmsg
,
522 nm
->nm_prufn(nm
->nm_so
, nm
->nm_nam
, nm
->nm_td
));
526 netmsg_pru_connect(netmsg_t msg
)
528 struct netmsg_pru_connect
*nm
= (void *)msg
;
530 lwkt_replymsg(&msg
->nm_lmsg
,
531 nm
->nm_prufn(nm
->nm_so
, nm
->nm_nam
, nm
->nm_td
));
535 netmsg_pru_connect2(netmsg_t msg
)
537 struct netmsg_pru_connect2
*nm
= (void *)msg
;
539 lwkt_replymsg(&msg
->nm_lmsg
, nm
->nm_prufn(nm
->nm_so1
, nm
->nm_so2
));
543 netmsg_pru_control(netmsg_t msg
)
545 struct netmsg_pru_control
*nm
= (void *)msg
;
548 error
= nm
->nm_prufn(nm
->nm_so
, nm
->nm_cmd
, nm
->nm_data
,
549 nm
->nm_ifp
, nm
->nm_td
);
550 lwkt_replymsg(&msg
->nm_lmsg
, error
);
554 netmsg_pru_detach(netmsg_t msg
)
556 struct netmsg_pru_detach
*nm
= (void *)msg
;
558 lwkt_replymsg(&msg
->nm_lmsg
, nm
->nm_prufn(nm
->nm_so
));
562 netmsg_pru_disconnect(netmsg_t msg
)
564 struct netmsg_pru_disconnect
*nm
= (void *)msg
;
566 lwkt_replymsg(&msg
->nm_lmsg
, nm
->nm_prufn(nm
->nm_so
));
570 netmsg_pru_listen(netmsg_t msg
)
572 struct netmsg_pru_listen
*nm
= (void *)msg
;
574 lwkt_replymsg(&msg
->nm_lmsg
, nm
->nm_prufn(nm
->nm_so
, nm
->nm_td
));
578 netmsg_pru_peeraddr(netmsg_t msg
)
580 struct netmsg_pru_peeraddr
*nm
= (void *)msg
;
582 lwkt_replymsg(&msg
->nm_lmsg
, nm
->nm_prufn(nm
->nm_so
, nm
->nm_nam
));
586 netmsg_pru_rcvd(netmsg_t msg
)
588 struct netmsg_pru_rcvd
*nm
= (void *)msg
;
590 lwkt_replymsg(&msg
->nm_lmsg
, nm
->nm_prufn(nm
->nm_so
, nm
->nm_flags
));
594 netmsg_pru_rcvoob(netmsg_t msg
)
596 struct netmsg_pru_rcvoob
*nm
= (void *)msg
;
598 lwkt_replymsg(&msg
->nm_lmsg
,
599 nm
->nm_prufn(nm
->nm_so
, nm
->nm_m
, nm
->nm_flags
));
603 netmsg_pru_send(netmsg_t msg
)
605 struct netmsg_pru_send
*nm
= (void *)msg
;
608 error
= nm
->nm_prufn(nm
->nm_so
, nm
->nm_flags
, nm
->nm_m
,
609 nm
->nm_addr
, nm
->nm_control
, nm
->nm_td
);
610 lwkt_replymsg(&msg
->nm_lmsg
, error
);
614 netmsg_pru_sense(netmsg_t msg
)
616 struct netmsg_pru_sense
*nm
= (void *)msg
;
618 lwkt_replymsg(&msg
->nm_lmsg
, nm
->nm_prufn(nm
->nm_so
, nm
->nm_stat
));
622 netmsg_pru_shutdown(netmsg_t msg
)
624 struct netmsg_pru_shutdown
*nm
= (void *)msg
;
626 lwkt_replymsg(&msg
->nm_lmsg
, nm
->nm_prufn(nm
->nm_so
));
630 netmsg_pru_sockaddr(netmsg_t msg
)
632 struct netmsg_pru_sockaddr
*nm
= (void *)msg
;
634 lwkt_replymsg(&msg
->nm_lmsg
, nm
->nm_prufn(nm
->nm_so
, nm
->nm_nam
));
638 netmsg_pru_sopoll(netmsg_t msg
)
640 struct netmsg_pru_sopoll
*nm
= (void *)msg
;
643 error
= nm
->nm_prufn(nm
->nm_so
, nm
->nm_events
, nm
->nm_cred
, nm
->nm_td
);
644 lwkt_replymsg(&msg
->nm_lmsg
, error
);
648 netmsg_pru_ctloutput(netmsg_t msg
)
650 struct netmsg_pru_ctloutput
*nm
= (void *)msg
;
652 lwkt_replymsg(&msg
->nm_lmsg
, nm
->nm_prufn(nm
->nm_so
, nm
->nm_sopt
));
656 netmsg_pru_ctlinput(netmsg_t msg
)
658 struct netmsg_pru_ctlinput
*nm
= (void *)msg
;
660 nm
->nm_prufn(nm
->nm_cmd
, nm
->nm_arg
, nm
->nm_extra
);
661 lwkt_replymsg(&nm
->nm_netmsg
.nm_lmsg
, 0);
665 netmsg_pr_timeout(netmsg_t msg
)
667 struct netmsg_pr_timeout
*nm
= (void *)msg
;
669 lwkt_replymsg(&msg
->nm_lmsg
, nm
->nm_prfn());
673 * Handle a predicate event request. This function is only called once
674 * when the predicate message queueing request is received.
677 netmsg_so_notify(netmsg_t netmsg
)
679 struct netmsg_so_notify
*msg
= (void *)netmsg
;
680 struct signalsockbuf
*ssb
;
682 ssb
= (msg
->nm_etype
& NM_REVENT
) ?
683 &msg
->nm_so
->so_rcv
:
687 * Reply immediately if the event has occured, otherwise queue the
690 if (msg
->nm_predicate(&msg
->nm_netmsg
)) {
691 lwkt_replymsg(&msg
->nm_netmsg
.nm_lmsg
,
692 msg
->nm_netmsg
.nm_lmsg
.ms_error
);
694 TAILQ_INSERT_TAIL(&ssb
->ssb_sel
.si_mlist
, msg
, nm_list
);
695 ssb
->ssb_flags
|= SSB_MEVENT
;
700 * Called by doio when trying to abort a netmsg_so_notify message.
701 * Unlike the other functions this one is dispatched directly by
702 * the LWKT subsystem, so it takes a lwkt_msg_t as an argument.
704 * The original message, lmsg, is under the control of the caller and
705 * will not be destroyed until we return so we can safely reference it
706 * in our synchronous abort request.
708 * This part of the abort request occurs on the originating cpu which
709 * means we may race the message flags and the original message may
710 * not even have been processed by the target cpu yet.
713 netmsg_so_notify_doabort(lwkt_msg_t lmsg
)
715 struct netmsg_so_notify_abort msg
;
717 if ((lmsg
->ms_flags
& (MSGF_DONE
| MSGF_REPLY
)) == 0) {
718 netmsg_init(&msg
.nm_netmsg
, &curthread
->td_msgport
, 0,
719 netmsg_so_notify_abort
);
720 msg
.nm_notifymsg
= (void *)lmsg
;
721 lwkt_domsg(lmsg
->ms_target_port
, &msg
.nm_netmsg
.nm_lmsg
, 0);
726 * Predicate requests can be aborted. This function is only called once
727 * and will interlock against processing/reply races (since such races
728 * occur on the same thread that controls the port where the abort is
731 * This part of the abort request occurs on the target cpu. The message
732 * flags must be tested again in case the test that we did on the
733 * originating cpu raced. Since messages are handled in sequence, the
734 * original message will have already been handled by the loop and either
735 * replied to or queued.
737 * We really only need to interlock with MSGF_REPLY (a bit that is set on
738 * our cpu when we reply). Note that MSGF_DONE is not set until the
739 * reply reaches the originating cpu. Test both bits anyway.
742 netmsg_so_notify_abort(netmsg_t netmsg
)
744 struct netmsg_so_notify_abort
*abrtmsg
= (void *)netmsg
;
745 struct netmsg_so_notify
*msg
= abrtmsg
->nm_notifymsg
;
746 struct signalsockbuf
*ssb
;
749 * The original notify message is not destroyed until after the
750 * abort request is returned, so we can check its state.
752 if ((msg
->nm_netmsg
.nm_lmsg
.ms_flags
& (MSGF_DONE
| MSGF_REPLY
)) == 0) {
753 ssb
= (msg
->nm_etype
& NM_REVENT
) ?
754 &msg
->nm_so
->so_rcv
:
756 TAILQ_REMOVE(&ssb
->ssb_sel
.si_mlist
, msg
, nm_list
);
757 lwkt_replymsg(&msg
->nm_netmsg
.nm_lmsg
, EINTR
);
761 * Reply to the abort message
763 lwkt_replymsg(&abrtmsg
->nm_netmsg
.nm_lmsg
, 0);