| 2866 | } |
| 2867 | |
| 2868 | void |
| 2869 | sorflush(struct socket *so) |
| 2870 | { |
| 2871 | struct sockbuf *sb = &so->so_rcv; |
| 2872 | struct protosw *pr = so->so_proto; |
| 2873 | struct socket aso; |
| 2874 | |
| 2875 | VNET_SO_ASSERT(so); |
| 2876 | |
| 2877 | /* |
| 2878 | * In order to avoid calling dom_dispose with the socket buffer mutex |
| 2879 | * held, and in order to generally avoid holding the lock for a long |
| 2880 | * time, we make a copy of the socket buffer and clear the original |
| 2881 | * (except locks, state). The new socket buffer copy won't have |
| 2882 | * initialized locks so we can only call routines that won't use or |
| 2883 | * assert those locks. |
| 2884 | * |
| 2885 | * Dislodge threads currently blocked in receive and wait to acquire |
| 2886 | * a lock against other simultaneous readers before clearing the |
| 2887 | * socket buffer. Don't let our acquire be interrupted by a signal |
| 2888 | * despite any existing socket disposition on interruptable waiting. |
| 2889 | */ |
| 2890 | socantrcvmore(so); |
| 2891 | (void) sblock(sb, SBL_WAIT | SBL_NOINTR); |
| 2892 | |
| 2893 | /* |
| 2894 | * Invalidate/clear most of the sockbuf structure, but leave selinfo |
| 2895 | * and mutex data unchanged. |
| 2896 | */ |
| 2897 | SOCKBUF_LOCK(sb); |
| 2898 | bzero(&aso, sizeof(aso)); |
| 2899 | aso.so_pcb = so->so_pcb; |
| 2900 | bcopy(&sb->sb_startzero, &aso.so_rcv.sb_startzero, |
| 2901 | sizeof(*sb) - offsetof(struct sockbuf, sb_startzero)); |
| 2902 | bzero(&sb->sb_startzero, |
| 2903 | sizeof(*sb) - offsetof(struct sockbuf, sb_startzero)); |
| 2904 | SOCKBUF_UNLOCK(sb); |
| 2905 | sbunlock(sb); |
| 2906 | |
| 2907 | /* |
| 2908 | * Dispose of special rights and flush the copied socket. Don't call |
| 2909 | * any unsafe routines (that rely on locks being initialized) on aso. |
| 2910 | */ |
| 2911 | if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose != NULL) |
| 2912 | (*pr->pr_domain->dom_dispose)(&aso); |
| 2913 | sbrelease_internal(&aso.so_rcv, so); |
| 2914 | } |
| 2915 | |
| 2916 | /* |
| 2917 | * Wrapper for Socket established helper hook. |
no test coverage detected