| |
| /pliant/language/context/memory.pli |
| |
| 1 |
scope "/pliant/language/" "/pliant/install/" | |
| 2 |
module "/pliant/install/ring2.pli" | |
| 3 |
module "/pliant/storage/database/light.pli" | |
| 4 |
| |
| 5 |
function test_memory -> mem | |
| 6 |
arg Intn mem | |
| 7 |
if os_api="linux" | |
| 8 |
os_sysinfo (gvar os_sysinfo sys) | |
| 9 |
mem := sys totalram | |
| 10 |
eif os_api="posix" | |
| 11 |
if not (os_sysctl:"hw.physmem" parse mem) | |
| 12 |
mem := 0 | |
| 13 |
eif os_api="win32" | |
| 14 |
os_GlobalMemoryStatus (var os_MEMORYSTATUS ms) | |
| 15 |
mem := ms dwTotalPhys | |
| 16 |
else | |
| 17 |
mem := 0 | |
| 18 |
if (data_read "security:/this_computer.pdb" "/hardware/memory/capacity" (var Int m))=success and m<>undefined | |
| 19 |
mem := m*2n^20 | |
| 20 |
| |
| 21 |
public | |
| 22 |
constant memory_physical test_memory | |
| 23 |
gvar Int memory_assigned := shunt memory_physical>0 memory_physical\4 32*2^20 | |
| 24 |
gvar Int memory_overflow := undefined | |
| 25 |
| |
| 26 |
function test_assigned | |
| 27 |
if (data_read "security:/this_computer.pdb" "/env/pliant/memory/assigned" (var Int m))=success and m<>undefined | |
| 28 |
memory_assigned := m*2^20 | |
| 29 |
if (data_read "security:/this_computer.pdb" "/env/pliant/memory/overflow" (var Int m))=success and m<>undefined | |
| 30 |
memory_overflow := m*2^20 | |
| 31 |
test_assigned | |
| 32 |
| |
| 33 |
function no_overflow_control | |
| 34 |
void | |
| 35 |
entry_root addressof:(the_function no_overflow_control) | |
| 36 |
| |
| 37 |
function memory_overflow_control | |
| 38 |
if memory_overflow=defined and memory_current_consumed>memory_overflow | |
| 39 |
pliant_memory_post_extend_hook := (the_function no_overflow_control) executable | |
| 40 |
memory_sem release | |
| 41 |
error error_id_starvation "too much memory consumed" | |
| 42 |
memory_sem request | |
| 43 |
entry_root addressof:(the_function memory_overflow_control) | |
| 44 |
| |
| 45 |
pliant_memory_post_extend_hook := (the_function memory_overflow_control) executable | |
| |