The issue seems clear. syscall.RLIM_INFINITY for loong64 does not have a special type. syscall.RLIM_INFINITY for loong64 (0xffffffffffffffff) is a reasonable ordinary value for type rlim_t (uint64). Prometheus has a bug.
---
The Open Group Base Specifications Issue 7, 2018 edition
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_resource.h.html sys/resource.h - definitions for XSI resource operations
rlim_t
Unsigned integer type used for limit values.
RLIM_INFINITY
A value of rlim_t indicating no limit.
---
The Go Programming Language
https://github.com/golang/go go/src/syscall/zerrors_linux_loong64.go:
const RLIM_INFINITY = 0xffffffffffffffff
go/src/syscall/zerrors_linux_amd64.go:
const RLIM_INFINITY = -0x1
These operating system and architecture dependent values are generated (mkerrors.sh) from the respective C header (#include <sys/resource.h>) files.
---
Prometheus
https://github.com/prometheus/prometheushttps://github.com/prometheus/prometheus/blob/main/util/runtime/limits_default.go#L27// syscall.RLIM_INFINITY is a constant and its default type is int.
// It needs to be converted to an int64 variable to be compared with uint64 values.
// See https://golang.org/ref/spec#Conversions
var unlimited int64 = syscall.RLIM_INFINITY
func limitToString(v uint64, unit string) string {
if v == uint64(unlimited) {
return "unlimited"
}
return fmt.Sprintf("%d%s", v, unit)
}For const RLIM_INFINITY = 0xffffffffffffffff, a bug:
https://go.dev/play/p/FvRPJer_UN1cannot use RLIM_INFINITY as int64 value (overflows)
---
A fix for the Prometheus bug.
The RLIM_INFINITY C constant integer values generate Go constant untyped values which convert to Go constant type uint64 values.
const unlimited uint64 = syscall.RLIM_INFINITY & 0xffffffffffffffff
func limitToString(v uint64, unit string) string {
if v == unlimited {
return "unlimited"
}
return fmt.Sprintf("%d%s", v, unit)
}https://go.dev/play/p/SZEJj9gSQ-tA test for const RLIM_INFINITY = 0xffffffffffffffff
https://go.dev/play/p/2t95X_-QRWj18446744073709551615 unlimitedA test for const RLIM_INFINITY = -1
https://go.dev/play/p/Q7aRtW1pWAz18446744073709551615 unlimited
peter