Developer Guide and Reference


Writing a Wrapper

The pointer checker is not supported on
You can write your own wrappers for run-time library functions. Typically, you would use one or more of the pointer checker intrinsics.
Example: Allocation Wrapping with __chkp_make_bounds
extern void *wrap_malloc(size_t bytes) { void* ppp; ppp = malloc(bytes); if (ppp) { ppp = (void*)__chkp_make_bounds(ppp, bytes); } else { ppp = (void*)0;} return ppp; }
The next example shows a wrapper that checks the validity of the pointer passed by performing writes to the first and last addresses that the C run-time routine will write. This will cause out of bounds events if necessary, while still allowing optimized handling of the C run-time library call.
Example: Checking without using Pointer Checker Intrinsics
extern void *wrap_memset(void *dst, int c, size_t size) { if (size > 0) { *(char *)dst = c; // write to first address *((char*)dst+size-1) = c; // write to last address (void)memset(dst, c, size); } return dst; }
Alternatively, you can perform the checking directly by comparing to the bounds associated with the pointer. In this case, you must first make sure that the bounds are meaningful. You can use the
intrinsics for this purpose.
Example: Upper and Lower Bound Intrinsics
extern void *wrap_memset(void *dst, int c, size_t size) { if (size > 0) { char *ub = __chkp_upper_bound(&dst); if ((intptr_t)ub != (intptr_t)-1) { char *lb = __chkp_lower_bound(&dst); char *max = (char*)dst+size-1; if (dst < lb) *(char*)dst = c; // cause bounds violation if (max > ub) *(char*)max = c; // cause bounds violation } (void)memset(dst, c, size); } return dst; }

Product and Performance Information


Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804