gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/abi/linux/shm.go (about)

     1  // Copyright 2018 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package linux
    16  
    17  import "math"
    18  
    19  // shmat(2) flags. Source: include/uapi/linux/shm.h
    20  const (
    21  	SHM_RDONLY = 010000  // Read-only access.
    22  	SHM_RND    = 020000  // Round attach address to SHMLBA boundary.
    23  	SHM_REMAP  = 040000  // Take-over region on attach.
    24  	SHM_EXEC   = 0100000 // Execution access.
    25  )
    26  
    27  // IPCPerm.Mode upper byte flags. Source: include/linux/shm.h
    28  const (
    29  	SHM_DEST      = 01000  // Segment will be destroyed on last detach.
    30  	SHM_LOCKED    = 02000  // Segment will not be swapped.
    31  	SHM_HUGETLB   = 04000  // Segment will use huge TLB pages.
    32  	SHM_NORESERVE = 010000 // Don't check for reservations.
    33  )
    34  
    35  // Additional Linux-only flags for shmctl(2). Source: include/uapi/linux/shm.h
    36  const (
    37  	SHM_LOCK   = 11
    38  	SHM_UNLOCK = 12
    39  	SHM_STAT   = 13
    40  	SHM_INFO   = 14
    41  )
    42  
    43  // SHM defaults as specified by linux. Source: include/uapi/linux/shm.h
    44  const (
    45  	SHMMIN = 1
    46  	SHMMNI = 4096
    47  	SHMMAX = math.MaxUint64 - 1<<24
    48  	SHMALL = math.MaxUint64 - 1<<24
    49  	SHMSEG = 4096
    50  )
    51  
    52  // ShmidDS is equivalent to struct shmid64_ds. Source:
    53  // include/uapi/asm-generic/shmbuf.h
    54  //
    55  // +marshal
    56  type ShmidDS struct {
    57  	ShmPerm    IPCPerm
    58  	ShmSegsz   uint64
    59  	ShmAtime   TimeT
    60  	ShmDtime   TimeT
    61  	ShmCtime   TimeT
    62  	ShmCpid    int32
    63  	ShmLpid    int32
    64  	ShmNattach uint64
    65  
    66  	Unused4 uint64
    67  	Unused5 uint64
    68  }
    69  
    70  // ShmParams is equivalent to struct shminfo. Source: include/uapi/linux/shm.h
    71  //
    72  // +marshal
    73  type ShmParams struct {
    74  	ShmMax uint64
    75  	ShmMin uint64
    76  	ShmMni uint64
    77  	ShmSeg uint64
    78  	ShmAll uint64
    79  }
    80  
    81  // ShmInfo is equivalent to struct shm_info. Source: include/uapi/linux/shm.h
    82  //
    83  // +marshal
    84  type ShmInfo struct {
    85  	UsedIDs       int32 // Number of currently existing segments.
    86  	_             [4]byte
    87  	ShmTot        uint64 // Total number of shared memory pages.
    88  	ShmRss        uint64 // Number of resident shared memory pages.
    89  	ShmSwp        uint64 // Number of swapped shared memory pages.
    90  	SwapAttempts  uint64 // Unused since Linux 2.4.
    91  	SwapSuccesses uint64 // Unused since Linux 2.4.
    92  }