int cloudabi_sys_fd_create1(struct thread *td, struct cloudabi_sys_fd_create1_args *uap) { struct filecaps fcaps = {}; switch (uap->type) { case CLOUDABI_FILETYPE_POLL: cap_rights_init(&fcaps.fc_rights, CAP_FSTAT, CAP_KQUEUE); return (kern_kqueue(td, 0, &fcaps)); case CLOUDABI_FILETYPE_SHARED_MEMORY: cap_rights_init(&fcaps.fc_rights, CAP_FSTAT, CAP_FTRUNCATE, CAP_MMAP_RWX); return (kern_shm_open(td, SHM_ANON, O_RDWR, 0, &fcaps)); case CLOUDABI_FILETYPE_SOCKET_DGRAM: return (kern_socket(td, AF_UNIX, SOCK_DGRAM, 0)); case CLOUDABI_FILETYPE_SOCKET_SEQPACKET: return (kern_socket(td, AF_UNIX, SOCK_SEQPACKET, 0)); case CLOUDABI_FILETYPE_SOCKET_STREAM: return (kern_socket(td, AF_UNIX, SOCK_STREAM, 0)); default: return (EINVAL); } }
static int linux_socket(struct linux_socket_args *args, int *res) { struct linux_socket_args linux_args; struct sockopt sopt; int error, domain, optval; error = copyin(args, &linux_args, sizeof(linux_args)); if (error) return (error); domain = linux_to_bsd_domain(linux_args.domain); if (domain == -1) return (EINVAL); error = kern_socket(domain, linux_args.type, linux_args.protocol, res); /* Copy back the return value from socket() */ if (error == 0 && linux_args.type == SOCK_RAW && (linux_args.protocol == IPPROTO_RAW || linux_args.protocol == 0) && linux_args.domain == AF_INET) { /* It's a raw IP socket: set the IP_HDRINCL option. */ optval = 1; sopt.sopt_dir = SOPT_SET; sopt.sopt_level = IPPROTO_IP; sopt.sopt_name = IP_HDRINCL; sopt.sopt_val = &optval; sopt.sopt_valsize = sizeof(optval); sopt.sopt_td = NULL; /* We ignore any error returned by setsockopt() */ kern_setsockopt(*res, &sopt); } return (error); }