Require @(init) and @(fini) to be proc "contextless" ()

This commit is contained in:
gingerBill
2025-08-08 12:10:01 +01:00
parent 3194fda8f3
commit 7642e0a0e0
47 changed files with 170 additions and 102 deletions
+2 -2
View File
@@ -52,7 +52,7 @@ CPU :: struct {
cpu: CPU
@(init, private)
init_cpu_features :: proc "c" () {
init_cpu_features :: proc "contextless" () {
is_set :: #force_inline proc "c" (bit: u32, value: u32) -> bool {
return (value>>bit) & 0x1 != 0
}
@@ -156,7 +156,7 @@ init_cpu_features :: proc "c" () {
_cpu_name_buf: [72]u8
@(init, private)
init_cpu_name :: proc "c" () {
init_cpu_name :: proc "contextless" () {
number_of_extended_ids, _, _, _ := cpuid(0x8000_0000, 0)
if number_of_extended_ids < 0x8000_0004 {
return
+3 -1
View File
@@ -2,11 +2,13 @@
#+build linux
package sysinfo
import "base:runtime"
import "core:sys/linux"
import "core:strings"
@(init, private)
init_cpu_features :: proc() {
init_cpu_features :: proc "contextless" () {
context = runtime.default_context()
fd, err := linux.open("/proc/cpuinfo", {})
if err != .NONE { return }
defer linux.close(fd)
+4 -1
View File
@@ -2,12 +2,15 @@
#+build linux
package sysinfo
import "base:runtime"
import "core:sys/linux"
import "core:strings"
import "core:strconv"
@(init, private)
init_cpu_core_count :: proc() {
init_cpu_core_count :: proc "contextless" () {
context = runtime.default_context()
fd, err := linux.open("/proc/cpuinfo", {})
if err != .NONE { return }
defer linux.close(fd)
+4 -1
View File
@@ -2,9 +2,12 @@ package sysinfo
import sys "core:sys/windows"
import "base:intrinsics"
import "base:runtime"
@(init, private)
init_cpu_core_count :: proc() {
init_cpu_core_count :: proc "contextless" () {
context = runtime.default_context()
infos: []sys.SYSTEM_LOGICAL_PROCESSOR_INFORMATION
defer delete(infos)
+4 -1
View File
@@ -1,5 +1,7 @@
package sysinfo
import "base:runtime"
import "core:strconv"
import "core:strings"
import "core:sys/unix"
@@ -9,7 +11,8 @@ import NS "core:sys/darwin/Foundation"
version_string_buf: [1024]u8
@(init, private)
init_platform :: proc() {
init_platform :: proc "contextless" () {
context = runtime.default_context()
ws :: strings.write_string
wi :: strings.write_int
+6 -3
View File
@@ -1,6 +1,7 @@
package sysinfo
import "base:intrinsics"
import "base:runtime"
import "core:strconv"
import "core:strings"
@@ -10,7 +11,9 @@ import "core:sys/linux"
version_string_buf: [1024]u8
@(init, private)
init_os_version :: proc () {
init_os_version :: proc "contextless" () {
context = runtime.default_context()
os_version.platform = .Linux
b := strings.builder_from_bytes(version_string_buf[:])
@@ -91,11 +94,11 @@ init_os_version :: proc () {
}
@(init, private)
init_ram :: proc() {
init_ram :: proc "contextless" () {
// Retrieve RAM info using `sysinfo`
sys_info: linux.Sys_Info
errno := linux.sysinfo(&sys_info)
assert(errno == .NONE, "Good luck to whoever's debugging this, something's seriously cucked up!")
assert_contextless(errno == .NONE, "Good luck to whoever's debugging this, something's seriously cucked up!")
ram = RAM{
total_ram = int(sys_info.totalram) * int(sys_info.mem_unit),
free_ram = int(sys_info.freeram) * int(sys_info.mem_unit),
+8 -4
View File
@@ -12,7 +12,9 @@ import "base:runtime"
version_string_buf: [1024]u8
@(init, private)
init_os_version :: proc () {
init_os_version :: proc "contextless" () {
context = runtime.default_context()
/*
NOTE(Jeroen):
`GetVersionEx` will return 6.2 for Windows 10 unless the program is manifested for Windows 10.
@@ -43,6 +45,7 @@ init_os_version :: proc () {
os_version.minor = int(osvi.dwMinorVersion)
os_version.build[0] = int(osvi.dwBuildNumber)
b := strings.builder_from_bytes(version_string_buf[:])
strings.write_string(&b, "Windows ")
@@ -259,7 +262,7 @@ init_os_version :: proc () {
}
@(init, private)
init_ram :: proc() {
init_ram :: proc "contextless" () {
state: sys.MEMORYSTATUSEX
state.dwLength = size_of(state)
@@ -276,10 +279,11 @@ init_ram :: proc() {
}
@(init, private)
init_gpu_info :: proc() {
init_gpu_info :: proc "contextless" () {
GPU_INFO_BASE :: "SYSTEM\\ControlSet001\\Control\\Class\\{4d36e968-e325-11ce-bfc1-08002be10318}\\"
context = runtime.default_context()
gpu_list: [dynamic]GPU
gpu_index: int
+2 -2
View File
@@ -628,7 +628,7 @@ run_as_user :: proc(username, password, application, commandline: string, pi: ^P
}
}
ensure_winsock_initialized :: proc() {
ensure_winsock_initialized :: proc "contextless" () {
@static gate := false
@static initted := false
@@ -644,7 +644,7 @@ ensure_winsock_initialized :: proc() {
unused_info: WSADATA
version_requested := WORD(2) << 8 | 2
res := WSAStartup(version_requested, &unused_info)
assert(res == 0, "unable to initialized Winsock2")
assert_contextless(res == 0, "unable to initialized Winsock2")
initted = true
}