MCPcopy
hub / github.com/google/gvisor / ConfigureMMap

Method ConfigureMMap

pkg/sentry/devices/memdev/zero.go:86–106  ·  view source on GitHub ↗

ConfigureMMap implements vfs.FileDescriptionImpl.ConfigureMMap.

(ctx context.Context, opts *memmap.MMapOpts)

Source from the content-addressed store, hash-verified

84
85// ConfigureMMap implements vfs.FileDescriptionImpl.ConfigureMMap.
86func (fd *zeroFD) ConfigureMMap(ctx context.Context, opts *memmap.MMapOpts) error {
87 if opts.Private || !opts.MaxPerms.Write {
88 // This mapping will never permit writing to the "underlying file" (in
89 // Linux terms, it isn't VM_SHARED), so implement it as an anonymous
90 // mapping, but back it with fd; this is what Linux does, and is
91 // actually application-visible because the resulting VMA will show up
92 // in /proc/[pid]/maps with fd.vfsfd.VirtualDentry()'s path rather than
93 // "/dev/zero (deleted)".
94 opts.Offset = 0
95 opts.MappingIdentity = &fd.vfsfd
96 opts.SentryOwnedContent = true
97 opts.MappingIdentity.IncRef()
98 return nil
99 }
100 tmpfsFD, err := tmpfs.NewZeroFile(ctx, auth.CredentialsFromContext(ctx), kernel.KernelFromContext(ctx).ShmMount(), opts.Length)
101 if err != nil {
102 return err
103 }
104 defer tmpfsFD.DecRef(ctx)
105 return tmpfsFD.ConfigureMMap(ctx, opts)
106}

Callers

nothing calls this directly

Calls 7

NewZeroFileFunction · 0.92
CredentialsFromContextFunction · 0.92
KernelFromContextFunction · 0.92
ShmMountMethod · 0.80
IncRefMethod · 0.65
DecRefMethod · 0.65
ConfigureMMapMethod · 0.65

Tested by

no test coverage detected