Initial QSfera import

This commit is contained in:
Курнат Андрей
2026-06-07 10:20:04 +03:00
commit 2315f25754
16485 changed files with 4826827 additions and 0 deletions
@@ -0,0 +1,20 @@
// Copyright 2019-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build freebsd || openbsd || dragonfly || netbsd
package sysmem
func Memory() int64 {
return sysctlInt64("hw.physmem")
}
@@ -0,0 +1,20 @@
// Copyright 2019-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build darwin
package sysmem
func Memory() int64 {
return sysctlInt64("hw.memsize")
}
@@ -0,0 +1,27 @@
// Copyright 2019-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build linux
package sysmem
import "syscall"
func Memory() int64 {
var info syscall.Sysinfo_t
err := syscall.Sysinfo(&info)
if err != nil {
return 0
}
return int64(info.Totalram) * int64(info.Unit)
}
@@ -0,0 +1,37 @@
// Copyright 2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build illumos || solaris
package sysmem
import (
"golang.org/x/sys/unix"
)
const (
_SC_PHYS_PAGES = 500
_SC_PAGESIZE = 11
)
func Memory() int64 {
pages, err := unix.Sysconf(_SC_PHYS_PAGES)
if err != nil {
return 0
}
pageSize, err := unix.Sysconf(_SC_PAGESIZE)
if err != nil {
return 0
}
return int64(pages) * int64(pageSize)
}
@@ -0,0 +1,21 @@
// Copyright 2022-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build wasm
package sysmem
func Memory() int64 {
// TODO: We don't know the system memory
return 0
}
@@ -0,0 +1,51 @@
// Copyright 2019-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build windows
package sysmem
import (
"unsafe"
"golang.org/x/sys/windows"
)
var winKernel32 = windows.NewLazySystemDLL("kernel32.dll")
var winGlobalMemoryStatusEx = winKernel32.NewProc("GlobalMemoryStatusEx")
func init() {
if err := winKernel32.Load(); err != nil {
panic(err)
}
if err := winGlobalMemoryStatusEx.Find(); err != nil {
panic(err)
}
}
// https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex
type _memoryStatusEx struct {
dwLength uint32
dwMemoryLoad uint32
ullTotalPhys uint64
unused [6]uint64 // ignore rest of struct
}
func Memory() int64 {
msx := &_memoryStatusEx{dwLength: 64}
res, _, _ := winGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(msx)))
if res == 0 {
return 0
}
return int64(msx.ullTotalPhys)
}
@@ -0,0 +1,21 @@
// Copyright 2022-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build zos
package sysmem
func Memory() int64 {
// TODO: We don't know the system memory
return 0
}
@@ -0,0 +1,33 @@
// Copyright 2019-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build darwin || freebsd || openbsd || dragonfly || netbsd
package sysmem
import (
"syscall"
"unsafe"
)
func sysctlInt64(name string) int64 {
s, err := syscall.Sysctl(name)
if err != nil {
return 0
}
// Make sure it's 8 bytes when we do the cast below.
// We were getting fatal error: checkptr: converted pointer straddles multiple allocations in go 1.22.1 on darwin.
var b [8]byte
copy(b[:], s)
return *(*int64)(unsafe.Pointer(&b[0]))
}