github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/sentry/pgalloc/pgalloc_unsafe.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 pgalloc
    16  
    17  import (
    18  	"reflect"
    19  	"unsafe"
    20  
    21  	"golang.org/x/sys/unix"
    22  )
    23  
    24  func unsafeSlice(addr uintptr, length int) (slice []byte) {
    25  	sh := (*reflect.SliceHeader)(unsafe.Pointer(&slice))
    26  	sh.Data = addr
    27  	sh.Len = length
    28  	sh.Cap = length
    29  	return
    30  }
    31  
    32  func mincore(s []byte, buf []byte) error {
    33  	if _, _, errno := unix.RawSyscall(
    34  		unix.SYS_MINCORE,
    35  		uintptr(unsafe.Pointer(&s[0])),
    36  		uintptr(len(s)),
    37  		uintptr(unsafe.Pointer(&buf[0]))); errno != 0 {
    38  		return errno
    39  	}
    40  	return nil
    41  }