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 --- 19 unchanged lines hidden (view full) --- 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94 33 */ 34 35#include <sys/cdefs.h> |
36__FBSDID("$FreeBSD: head/sys/kern/uipc_syscalls.c 191816 2009-05-05 10:56:12Z zec $"); |
37 38#include "opt_sctp.h" 39#include "opt_compat.h" 40#include "opt_ktrace.h" 41#include "opt_mac.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> --- 14 unchanged lines hidden (view full) --- 59#include <sys/sf_buf.h> 60#include <sys/socket.h> 61#include <sys/socketvar.h> 62#include <sys/signalvar.h> 63#include <sys/syscallsubr.h> 64#include <sys/sysctl.h> 65#include <sys/uio.h> 66#include <sys/vnode.h> |
67#include <sys/vimage.h> |
68#ifdef KTRACE 69#include <sys/ktrace.h> 70#endif 71 72#include <security/mac/mac_framework.h> 73 74#include <vm/vm.h> 75#include <vm/vm_object.h> --- 184 unchanged lines hidden (view full) --- 260 so = fp->f_data; 261#ifdef MAC 262 SOCK_LOCK(so); 263 error = mac_socket_check_listen(td->td_ucred, so); 264 SOCK_UNLOCK(so); 265 if (error) 266 goto done; 267#endif |
268 CURVNET_SET(so->so_vnet); |
269 error = solisten(so, uap->backlog, td); |
270 CURVNET_RESTORE(); |
271#ifdef MAC 272done: 273#endif 274 fdrop(fp, td); 275 } 276 return(error); 277} 278 --- 148 unchanged lines hidden (view full) --- 427 428 finit(nfp, fflag, DTYPE_SOCKET, so, &socketops); 429 /* Sync socket nonblocking/async state with file flags */ 430 tmp = fflag & FNONBLOCK; 431 (void) fo_ioctl(nfp, FIONBIO, &tmp, td->td_ucred, td); 432 tmp = fflag & FASYNC; 433 (void) fo_ioctl(nfp, FIOASYNC, &tmp, td->td_ucred, td); 434 sa = 0; |
435 CURVNET_SET(so->so_vnet); |
436 error = soaccept(so, &sa); |
437 CURVNET_RESTORE(); |
438 if (error) { 439 /* 440 * return a namelen of zero for older code which might 441 * ignore the return value from accept. 442 */ 443 if (name) 444 *namelen = 0; 445 goto noconnection; --- 530 unchanged lines hidden (view full) --- 976 return (EINVAL); 977 } 978 } 979#ifdef KTRACE 980 if (KTRPOINT(td, KTR_GENIO)) 981 ktruio = cloneuio(&auio); 982#endif 983 len = auio.uio_resid; |
984 CURVNET_SET(so->so_vnet); |
985 error = soreceive(so, &fromsa, &auio, (struct mbuf **)0, 986 (mp->msg_control || controlp) ? &control : (struct mbuf **)0, 987 &mp->msg_flags); |
988 CURVNET_RESTORE(); |
989 if (error) { 990 if (auio.uio_resid != (int)len && (error == ERESTART || 991 error == EINTR || error == EWOULDBLOCK)) 992 error = 0; 993 } 994#ifdef KTRACE 995 if (ktruio != NULL) { 996 ktruio->uio_resid = (int)len - auio.uio_resid; --- 327 unchanged lines hidden (view full) --- 1324 break; 1325 default: 1326 panic("kern_setsockopt called with bad valseg"); 1327 } 1328 1329 error = getsock(td->td_proc->p_fd, s, &fp, NULL); 1330 if (error == 0) { 1331 so = fp->f_data; |
1332 CURVNET_SET(so->so_vnet); |
1333 error = sosetopt(so, &sopt); |
1334 CURVNET_RESTORE(); |
1335 fdrop(fp, td); 1336 } 1337 return(error); 1338} 1339 1340/* ARGSUSED */ 1341int 1342getsockopt(td, uap) --- 61 unchanged lines hidden (view full) --- 1404 break; 1405 default: 1406 panic("kern_getsockopt called with bad valseg"); 1407 } 1408 1409 error = getsock(td->td_proc->p_fd, s, &fp, NULL); 1410 if (error == 0) { 1411 so = fp->f_data; |
1412 CURVNET_SET(so->so_vnet); |
1413 error = sogetopt(so, &sopt); |
1414 CURVNET_RESTORE(); |
1415 *valsize = sopt.sopt_valsize; 1416 fdrop(fp, td); 1417 } 1418 return (error); 1419} 1420 1421/* 1422 * getsockname1() - Get socket name. --- 46 unchanged lines hidden (view full) --- 1469 if (*alen < 0) 1470 return (EINVAL); 1471 1472 error = getsock(td->td_proc->p_fd, fd, &fp, NULL); 1473 if (error) 1474 return (error); 1475 so = fp->f_data; 1476 *sa = NULL; |
1477 CURVNET_SET(so->so_vnet); |
1478 error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, sa); |
1479 CURVNET_RESTORE(); |
1480 if (error) 1481 goto bad; 1482 if (*sa == NULL) 1483 len = 0; 1484 else 1485 len = MIN(*alen, (*sa)->sa_len); 1486 *alen = len; 1487#ifdef KTRACE --- 84 unchanged lines hidden (view full) --- 1572 if (error) 1573 return (error); 1574 so = fp->f_data; 1575 if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) { 1576 error = ENOTCONN; 1577 goto done; 1578 } 1579 *sa = NULL; |
1580 CURVNET_SET(so->so_vnet); |
1581 error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, sa); |
1582 CURVNET_RESTORE(); |
1583 if (error) 1584 goto bad; 1585 if (*sa == NULL) 1586 len = 0; 1587 else 1588 len = MIN(*alen, (*sa)->sa_len); 1589 *alen = len; 1590#ifdef KTRACE --- 595 unchanged lines hidden (view full) --- 2186 mlen = m_length(m, NULL); 2187 SOCKBUF_LOCK(&so->so_snd); 2188 if (so->so_snd.sb_state & SBS_CANTSENDMORE) { 2189 error = EPIPE; 2190 SOCKBUF_UNLOCK(&so->so_snd); 2191 goto done; 2192 } 2193 SOCKBUF_UNLOCK(&so->so_snd); |
2194 CURVNET_SET(so->so_vnet); |
2195 /* Avoid error aliasing. */ 2196 err = (*so->so_proto->pr_usrreqs->pru_send) 2197 (so, 0, m, NULL, NULL, td); |
2198 CURVNET_RESTORE(); |
2199 if (err == 0) { 2200 /* 2201 * We need two counters to get the 2202 * file offset and nbytes to send 2203 * right: 2204 * - sbytes contains the total amount 2205 * of bytes sent, including headers. 2206 * - fsbytes contains the total amount --- 520 unchanged lines hidden --- |