Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Examples/Smoke/Src/Main.rux
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Licensed under the MIT License
*/

import MacOS::{ GetStdHandle, StdHandle, WriteFile, ReadFile, GetProcessHeap, HeapAlloc, HeapFree };
import MacOS::{ GetStdHandle, StdHandle, WriteFile, ReadFile, GetProcessHeap, HeapAlloc, HeapFree, Munmap };

// Exercises the macOS bindings end-to-end: a non-zero exit code identifies the
// step that failed; 0 means every binding behaved as expected.
Expand All @@ -22,7 +22,7 @@ func Main() -> int32 {

// heap: allocate, write, read back, free
let heap = GetProcessHeap();
let buf = HeapAlloc(heap, 0, 32u) as *char8;
let buf = HeapAlloc(heap, 0u32, 32u) as *char8;
if buf == null {
return 3i32;
}
Expand All @@ -31,7 +31,7 @@ func Main() -> int32 {
if *buf != c8'R' || *(buf + 1u) != c8'X' {
return 4i32;
}
if HeapFree(heap, 0, buf as *opaque) == 0 {
if HeapFree(heap, 0u32, buf as *opaque) == 0 {
return 5i32;
}

Expand All @@ -44,5 +44,18 @@ func Main() -> int32 {
return 6i32;
}

// mmap/munmap roundtrip: allocate a page, write/read, then unmap it.
let page = HeapAlloc(heap, 0u32, 4096u) as *char8;
if page == null {
return 7i32;
}
*page = c8'M';
if *page != c8'M' {
return 8i32;
}
if Munmap(page as *opaque, 4096u) != 0i64 {
return 9i32;
}

return 0i32;
}
5 changes: 5 additions & 0 deletions Src/Platform.rux
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,10 @@ module MacOS {
/// Frees a memory block. Currently a no-op on macOS (the backing pages
/// are not unmapped), so it always reports success.
func HeapFree(heap: *opaque, flags: uint32, mem: *opaque) -> bool32;

/// Unmaps a memory region. Backed by SYS_munmap; addr must be the base
/// of a prior HeapAlloc mapping and length its full size. Returns 0 on
/// success.
func Munmap(addr: *opaque, length: uint) -> int64;
}
}