Checking for Bad Pointers and Data Misalignment — Intel® SDE documentation

# 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 with memory checks is to provide minimal checks to keep the overhead low. When the memory checker is active, it has a few operation modes. The basic mode is to report bad memory accesses and terminate the process. Another option is to raise memory access exception, meaning the execution will be resumed at the exception handler, if the application provides one. The last option is available when using application debugging. In this case, Intel® SDE causes debugger breakpoint.

The three modes are mutualy exclusive, meaning that you cannot get both error message and raise exception. Note that by default, Intel® SDE memory checker skips checking memory accesses with the stack pointer as their base register. Use the knob -ptr-skip-stack 0 for enabling the check of all memory instructions.

`-null_check`

  Check memory accesses for null references [default 0]

`-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 the memory checker [default sde-ptr-check.out.txt]

`-ptr_emu_only`

  Check memory issues only in emulated instructions [default 0]

`-ptr_raise`

  Raise exception on memory access errors [default 0]

`-ptr_skip_stack`

  Skip checking memory with stack register [default 1]