Socket implements the linux syscall socket(2).
(t *kernel.Task, sysno uintptr, args arch.SyscallArguments)
| 176 | |
| 177 | // Socket implements the linux syscall socket(2). |
| 178 | func Socket(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) { |
| 179 | domain := int(args[0].Int()) |
| 180 | stype := args[1].Int() |
| 181 | protocol := int(args[2].Int()) |
| 182 | |
| 183 | // Check and initialize the flags. |
| 184 | if stype & ^(0xf|linux.SOCK_NONBLOCK|linux.SOCK_CLOEXEC) != 0 { |
| 185 | return 0, nil, linuxerr.EINVAL |
| 186 | } |
| 187 | |
| 188 | // Create the new socket. |
| 189 | s, e := socket.New(t, domain, linux.SockType(stype&0xf), protocol) |
| 190 | if e != nil { |
| 191 | return 0, nil, e.ToError() |
| 192 | } |
| 193 | defer s.DecRef(t) |
| 194 | |
| 195 | if err := s.SetStatusFlags(t, t.Credentials(), uint32(stype&linux.SOCK_NONBLOCK)); err != nil { |
| 196 | return 0, nil, err |
| 197 | } |
| 198 | |
| 199 | fd, err := t.NewFDFrom(0, s, kernel.FDFlags{ |
| 200 | CloseOnExec: stype&linux.SOCK_CLOEXEC != 0, |
| 201 | }) |
| 202 | if err != nil { |
| 203 | return 0, nil, err |
| 204 | } |
| 205 | |
| 206 | return uintptr(fd), nil, nil |
| 207 | } |
| 208 | |
| 209 | // SocketPair implements the linux syscall socketpair(2). |
| 210 | func SocketPair(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…