/* * Copyright (c) 2020 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. The rights granted to you under the License * may not be used to create, or enable the creation or redistribution of, * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */#include<sys/domain.h>#include<sys/socket.h>#include<sys/protosw.h>#include<sys/mcache.h>#include<sys/systm.h>#include<sys/sysctl.h>#include<sys/random.h>#include<sys/mbuf.h>#include<sys/vsock_domain.h>#include<sys/vsock_transport.h>#include<kern/task.h>#include<kern/zalloc.h>#include<kern/locks.h>#include<machine/atomic.h>#include<IOKit/IOBSD.h>#define sotovsockpcb(so) ((struct vsockpcb *)(so)->so_pcb)#define VSOCK_PORT_RESERVED 1024#define VSOCK_PRIVATE_ENTITLEMENT "com.apple.private.vsock"/* VSock Protocol Globals */staticstructvsock_transport*_Atomicthe_vsock_transport[VSOCK_PROTO_MAX];staticZONE_DEFINE_TYPE(vsockpcb_zone,"vsockpcbzone",structvsockpcb,ZC_NONE);staticstructvsockpcbinfovsockinfo[VSOCK_PROTO_MAX];staticuint32_tvsock_sendspace[VSOCK_PROTO_MAX];staticuint32_tvsock_recvspace[VSOCK_PROTO_MAX];/* VSock Private Entitlements */staticerrno_tvsock_validate_entitlements(uint16_tprotocol,structproc*p){if(protocol!=VSOCK_PROTO_PRIVATE){return0;}if(!p){p=current_proc();}if(p==kernproc){// Assume kernel callers