(domain: u32, raw_ty: u32, proto: u32)
| 24 | }; |
| 25 | |
| 26 | pub fn sys_socket(domain: u32, raw_ty: u32, proto: u32) -> AxResult<isize> { |
| 27 | debug!("sys_socket <= domain: {domain}, ty: {raw_ty}, proto: {proto}"); |
| 28 | let ty = raw_ty & 0xFF; |
| 29 | |
| 30 | let pid = current().as_thread().proc_data.proc.pid(); |
| 31 | let socket = match (domain, ty) { |
| 32 | (AF_INET, SOCK_STREAM) => { |
| 33 | if proto != 0 && proto != IPPROTO_TCP as _ { |
| 34 | return Err(AxError::from(LinuxError::EPROTONOSUPPORT)); |
| 35 | } |
| 36 | axnet::Socket::Tcp(TcpSocket::new()) |
| 37 | } |
| 38 | (AF_INET, SOCK_DGRAM) => { |
| 39 | if proto != 0 && proto != IPPROTO_UDP as _ { |
| 40 | return Err(AxError::from(LinuxError::EPROTONOSUPPORT)); |
| 41 | } |
| 42 | axnet::Socket::Udp(UdpSocket::new()) |
| 43 | } |
| 44 | (AF_UNIX, SOCK_STREAM) => axnet::Socket::Unix(UnixSocket::new(StreamTransport::new(pid))), |
| 45 | (AF_UNIX, SOCK_DGRAM) => axnet::Socket::Unix(UnixSocket::new(DgramTransport::new(pid))), |
| 46 | #[cfg(feature = "vsock")] |
| 47 | (AF_VSOCK, SOCK_STREAM) => { |
| 48 | axnet::Socket::Vsock(VsockSocket::new(VsockStreamTransport::new())) |
| 49 | } |
| 50 | (AF_INET, _) | (AF_UNIX, _) | (AF_VSOCK, _) => { |
| 51 | warn!("Unsupported socket type: domain: {domain}, ty: {ty}"); |
| 52 | return Err(AxError::from(LinuxError::ESOCKTNOSUPPORT)); |
| 53 | } |
| 54 | _ => { |
| 55 | return Err(AxError::from(LinuxError::EAFNOSUPPORT)); |
| 56 | } |
| 57 | }; |
| 58 | let socket = Socket(socket); |
| 59 | |
| 60 | if raw_ty & O_NONBLOCK != 0 { |
| 61 | socket.set_nonblocking(true)?; |
| 62 | } |
| 63 | let cloexec = raw_ty & O_CLOEXEC != 0; |
| 64 | |
| 65 | socket.add_to_fd_table(cloexec).map(|fd| fd as isize) |
| 66 | } |
| 67 | |
| 68 | pub fn sys_bind(fd: i32, addr: UserConstPtr<sockaddr>, addrlen: u32) -> AxResult<isize> { |
| 69 | let addr = SocketAddrEx::read_from_user(addr, addrlen)?; |
no test coverage detected