mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Begin work on windows 386
This commit is contained in:
@@ -2,35 +2,68 @@ package runtime
|
||||
|
||||
foreign import kernel32 "system:Kernel32.lib"
|
||||
|
||||
@private
|
||||
@(link_name="_tls_index")
|
||||
_tls_index: u32;
|
||||
windows_trap_array_bounds :: proc "contextless" () -> ! {
|
||||
DWORD :: u32;
|
||||
ULONG_PTR :: uint;
|
||||
|
||||
EXCEPTION_ARRAY_BOUNDS_EXCEEDED :: 0xC000008C;
|
||||
|
||||
foreign kernel32 {
|
||||
RaiseException :: proc "stdcall" (dwExceptionCode, dwExceptionFlags, nNumberOfArguments: DWORD, lpArguments: ^ULONG_PTR) -> ! ---
|
||||
}
|
||||
|
||||
RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, 0, 0, nil);
|
||||
}
|
||||
|
||||
windows_trap_type_assertion :: proc "contextless" () -> ! {
|
||||
windows_trap_array_bounds();
|
||||
}
|
||||
|
||||
@(private, require, link_name="_fltused") _fltused: i32 = 0x9875;
|
||||
|
||||
@(private, require, link_name="_tls_index") _tls_index: u32;
|
||||
@(private, require, link_name="_tls_array") _tls_array: u32;
|
||||
|
||||
|
||||
@private
|
||||
@(link_name="_fltused")
|
||||
_fltused: i32 = 0x9875;
|
||||
|
||||
@(link_name="memcpy")
|
||||
memcpy :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
|
||||
foreign kernel32 {
|
||||
RtlCopyMemory :: proc "c" (dst, src: rawptr, len: int) ---
|
||||
}
|
||||
if dst == nil || src == nil || len == 0 {
|
||||
if dst == nil || src == nil || len == 0 || dst == src {
|
||||
return dst;
|
||||
}
|
||||
RtlCopyMemory(dst, src, len);
|
||||
d := uintptr(dst);
|
||||
s := uintptr(src);
|
||||
n := uintptr(len);
|
||||
|
||||
for i in 0..<n {
|
||||
(^byte)(d+i)^ = (^byte)(s+i)^;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
@(link_name="memmove")
|
||||
memmove :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
|
||||
foreign kernel32 {
|
||||
RtlMoveMemory :: proc "c" (dst, src: rawptr, len: int) ---
|
||||
}
|
||||
if dst == nil || src == nil || len == 0 {
|
||||
if dst == nil || src == nil || len == 0 || dst == src {
|
||||
return dst;
|
||||
}
|
||||
RtlMoveMemory(dst, src, len);
|
||||
|
||||
d := uintptr(dst);
|
||||
s := uintptr(src);
|
||||
n := uintptr(len);
|
||||
|
||||
if s < d && d < s+n {
|
||||
// Overlap
|
||||
for i := n-1; n >= 0; i -= 1 {
|
||||
(^byte)(d+i)^ = (^byte)(s+i)^;
|
||||
}
|
||||
|
||||
} else {
|
||||
for i in 0..<n {
|
||||
(^byte)(d+i)^ = (^byte)(s+i)^;
|
||||
}
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user