uipc_syscalls.c (89110) | uipc_syscalls.c (89306) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * sendfile(2) and related extensions: 6 * Copyright (c) 1998, David Greenman. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 20 unchanged lines hidden (view full) --- 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94 | 1/* 2 * Copyright (c) 1982, 1986, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * sendfile(2) and related extensions: 6 * Copyright (c) 1998, David Greenman. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 20 unchanged lines hidden (view full) --- 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94 |
37 * $FreeBSD: head/sys/kern/uipc_syscalls.c 89110 2002-01-09 02:47:00Z alfred $ | 37 * $FreeBSD: head/sys/kern/uipc_syscalls.c 89306 2002-01-13 11:58:06Z alfred $ |
38 */ 39 40#include "opt_compat.h" 41#include "opt_ktrace.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/kernel.h> --- 83 unchanged lines hidden (view full) --- 129 mtx_lock(&Giant); 130 fdp = td->td_proc->p_fd; 131 error = falloc(td, &fp, &fd); 132 if (error) 133 goto done2; 134 fhold(fp); 135 error = socreate(uap->domain, &so, uap->type, uap->protocol, 136 td->td_proc->p_ucred, td); | 38 */ 39 40#include "opt_compat.h" 41#include "opt_ktrace.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/kernel.h> --- 83 unchanged lines hidden (view full) --- 129 mtx_lock(&Giant); 130 fdp = td->td_proc->p_fd; 131 error = falloc(td, &fp, &fd); 132 if (error) 133 goto done2; 134 fhold(fp); 135 error = socreate(uap->domain, &so, uap->type, uap->protocol, 136 td->td_proc->p_ucred, td); |
137 FILEDESC_LOCK(fdp); |
|
137 if (error) { 138 if (fdp->fd_ofiles[fd] == fp) { 139 fdp->fd_ofiles[fd] = NULL; | 138 if (error) { 139 if (fdp->fd_ofiles[fd] == fp) { 140 fdp->fd_ofiles[fd] = NULL; |
141 FILEDESC_UNLOCK(fdp); |
|
140 fdrop(fp, td); | 142 fdrop(fp, td); |
141 } | 143 } else 144 FILEDESC_UNLOCK(fdp); |
142 } else { 143 fp->f_data = (caddr_t)so; /* already has ref count */ 144 fp->f_flag = FREAD|FWRITE; 145 fp->f_ops = &socketops; 146 fp->f_type = DTYPE_SOCKET; | 145 } else { 146 fp->f_data = (caddr_t)so; /* already has ref count */ 147 fp->f_flag = FREAD|FWRITE; 148 fp->f_ops = &socketops; 149 fp->f_type = DTYPE_SOCKET; |
150 FILEDESC_UNLOCK(fdp); |
|
147 td->td_retval[0] = fd; 148 } 149 fdrop(fp, td); 150done2: 151 mtx_unlock(&Giant); 152 return (error); 153} 154 --- 146 unchanged lines hidden (view full) --- 301 /* connection has been removed from the listen queue */ 302 KNOTE(&head->so_rcv.sb_sel.si_note, 0); 303 304 so->so_state &= ~SS_COMP; 305 so->so_head = NULL; 306 if (head->so_sigio != NULL) 307 fsetown(fgetown(head->so_sigio), &so->so_sigio); 308 | 151 td->td_retval[0] = fd; 152 } 153 fdrop(fp, td); 154done2: 155 mtx_unlock(&Giant); 156 return (error); 157} 158 --- 146 unchanged lines hidden (view full) --- 305 /* connection has been removed from the listen queue */ 306 KNOTE(&head->so_rcv.sb_sel.si_note, 0); 307 308 so->so_state &= ~SS_COMP; 309 so->so_head = NULL; 310 if (head->so_sigio != NULL) 311 fsetown(fgetown(head->so_sigio), &so->so_sigio); 312 |
313 FILE_LOCK(nfp); |
|
309 soref(so); /* file descriptor reference */ 310 nfp->f_data = (caddr_t)so; /* nfp has ref count from falloc */ 311 nfp->f_flag = fflag; 312 nfp->f_ops = &socketops; 313 nfp->f_type = DTYPE_SOCKET; | 314 soref(so); /* file descriptor reference */ 315 nfp->f_data = (caddr_t)so; /* nfp has ref count from falloc */ 316 nfp->f_flag = fflag; 317 nfp->f_ops = &socketops; 318 nfp->f_type = DTYPE_SOCKET; |
319 FILE_UNLOCK(nfp); |
|
314 sa = 0; 315 error = soaccept(so, &sa); 316 if (error) { 317 /* 318 * return a namelen of zero for older code which might 319 * ignore the return value from accept. 320 */ 321 if (uap->name != NULL) { --- 30 unchanged lines hidden (view full) --- 352 if (sa) 353 FREE(sa, M_SONAME); 354 355 /* 356 * close the new descriptor, assuming someone hasn't ripped it 357 * out from under us. 358 */ 359 if (error) { | 320 sa = 0; 321 error = soaccept(so, &sa); 322 if (error) { 323 /* 324 * return a namelen of zero for older code which might 325 * ignore the return value from accept. 326 */ 327 if (uap->name != NULL) { --- 30 unchanged lines hidden (view full) --- 358 if (sa) 359 FREE(sa, M_SONAME); 360 361 /* 362 * close the new descriptor, assuming someone hasn't ripped it 363 * out from under us. 364 */ 365 if (error) { |
366 FILEDESC_LOCK(fdp); |
|
360 if (fdp->fd_ofiles[fd] == nfp) { 361 fdp->fd_ofiles[fd] = NULL; | 367 if (fdp->fd_ofiles[fd] == nfp) { 368 fdp->fd_ofiles[fd] = NULL; |
369 FILEDESC_UNLOCK(fdp); |
|
362 fdrop(nfp, td); | 370 fdrop(nfp, td); |
371 } else { 372 FILEDESC_UNLOCK(fdp); |
|
363 } 364 } 365 splx(s); 366 367 /* 368 * Release explicitly held references before returning. 369 */ 370done: --- 134 unchanged lines hidden (view full) --- 505 if (uap->type == SOCK_DGRAM) { 506 /* 507 * Datagram socket connection is asymmetric. 508 */ 509 error = soconnect2(so2, so1); 510 if (error) 511 goto free4; 512 } | 373 } 374 } 375 splx(s); 376 377 /* 378 * Release explicitly held references before returning. 379 */ 380done: --- 134 unchanged lines hidden (view full) --- 515 if (uap->type == SOCK_DGRAM) { 516 /* 517 * Datagram socket connection is asymmetric. 518 */ 519 error = soconnect2(so2, so1); 520 if (error) 521 goto free4; 522 } |
513 fp1->f_flag = fp2->f_flag = FREAD|FWRITE; 514 fp1->f_ops = fp2->f_ops = &socketops; 515 fp1->f_type = fp2->f_type = DTYPE_SOCKET; | 523 FILE_LOCK(fp1); 524 fp1->f_flag = FREAD|FWRITE; 525 fp1->f_ops = &socketops; 526 fp1->f_type = DTYPE_SOCKET; 527 FILE_UNLOCK(fp1); 528 FILE_LOCK(fp2); 529 fp2->f_flag = FREAD|FWRITE; 530 fp2->f_ops = &socketops; 531 fp2->f_type = DTYPE_SOCKET; 532 FILE_UNLOCK(fp2); |
516 error = copyout((caddr_t)sv, (caddr_t)uap->rsv, 2 * sizeof (int)); 517 fdrop(fp1, td); 518 fdrop(fp2, td); 519 goto done2; 520free4: | 533 error = copyout((caddr_t)sv, (caddr_t)uap->rsv, 2 * sizeof (int)); 534 fdrop(fp1, td); 535 fdrop(fp2, td); 536 goto done2; 537free4: |
538 FILEDESC_LOCK(fdp); |
|
521 if (fdp->fd_ofiles[sv[1]] == fp2) { 522 fdp->fd_ofiles[sv[1]] = NULL; | 539 if (fdp->fd_ofiles[sv[1]] == fp2) { 540 fdp->fd_ofiles[sv[1]] = NULL; |
541 FILEDESC_UNLOCK(fdp); |
|
523 fdrop(fp2, td); | 542 fdrop(fp2, td); |
524 } | 543 } else 544 FILEDESC_UNLOCK(fdp); |
525 fdrop(fp2, td); 526free3: | 545 fdrop(fp2, td); 546free3: |
547 FILEDESC_LOCK(fdp); |
|
527 if (fdp->fd_ofiles[sv[0]] == fp1) { 528 fdp->fd_ofiles[sv[0]] = NULL; | 548 if (fdp->fd_ofiles[sv[0]] == fp1) { 549 fdp->fd_ofiles[sv[0]] = NULL; |
550 FILEDESC_UNLOCK(fdp); |
|
529 fdrop(fp1, td); | 551 fdrop(fp1, td); |
530 } | 552 } else 553 FILEDESC_UNLOCK(fdp); |
531 fdrop(fp1, td); 532free2: 533 (void)soclose(so2); 534free1: 535 (void)soclose(so1); 536done2: 537 mtx_unlock(&Giant); 538 return (error); --- 1388 unchanged lines hidden (view full) --- 1927 } 1928 if (vp) 1929 vrele(vp); 1930 if (so) 1931 fputsock(so); 1932 mtx_unlock(&Giant); 1933 return (error); 1934} | 554 fdrop(fp1, td); 555free2: 556 (void)soclose(so2); 557free1: 558 (void)soclose(so1); 559done2: 560 mtx_unlock(&Giant); 561 return (error); --- 1388 unchanged lines hidden (view full) --- 1950 } 1951 if (vp) 1952 vrele(vp); 1953 if (so) 1954 fputsock(so); 1955 mtx_unlock(&Giant); 1956 return (error); 1957} |
1935 | |