aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-11-04 11:03:21 +0000
committergingerBill <bill@gingerbill.org>2021-11-04 11:03:21 +0000
commit3fa7dabaa87e99386e469bd5e4badab23f89aaef (patch)
tree84933a742d8246b97ec862142ec9579319510bf7 /core
parent1980f32bd6636edf7f8a1ba0d0010f23b5292488 (diff)
Correctly support `-default-to-nil-allocator` for all platforms
Diffstat (limited to 'core')
-rw-r--r--core/runtime/core.odin6
-rw-r--r--core/runtime/default_allocators_general.odin15
-rw-r--r--core/runtime/default_allocators_nil.odin33
-rw-r--r--core/runtime/default_allocators_wasi.odin31
-rw-r--r--core/runtime/default_allocators_windows.odin66
-rw-r--r--core/runtime/default_temporary_allocator.odin17
-rw-r--r--core/runtime/procs.odin3
-rw-r--r--core/runtime/procs_windows_amd64.odin10
8 files changed, 85 insertions, 96 deletions
diff --git a/core/runtime/core.odin b/core/runtime/core.odin
index 22e23d79e..20e808fb7 100644
--- a/core/runtime/core.odin
+++ b/core/runtime/core.odin
@@ -506,8 +506,10 @@ __init_context :: proc "contextless" (c: ^Context) {
c.temp_allocator.procedure = default_temp_allocator_proc
c.temp_allocator.data = &global_default_temp_allocator_data
-
- c.assertion_failure_proc = default_assertion_failure_proc
+
+ when !ODIN_DISABLE_ASSERT {
+ c.assertion_failure_proc = default_assertion_failure_proc
+ }
c.logger.procedure = default_logger_proc
c.logger.data = nil
diff --git a/core/runtime/default_allocators_general.odin b/core/runtime/default_allocators_general.odin
index 6bcfb68ae..5ccd5ceb4 100644
--- a/core/runtime/default_allocators_general.odin
+++ b/core/runtime/default_allocators_general.odin
@@ -5,19 +5,8 @@ package runtime
when ODIN_DEFAULT_TO_NIL_ALLOCATOR {
// mem.nil_allocator reimplementation
-
- default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
- size, alignment: int,
- old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, Allocator_Error) {
- return nil, .None
- }
-
- default_allocator :: proc() -> Allocator {
- return Allocator{
- procedure = default_allocator_proc,
- data = nil,
- }
- }
+ default_allocator_proc :: nil_allocator_proc
+ default_allocator :: nil_allocator
} else {
// TODO(bill): reimplement these procedures in the os_specific stuff
import "core:os"
diff --git a/core/runtime/default_allocators_nil.odin b/core/runtime/default_allocators_nil.odin
index 5100bc517..ccb4a3381 100644
--- a/core/runtime/default_allocators_nil.odin
+++ b/core/runtime/default_allocators_nil.odin
@@ -1,17 +1,38 @@
-//+build freestanding
package runtime
-// mem.nil_allocator reimplementation
-
-default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
+nil_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
size, alignment: int,
old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, Allocator_Error) {
+ switch mode {
+ case .Alloc:
+ return nil, .Out_Of_Memory
+ case .Free:
+ return nil, .None
+ case .Free_All:
+ return nil, .Mode_Not_Implemented
+ case .Resize:
+ if size == 0 {
+ return nil, .None
+ }
+ return nil, .Out_Of_Memory
+ case .Query_Features:
+ return nil, .Mode_Not_Implemented
+ case .Query_Info:
+ return nil, .Mode_Not_Implemented
+ }
return nil, .None
}
-default_allocator :: proc() -> Allocator {
+nil_allocator :: proc() -> Allocator {
return Allocator{
- procedure = default_allocator_proc,
+ procedure = nil_allocator_proc,
data = nil,
}
}
+
+
+
+when ODIN_OS == "freestanding" {
+ default_allocator_proc :: nil_allocator_proc
+ default_allocator :: nil_allocator
+} \ No newline at end of file
diff --git a/core/runtime/default_allocators_wasi.odin b/core/runtime/default_allocators_wasi.odin
index e2bb7516e..2e475e055 100644
--- a/core/runtime/default_allocators_wasi.odin
+++ b/core/runtime/default_allocators_wasi.odin
@@ -1,32 +1,5 @@
//+build wasi
package runtime
-default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
- size, alignment: int,
- old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, Allocator_Error) {
- switch mode {
- case .Alloc:
- return nil, .Out_Of_Memory
- case .Free:
- return nil, .None
- case .Free_All:
- return nil, .Mode_Not_Implemented
- case .Resize:
- if size == 0 {
- return nil, .None
- }
- return nil, .Out_Of_Memory
- case .Query_Features:
- return nil, .Mode_Not_Implemented
- case .Query_Info:
- return nil, .Mode_Not_Implemented
- }
- return nil, .None
-}
-
-default_allocator :: proc() -> Allocator {
- return Allocator{
- procedure = default_allocator_proc,
- data = nil,
- }
-}
+default_allocator_proc :: nil_allocator_proc
+default_allocator :: nil_allocator
diff --git a/core/runtime/default_allocators_windows.odin b/core/runtime/default_allocators_windows.odin
index f57f4c86c..9cabbcce8 100644
--- a/core/runtime/default_allocators_windows.odin
+++ b/core/runtime/default_allocators_windows.odin
@@ -1,38 +1,44 @@
//+build windows
package runtime
-default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
- size, alignment: int,
- old_memory: rawptr, old_size: int, loc := #caller_location) -> (data: []byte, err: Allocator_Error) {
- switch mode {
- case .Alloc:
- data, err = _windows_default_alloc(size, alignment)
-
- case .Free:
- _windows_default_free(old_memory)
-
- case .Free_All:
- // NOTE(tetra): Do nothing.
-
- case .Resize:
- data, err = _windows_default_resize(old_memory, old_size, size, alignment)
-
- case .Query_Features:
- set := (^Allocator_Mode_Set)(old_memory)
- if set != nil {
- set^ = {.Alloc, .Free, .Resize, .Query_Features}
+when ODIN_DEFAULT_TO_NIL_ALLOCATOR {
+ // mem.nil_allocator reimplementation
+ default_allocator_proc :: nil_allocator_proc
+ default_allocator :: nil_allocator
+} else {
+ default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
+ size, alignment: int,
+ old_memory: rawptr, old_size: int, loc := #caller_location) -> (data: []byte, err: Allocator_Error) {
+ switch mode {
+ case .Alloc:
+ data, err = _windows_default_alloc(size, alignment)
+
+ case .Free:
+ _windows_default_free(old_memory)
+
+ case .Free_All:
+ // NOTE(tetra): Do nothing.
+
+ case .Resize:
+ data, err = _windows_default_resize(old_memory, old_size, size, alignment)
+
+ case .Query_Features:
+ set := (^Allocator_Mode_Set)(old_memory)
+ if set != nil {
+ set^ = {.Alloc, .Free, .Resize, .Query_Features}
+ }
+
+ case .Query_Info:
+ // Do nothing
}
- case .Query_Info:
- // Do nothing
+ return
}
- return
-}
-
-default_allocator :: proc() -> Allocator {
- return Allocator{
- procedure = default_allocator_proc,
- data = nil,
+ default_allocator :: proc() -> Allocator {
+ return Allocator{
+ procedure = default_allocator_proc,
+ data = nil,
+ }
}
-}
+} \ No newline at end of file
diff --git a/core/runtime/default_temporary_allocator.odin b/core/runtime/default_temporary_allocator.odin
index afe3ee922..3da0a9f21 100644
--- a/core/runtime/default_temporary_allocator.odin
+++ b/core/runtime/default_temporary_allocator.odin
@@ -3,21 +3,14 @@ package runtime
DEFAULT_TEMP_ALLOCATOR_BACKING_SIZE: int : #config(DEFAULT_TEMP_ALLOCATOR_BACKING_SIZE, 1<<22)
-when ODIN_OS == "freestanding" {
- Default_Temp_Allocator :: struct {
- }
+when ODIN_OS == "freestanding" || ODIN_DEFAULT_TO_NIL_ALLOCATOR {
+ Default_Temp_Allocator :: struct {}
- default_temp_allocator_init :: proc(s: ^Default_Temp_Allocator, size: int, backup_allocator := context.allocator) {
- }
+ default_temp_allocator_init :: proc(s: ^Default_Temp_Allocator, size: int, backup_allocator := context.allocator) {}
- default_temp_allocator_destroy :: proc(s: ^Default_Temp_Allocator) {
- }
+ default_temp_allocator_destroy :: proc(s: ^Default_Temp_Allocator) {}
- default_temp_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
- size, alignment: int,
- old_memory: rawptr, old_size: int, loc := #caller_location) -> (data: []byte, err: Allocator_Error) {
- return nil, nil
- }
+ default_temp_allocator_proc :: nil_allocator_proc
} else {
Default_Temp_Allocator :: struct {
data: []byte,
diff --git a/core/runtime/procs.odin b/core/runtime/procs.odin
index 7ea6145b9..17703efdf 100644
--- a/core/runtime/procs.odin
+++ b/core/runtime/procs.odin
@@ -26,6 +26,7 @@ when ODIN_ARCH == "wasm32" || ODIN_ARCH == "wasm64" {
}
} else when ODIN_NO_CRT {
+ @(export)
@(link_name="memset")
memset :: proc "c" (ptr: rawptr, val: i32, len: int) -> rawptr {
if ptr != nil && len != 0 {
@@ -38,6 +39,7 @@ when ODIN_ARCH == "wasm32" || ODIN_ARCH == "wasm64" {
return ptr
}
+ @(export)
@(link_name="memmove")
memmove :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
if dst != src {
@@ -50,6 +52,7 @@ when ODIN_ARCH == "wasm32" || ODIN_ARCH == "wasm64" {
return dst
}
+ @(export)
@(link_name="memcpy")
memcpy :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
if dst != src {
diff --git a/core/runtime/procs_windows_amd64.odin b/core/runtime/procs_windows_amd64.odin
index 8faed87e5..394df14e6 100644
--- a/core/runtime/procs_windows_amd64.odin
+++ b/core/runtime/procs_windows_amd64.odin
@@ -20,11 +20,13 @@ windows_trap_type_assertion :: proc "contextless" () -> ! {
}
when ODIN_NO_CRT {
- @private
- @(link_name="_tls_index")
+ @(private, export, link_name="_tls_index")
_tls_index: u32
- @private
- @(link_name="_fltused")
+ @(private, export, link_name="_fltused")
_fltused: i32 = 0x9875
+
+ @(private, export, link_name="__chkstk")
+ __chkstk :: proc "c" (rawptr) {
+ }
} \ No newline at end of file