Checking for Bad Pointers and Data Misalignment

Common application development errors are related to using pointers and memory references. Intel® SDE checks for two types of errors: data misalignment and bad memory pointers.

Data misalignment happen when the executed instruction has alignment restrictions and the input memory operand is not properly aligned. In this case the execution of the native instruction will fault. In the instruction emulation, there is not fault, and Intel® SDE data misalignment checker will detect this issue and report it the user.

Bad memory access is any memory load or store from inaccessible memory address. This can be load from a missing page, or store to a missing page or to a read-only page. When the bad access happen in the execution of native (i.e. not emulated) instruction, the application will fault like a normal application faults. When the bad access happen in an emulated instruction Intel® SDE will dump an error massage with minimal information.

% sde -skx -- myapp
SDE ERROR: Could not read memory at location 0x123440 nbytes= 64
For more detailed error message please run with -ptr-check and compile application with debug information
at ...../sde-safecopy.cpp:37 Function sde_safeload_fail

Intel® SDE has a more comprehensive analysis tool to inspect memory accesses. When adding the -ptr-check knob the output will have more information.

% sde -skx -ptr-check -- myapp
SDE ERROR: DEREFERENCING BAD MEMORY POINTER PC=0x40124d MEMEA=0x123440 vmovapd zmm0, zmmword ptr [rax]
Image: myapp+0x124d (in multi-region image, region# 1)
Function: main

When the application is compiled with debug information, then the source file and line that has the code with the bad access will be in the report.

Data Misalignment Options

Intel® SDE default behavior is to check for data misalignment only for emulated instructions (that has alignment requirements). When there is misaligned access in native executed instructions, a fault will happen and the process will crash. Intel® SDE provides an option to check for data misalignment for all instructions.

-align_checker_action

Check for unaligned memory accesses. Valid choices are: assert (default), warn, report or ignore. [default assert]

-align_checker_all

Check for unaligned memory for all instructions. Instructions that do not require memory alignment will also be checked. Disabled by default. [default 0]

-align_checker_emu_only

Check for unaligned memory only for emulated instructions. If disabled, native instructions will also be checked [default 1]

-align_checker_file

File name for messages about unaligned memory accesses. [default sde-align-checker-out.txt]

-align_checker_image

Only check instructions in the named image [default is off]

-align_checker_prefetch

Check alignment for prefetch instructions 1=check prefetches, 0=ignore prefetches. [default 1]

-align_checker_stderr

Attempt writing messages about unaligned data accesses to stderr. When disabled, then the output file is used.

Memory Checking Options

The default Intel® SDE behavior is to reduce overhead and not do the comprehensive memory checks. When memory checker is active, it has a few modes. The basic mode is that bad memory accesses are reported and the process execution is terminated. Another option is to raise memory access exception, then if the application can handle the exception, the execution will be resumed at the exception handler. The last option is available when using application debugging. In this case, Intel® SDE can cause debugger breakpoint.

-null_check

Check memory accesses for null references [default 0]

-null_check_out

Output file name for -null-check [default sde-null-check.out.txt]

-ptr_breakpoint

Raise application breakpoint on memory access errors [default 0]

-ptr_check

Check for bad memory accesses [default 0]

-ptr_check_out

Output file name for -ptr-check [default sde-ptr-check.out.txt]

-ptr_check_warn

Make the memory checker warn on errors Default is to die on errors. [default 0]

-ptr_raise

Raise exception on memory access errors [default 0]