MCPcopy Index your code
hub / github.com/google/gvisor / Socket

Function Socket

pkg/sentry/syscalls/linux/sys_socket.go:178–207  ·  view source on GitHub ↗

Socket implements the linux syscall socket(2).

(t *kernel.Task, sysno uintptr, args arch.SyscallArguments)

Source from the content-addressed store, hash-verified

176
177// Socket implements the linux syscall socket(2).
178func 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).
210func SocketPair(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
SockTypeTypeAlias · 0.92
ToErrorMethod · 0.80
SetStatusFlagsMethod · 0.80
NewFDFromMethod · 0.80
DecRefMethod · 0.65
CredentialsMethod · 0.65
IntMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…