Source file src/runtime/cgo/cgo_freebsd_amd64.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build goexperiment.runtimecgopurego && !msan && !tsan && freebsd && amd64
     6  
     7  package cgo
     8  
     9  import "unsafe"
    10  
    11  //go:linkname _cgo_libc_sigaction _cgo_libc_sigaction
    12  var _cgo_libc_sigaction byte
    13  var libc_sigaction = unsafe.Pointer(&_cgo_libc_sigaction)
    14  
    15  //go:linkname _cgo_libc_errno_location _cgo_libc_errno_location
    16  var _cgo_libc_errno_location byte
    17  var libc_errno_location = unsafe.Pointer(&_cgo_libc_errno_location)
    18  
    19  //go:cgo_import_dynamic _cgo_libc_mmap mmap "libc.so.7"
    20  //go:cgo_import_dynamic _cgo_libc_munmap munmap "libc.so.7"
    21  //go:cgo_import_dynamic _cgo_libc_sigaction sigaction "libc.so.7"
    22  //go:cgo_import_dynamic _cgo_libc_errno_location __error "libc.so.7"
    23  
    24  // freebsdSigaction matches both runtime.sigactiont (os_freebsd.go) and
    25  // FreeBSD's C struct sigaction on freebsd/amd64.
    26  type freebsdSigaction struct {
    27  	handler uintptr
    28  	flags   int32
    29  	mask    [4]uint32
    30  }
    31  
    32  //go:linknamestd _cgoSigaction runtime.cgoSigaction
    33  var _cgoSigaction = cgoSigaction
    34  
    35  //go:nosplit
    36  //go:norace
    37  //go:nocheckptr
    38  func cgoSigaction(signum uintptr, goact, oldgoact *freebsdSigaction, noG bool) int32 {
    39  	tsanAcquireMode(noG)
    40  
    41  	var act, oldact freebsdSigaction
    42  	var actPtr, oldactPtr uintptr
    43  
    44  	if goact != nil {
    45  		act = *goact
    46  		msanUnpoisonMode(noG, unsafe.Pointer(&act), unsafe.Sizeof(act))
    47  		actPtr = uintptr(unsafe.Pointer(&act))
    48  	}
    49  	if oldgoact != nil {
    50  		oldactPtr = uintptr(unsafe.Pointer(&oldact))
    51  	}
    52  
    53  	ret := int32(asmcgocallMode(noG, uintptr(libc_sigaction), uintptr(int32(signum)), actPtr, oldactPtr, 0, 0, 0))
    54  	if ret == -1 {
    55  		errnoPtr := asmcgocallMode(noG, uintptr(libc_errno_location), 0, 0, 0, 0, 0, 0)
    56  		errno := *(*int32)(unsafe.Pointer(errnoPtr))
    57  		tsanReleaseMode(noG)
    58  		return errno
    59  	}
    60  
    61  	if oldgoact != nil {
    62  		*oldgoact = oldact
    63  		msanUnpoisonMode(noG, unsafe.Pointer(oldgoact), unsafe.Sizeof(*oldgoact))
    64  	}
    65  
    66  	tsanReleaseMode(noG)
    67  	return ret
    68  }
    69  

View as plain text