5.5 Non-secure function pointer intrinsics

A non-secure function pointer is a function pointer that has its LSB unset.

The following table describes the non-secure function pointer intrinsics that are available when __ARM_FEATURE_CMSE is set to 3:
Intrinsic Description
cmse_nsfptr_create(p)
Returns the value of p with its LSB cleared. The argument p can be any function pointer type.
ARM recommends that the return type of this intrinsic is identical to the type of its argument.
cmse_is_nsfptr(p) Returns non-zero if p has LSB unset, zero otherwise. The argument p can be any function pointer type.

Example

The following example shows how to use these intrinsics:
#include <arm_cmse.h>
typedef void __attribute__((cmse_nonsecure_call)) nsfunc(void);
void default_callback(void) { … }

// fp can point to a secure function or a non-secure function
nsfunc *fp = (nsfunc *) default_callback;           // secure function pointer

void __attribute__((cmse_nonsecure_entry)) entry(nsfunc *callback) {
    fp = cmse_nsfptr_create(callback);  // non-secure function pointer
}

void call_callback(void) {
    if (cmse_is_nsfptr(fp)) fp();       // non-secure function call
    else ((void (*)(void)) fp)();       // normal function call
}
Related reference
3.3 __attribute__((cmse_nonsecure_call)) function attribute
3.4 __attribute__((cmse_nonsecure_entry)) function attribute
Related information
Building Secure and Non-secure Images Using ARMv8-M Security Extensions
Non-ConfidentialPDF file icon PDF versionARM DUI0774E
Copyright © 2014-2016 ARM. All rights reserved.