Source file src/runtime/os_linux32.go

     1  // Copyright 2025 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 linux && (386 || arm || mips || mipsle || (gccgo && (ppc || s390)))
     6  
     7  package runtime
     8  
     9  import (
    10  	"unsafe"
    11  )
    12  
    13  func configure64bitsTimeOn32BitsArchitectures() {
    14  	use64bitsTimeOn32bits = getKernelVersion().GE(5, 1)
    15  }
    16  
    17  //go:noescape
    18  func futex_time32(addr unsafe.Pointer, op int32, val uint32, ts *timespec32, addr2 unsafe.Pointer, val3 uint32) int32
    19  
    20  //go:noescape
    21  func futex_time64(addr unsafe.Pointer, op int32, val uint32, ts *timespec, addr2 unsafe.Pointer, val3 uint32) int32
    22  
    23  var use64bitsTimeOn32bits bool
    24  
    25  //go:nosplit
    26  func futex(addr unsafe.Pointer, op int32, val uint32, ts *timespec, addr2 unsafe.Pointer, val3 uint32) int32 {
    27  	if use64bitsTimeOn32bits {
    28  		return futex_time64(addr, op, val, ts, addr2, val3)
    29  	}
    30  	// Downgrade ts.
    31  	var ts32 timespec32
    32  	var pts32 *timespec32
    33  	if ts != nil {
    34  		ts32.setNsec(ts.tv_sec*1e9 + ts.tv_nsec)
    35  		pts32 = &ts32
    36  	}
    37  	return futex_time32(addr, op, val, pts32, addr2, val3)
    38  }
    39  
    40  //go:noescape
    41  func timer_settime32(timerid int32, flags int32, new, old *itimerspec32) int32
    42  
    43  //go:noescape
    44  func timer_settime64(timerid int32, flags int32, new, old *itimerspec) int32
    45  
    46  //go:nosplit
    47  func timer_settime(timerid int32, flags int32, new, old *itimerspec) int32 {
    48  	if use64bitsTimeOn32bits {
    49  		return timer_settime64(timerid, flags, new, old)
    50  	}
    51  
    52  	var newts, oldts itimerspec32
    53  	var new32, old32 *itimerspec32
    54  
    55  	if new != nil {
    56  		newts.it_interval.setNsec(new.it_interval.tv_sec*1e9 + new.it_interval.tv_nsec)
    57  		newts.it_value.setNsec(new.it_value.tv_sec*1e9 + new.it_value.tv_nsec)
    58  		new32 = &newts
    59  	}
    60  
    61  	if old != nil {
    62  		oldts.it_interval.setNsec(old.it_interval.tv_sec*1e9 + old.it_interval.tv_nsec)
    63  		oldts.it_value.setNsec(old.it_value.tv_sec*1e9 + old.it_value.tv_nsec)
    64  		old32 = &oldts
    65  	}
    66  
    67  	return timer_settime32(timerid, flags, new32, old32)
    68  }
    69  

View as plain text