![]() |
Up | ![]() |
TOC | Index | |||
<< 7 Included Tools | < 8.45 Memory Management - Low-Level | Up: 8 API Reference | 8.47 Memory Constants > | 9 Release Notes >> |
8.46 Safe Machine Level Access
This is a slower DEBUGGING VERSION of machine.e
How To Use This File:
1. If your program doesn't already include machine.e add: include std/machine.e to your main .ex[w][u] file at the top.
2. To turn debug version on, issue
with define SAFE
in your main program, before the statement including machine.e.
3. If necessary, call register_block(address, length, memory_protection) to add additional "external" blocks of memory to the safe_address_list. These are blocks of memory that are safe to use but which you did not acquire through Euphoria's allocate(), allocate_data(), allocate_code() or memory_protect(). Call unregister_block(address) when you want to prevent further access to an external block.
4. Run your program. It might be 10x slower than normal but it's worth it to catch a nasty bug.
5. If a bug is caught, you will hear some "beep" sounds. Press Enter to clear the screen and see the error message. There will be a "divide by zero" traceback in ex.err so you can find the statement that is making the illegal memory access.
6. To switch between normal and debug versions, simply comment in or out the "with define SAFE" directive. In means debugging and out means normal. Alternatively, you can use -D SAFE as a switch on the command line (debug) or not (normal).
7. The older method of switching files and renaming them no longer works. machine.e conditionally includes safe.e.
This file is equivalent to machine.e, but it overrides the built-in
routines:
poke, peek, poke4, peek4s, peek4u, call, mem_copy, and mem_set
and it provides alternate versions of:
allocate, free
Your program will only be allowed to read/write areas of memory that it allocated (and hasn't freed), as well as areas in low memory that you list below, or add dynamically via register_block().
8.46.0.1 BORDER_SPACE
include std/safe.e namespace safe export constant BORDER_SPACE
8.46.0.2 leader
include std/safe.e namespace safe export constant leader
8.46.0.3 trailer
include std/safe.e namespace safe export constant trailer
8.46.0.4 check_calls
include std/safe.e namespace safe public integer check_calls
Define block checking policy.
Comments:
If this integer is 1, (the default), check all blocks for edge corruption after each call(), c_proc() or c_func(). To save time, your program can turn off this checking by setting check_calls to 0.
8.46.0.5 edges_only
include std/safe.e namespace safe public integer edges_only
Determine whether to flag accesses to remote memory areas.
Comments:
If this integer is 1 (the default under WINDOWS), only check for references to the leader or trailer areas just outside each registered block, and don't complain about addresses that are far out of bounds (it's probably a legitimate block from another source)
For a stronger check, set this to 0 if your program will never read/write an unregistered block of memory.
On WINDOWS people often use unregistered blocks.
8.46.0.6 safe_address_list
include std/safe.e namespace safe public sequence safe_address_list
8.46.0.7 positive_int
include std/safe.e namespace safe export type positive_int(object x)
8.46.0.8 machine_addr
include std/safe.e namespace safe public type machine_addr(object a)
8.46.0.9 bordered_address
include std/safe.e namespace safe export type bordered_address(ext_addr addr)
8.46.0.10 safe_address
include std/safe.e namespace safe public function safe_address(machine_addr start, natural len, positive_int action)
8.46.0.11 peek
include std/safe.e namespace safe override ) override function peek(object
8.46.0.12 peeks
include std/safe.e namespace safe override function peeks(object x)
8.46.0.13 peek2u
include std/safe.e namespace safe override function peek2u(object x)
8.46.0.14 peek2s
include std/safe.e namespace safe override function peek2s(object x)
8.46.0.15 peek4s
include std/safe.e namespace safe override function peek4s(object x)
8.46.0.16 peek4u
include std/safe.e namespace safe override function peek4u(object x)
8.46.0.17 peek_string
include std/safe.e namespace safe override function peek_string(object x)
8.46.0.18 poke
include std/safe.e namespace safe override procedure poke(atom a, object v)
8.46.0.19 poke2
include std/safe.e namespace safe override procedure poke2(atom a, object v)
8.46.0.20 poke4
include std/safe.e namespace safe override procedure poke4(atom a, object v)
8.46.0.21 mem_copy
include std/safe.e namespace safe override procedure mem_copy(machine_addr target, machine_addr source, natural len)
8.46.0.22 mem_set
include std/safe.e namespace safe override procedure mem_set(machine_addr target, atom value, natural len)
8.46.0.23 show_block
include std/safe.e namespace safe public procedure show_block(sequence block_info)
8.46.0.24 check_all_blocks
include std/safe.e namespace safe public procedure check_all_blocks()
8.46.0.25 call
include std/safe.e namespace safe override procedure call(machine_addr addr)
8.46.0.26 c_proc
include std/safe.e namespace safe override procedure c_proc(integer i, sequence s)
8.46.0.27 c_func
include std/safe.e namespace safe override function c_func(integer i, sequence s)
8.46.0.28 register_block
include std/safe.e namespace safe public procedure register_block(machine_addr block_addr, positive_int block_len, valid_memory_protection_constant memory_protection = PAGE_READ_WRITE)
8.46.0.29 unregister_block
include std/safe.e namespace safe public procedure unregister_block(machine_addr block_addr)
8.46.0.30 prepare_block
include std/safe.e namespace safe export function prepare_block(int_addr iaddr, positive_int n, natural protection)
8.46.0.31 deallocate
include std/safe.e namespace safe export procedure deallocate(atom a)
8.46.0.32 dep_works
include std/safe.e namespace safe export function dep_works()
8.46.0.33 VirtualFree_rid
include std/safe.e namespace safe export atom VirtualFree_rid
8.46.0.34 free_code
include std/safe.e namespace safe public procedure free_code(atom addr, integer size, valid_wordsize wordsize = 1)
8.46.0.35 info
include std/safe.e namespace safe public function info()
8.46.0.36 memory_used
include std/safe.e namespace safe public function memory_used()
8.46.0.37 allocations
include std/safe.e namespace safe public function allocations()