libstand.3: add HAMMER and MS-DOS filesystems and improve mark-up
[dragonfly.git] / sys / kern / uipc_msg.c
blobe6951209ff4f33d33b3cb8505745690af3a6b3ce
1 /*
2 * Copyright (c) 2003, 2004 Jeffrey M. Hsu. All rights reserved.
3 * Copyright (c) 2003, 2004 The DragonFly Project. All rights reserved.
4 *
5 * This code is derived from software contributed to The DragonFly Project
6 * by Jeffrey M. Hsu.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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
31 * SUCH DAMAGE.
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>
47 #include <vm/pmap.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.
58 void
59 so_pru_abort(struct socket *so)
61 struct netmsg_pru_abort msg;
62 lwkt_port_t port;
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,
67 0, netmsg_pru_abort);
68 msg.nm_prufn = so->so_proto->pr_usrreqs->pru_abort;
69 msg.nm_so = so;
70 (void)lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
74 * Abort a socket and free it, asynchronously. Called from
75 * soaborta() only.
77 * The SS_ABORTING flag must already be set.
79 void
80 so_pru_aborta(struct socket *so)
82 struct netmsg_pru_abort *msg;
83 lwkt_port_t port;
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,
89 0, netmsg_pru_abort);
90 msg->nm_prufn = so->so_proto->pr_usrreqs->pru_abort;
91 msg->nm_so = so;
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.
101 void
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));
113 #ifdef notdef
114 int error;
115 struct netmsg_pru_accept msg;
116 lwkt_port_t port;
118 port = so->so_proto->pr_mport(so, NULL, NULL, PRU_ACCEPT);
119 netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0,
120 netmsg_pru_accept);
121 msg.nm_prufn = so->so_proto->pr_usrreqs->pru_accept;
122 msg.nm_so = so;
123 msg.nm_nam = nam;
124 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
125 return (error);
126 #endif
130 so_pru_attach(struct socket *so, int proto, struct pru_attach_info *ai)
132 int error;
133 struct netmsg_pru_attach msg;
134 lwkt_port_t port;
136 port = so->so_proto->pr_mport(NULL, NULL, NULL, PRU_ATTACH);
137 netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0,
138 netmsg_pru_attach);
139 msg.nm_prufn = so->so_proto->pr_usrreqs->pru_attach;
140 msg.nm_so = so;
141 msg.nm_proto = proto;
142 msg.nm_ai = ai;
143 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
144 return (error);
148 so_pru_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
150 int error;
151 struct netmsg_pru_bind msg;
152 lwkt_port_t port;
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,
157 netmsg_pru_bind);
158 msg.nm_prufn = so->so_proto->pr_usrreqs->pru_bind;
159 msg.nm_so = so;
160 msg.nm_nam = nam;
161 msg.nm_td = td; /* used only for prison_ip() XXX JH */
162 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
163 return (error);
167 so_pru_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
169 int error;
170 struct netmsg_pru_connect msg;
171 lwkt_port_t port;
173 port = so->so_proto->pr_mport(so, nam, NULL, PRU_CONNECT);
174 netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0,
175 netmsg_pru_connect);
176 msg.nm_prufn = so->so_proto->pr_usrreqs->pru_connect;
177 msg.nm_so = so;
178 msg.nm_nam = nam;
179 msg.nm_td = td;
180 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
181 return (error);
185 so_pru_connect2(struct socket *so1, struct socket *so2)
187 int error;
188 struct netmsg_pru_connect2 msg;
189 lwkt_port_t port;
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;
195 msg.nm_so1 = so1;
196 msg.nm_so2 = so2;
197 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
198 return (error);
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,
205 curthread));
206 #ifdef gag /* does copyin and copyout deep inside stack XXX JH */
207 int error;
208 struct netmsg_pru_control msg;
209 lwkt_port_t port;
211 port = so->so_proto->pr_mport(so, NULL, NULL, PRU_CONTROL);
212 netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0,
213 netmsg_pru_control);
214 msg.nm_prufn = so->so_proto->pr_usrreqs->pru_control;
215 msg.nm_so = so;
216 msg.nm_cmd = cmd;
217 msg.nm_data = data;
218 msg.nm_ifp = ifp;
219 msg.nm_td = td;
220 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
221 return (error);
222 #endif
226 so_pru_detach(struct socket *so)
228 int error;
229 struct netmsg_pru_detach msg;
230 lwkt_port_t port;
232 port = so->so_proto->pr_mport(so, NULL, NULL, PRU_DETACH);
233 netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0,
234 netmsg_pru_detach);
235 msg.nm_prufn = so->so_proto->pr_usrreqs->pru_detach;
236 msg.nm_so = so;
237 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
238 return (error);
242 so_pru_disconnect(struct socket *so)
244 int error;
245 struct netmsg_pru_disconnect msg;
246 lwkt_port_t port;
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;
252 msg.nm_so = so;
253 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
254 return (error);
258 so_pru_listen(struct socket *so, struct thread *td)
260 int error;
261 struct netmsg_pru_listen msg;
262 lwkt_port_t port;
264 port = so->so_proto->pr_mport(so, NULL, NULL, PRU_LISTEN);
265 netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0,
266 netmsg_pru_listen);
267 msg.nm_prufn = so->so_proto->pr_usrreqs->pru_listen;
268 msg.nm_so = so;
269 msg.nm_td = td; /* used only for prison_ip() XXX JH */
270 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
271 return (error);
275 so_pru_peeraddr(struct socket *so, struct sockaddr **nam)
277 int error;
278 struct netmsg_pru_peeraddr msg;
279 lwkt_port_t port;
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;
285 msg.nm_so = so;
286 msg.nm_nam = nam;
287 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
288 return (error);
292 so_pru_rcvd(struct socket *so, int flags)
294 int error;
295 struct netmsg_pru_rcvd msg;
296 lwkt_port_t port;
298 port = so->so_proto->pr_mport(so, NULL, NULL, PRU_RCVD);
299 netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0,
300 netmsg_pru_rcvd);
301 msg.nm_prufn = so->so_proto->pr_usrreqs->pru_rcvd;
302 msg.nm_so = so;
303 msg.nm_flags = flags;
304 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
305 return (error);
309 so_pru_rcvoob(struct socket *so, struct mbuf *m, int flags)
311 int error;
312 struct netmsg_pru_rcvoob msg;
313 lwkt_port_t port;
315 port = so->so_proto->pr_mport(so, NULL, NULL, PRU_RCVOOB);
316 netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0,
317 netmsg_pru_rcvoob);
318 msg.nm_prufn = so->so_proto->pr_usrreqs->pru_rcvoob;
319 msg.nm_so = so;
320 msg.nm_m = m;
321 msg.nm_flags = flags;
322 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
323 return (error);
327 so_pru_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
328 struct mbuf *control, struct thread *td)
330 int error;
331 struct netmsg_pru_send msg;
332 lwkt_port_t port;
334 port = so->so_proto->pr_mport(so, addr, &m, PRU_SEND);
335 if (port == NULL) {
336 KKASSERT(m == NULL);
337 return EINVAL;
340 netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0,
341 netmsg_pru_send);
342 msg.nm_prufn = so->so_proto->pr_usrreqs->pru_send;
343 msg.nm_so = so;
344 msg.nm_flags = flags;
345 msg.nm_m = m;
346 msg.nm_addr = addr;
347 msg.nm_control = control;
348 msg.nm_td = td;
349 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
350 return (error);
354 so_pru_sense(struct socket *so, struct stat *sb)
356 int error;
357 struct netmsg_pru_sense msg;
358 lwkt_port_t port;
360 port = so->so_proto->pr_mport(so, NULL, NULL, PRU_SENSE);
361 netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0,
362 netmsg_pru_sense);
363 msg.nm_prufn = so->so_proto->pr_usrreqs->pru_sense;
364 msg.nm_so = so;
365 msg.nm_stat = sb;
366 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
367 return (error);
371 so_pru_shutdown(struct socket *so)
373 int error;
374 struct netmsg_pru_shutdown msg;
375 lwkt_port_t port;
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;
381 msg.nm_so = so;
382 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
383 return (error);
387 so_pru_sockaddr(struct socket *so, struct sockaddr **nam)
389 int error;
390 struct netmsg_pru_sockaddr msg;
391 lwkt_port_t port;
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;
397 msg.nm_so = so;
398 msg.nm_nam = nam;
399 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
400 return (error);
404 so_pru_sopoll(struct socket *so, int events, struct ucred *cred)
406 int error;
407 struct netmsg_pru_sopoll msg;
408 lwkt_port_t port;
410 port = so->so_proto->pr_mport(so, NULL, NULL, PRU_SOPOLL);
411 netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0,
412 netmsg_pru_sopoll);
413 msg.nm_prufn = so->so_proto->pr_usrreqs->pru_sopoll;
414 msg.nm_so = so;
415 msg.nm_events = events;
416 msg.nm_cred = cred;
417 msg.nm_td = curthread;
418 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
419 return (error);
423 so_pru_ctloutput(struct socket *so, struct sockopt *sopt)
425 struct netmsg_pru_ctloutput msg;
426 lwkt_port_t port;
427 int error;
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;
435 msg.nm_so = so;
436 msg.nm_sopt = sopt;
437 error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg, 0);
438 return (error);
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
449 * temporary data.
451 void
452 so_pru_ctlinput(struct protosw *pr, int cmd, struct sockaddr *arg, void *extra)
454 struct netmsg_pru_ctlinput msg;
455 lwkt_port_t port;
457 if (pr->pr_ctlport == NULL)
458 return;
459 KKASSERT(pr->pr_ctlinput != NULL);
460 port = pr->pr_ctlport(cmd, arg, extra);
461 if (port == NULL)
462 return;
463 netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0,
464 netmsg_pru_ctlinput);
465 msg.nm_prufn = pr->pr_ctlinput;
466 msg.nm_cmd = cmd;
467 msg.nm_arg = arg;
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.
482 void
483 netmsg_pru_abort(netmsg_t msg)
485 struct netmsg_pru_abort *nm = (void *)msg;
486 struct socket *so = nm->nm_so;
487 int error;
489 KKASSERT(so->so_state & SS_ABORTING);
490 so->so_state &= ~SS_ABORTING;
491 error = nm->nm_prufn(so);
492 if (error)
493 sofree(so);
494 lwkt_replymsg(&msg->nm_lmsg, error);
497 #ifdef notused
498 void
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));
505 #endif
507 void
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));
516 void
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));
525 void
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));
534 void
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));
542 void
543 netmsg_pru_control(netmsg_t msg)
545 struct netmsg_pru_control *nm = (void *)msg;
546 int error;
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);
553 void
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));
561 void
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));
569 void
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));
577 void
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));
585 void
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));
593 void
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));
602 void
603 netmsg_pru_send(netmsg_t msg)
605 struct netmsg_pru_send *nm = (void *)msg;
606 int error;
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);
613 void
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));
621 void
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));
629 void
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));
637 void
638 netmsg_pru_sopoll(netmsg_t msg)
640 struct netmsg_pru_sopoll *nm = (void *)msg;
641 int error;
643 error = nm->nm_prufn(nm->nm_so, nm->nm_events, nm->nm_cred, nm->nm_td);
644 lwkt_replymsg(&msg->nm_lmsg, error);
647 void
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));
655 void
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);
664 void
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.
676 void
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 :
684 &msg->nm_so->so_snd;
687 * Reply immediately if the event has occured, otherwise queue the
688 * request.
690 if (msg->nm_predicate(&msg->nm_netmsg)) {
691 lwkt_replymsg(&msg->nm_netmsg.nm_lmsg,
692 msg->nm_netmsg.nm_lmsg.ms_error);
693 } else {
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.
712 void
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
729 * requeued).
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.
741 void
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 :
755 &msg->nm_so->so_snd;
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);