diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/common.h | 17 | ||||
-rw-r--r-- | include/console.h | 3 | ||||
-rw-r--r-- | include/extension.h | 9 | ||||
-rw-r--r-- | include/hooks.h | 6 | ||||
-rw-r--r-- | include/host_command.h | 7 | ||||
-rw-r--r-- | include/mkbp_event.h | 3 | ||||
-rw-r--r-- | include/test_util.h | 3 |
7 files changed, 37 insertions, 11 deletions
diff --git a/include/common.h b/include/common.h index 555f91a953..dac0bf2f00 100644 --- a/include/common.h +++ b/include/common.h @@ -96,6 +96,23 @@ #define __bss_slow __attribute__((section(".bss.slow"))) #endif +/* gcc does not support __has_feature */ +#ifndef __has_feature +#define __has_feature(x) 0 +#endif + +/* + * Use this to prevent AddressSanitizer from putting guards around some global + * variables (e.g. hook/commands "arrays" that are put together at link time). + */ +#ifndef __no_sanitize_address +#if __has_feature(address_sanitizer) +#define __no_sanitize_address __attribute__((no_sanitize("address"))) +#else +#define __no_sanitize_address +#endif +#endif + /* There isn't really a better place for this */ #define C_TO_K(temp_c) ((temp_c) + 273) #define K_TO_C(temp_c) ((temp_c) - 273) diff --git a/include/console.h b/include/console.h index d8da234a24..57a190226b 100644 --- a/include/console.h +++ b/include/console.h @@ -158,7 +158,8 @@ void console_has_input(void); static const char __con_cmd_label_##NAME[] = #NAME; \ struct size_check##NAME { \ int field[2 * (sizeof(__con_cmd_label_##NAME) < 16) - 1]; }; \ - const struct console_command __keep __con_cmd_##NAME \ + const struct console_command __keep __no_sanitize_address \ + __con_cmd_##NAME \ __attribute__((section(".rodata.cmds." #NAME))) = \ { .name = __con_cmd_label_##NAME, \ .handler = ROUTINE, \ diff --git a/include/extension.h b/include/extension.h index ed7dd70f32..b984c583b0 100644 --- a/include/extension.h +++ b/include/extension.h @@ -74,7 +74,8 @@ struct extension_command { ¶ms->out_size); \ return VENDOR_RC_SUCCESS; \ } \ - const struct extension_command __keep __extension_cmd_##code \ + const struct extension_command __keep __no_sanitize_address \ + __extension_cmd_##code \ __attribute__((section(".rodata.extensioncmds"))) \ = {.command_code = code, .handler = func##_wrap } @@ -86,13 +87,15 @@ struct extension_command { return func(params->code, params->buffer, \ params->in_size, ¶ms->out_size); \ } \ - const struct extension_command __keep __vendor_cmd_##cmd_code \ + const struct extension_command __keep __no_sanitize_address \ + __vendor_cmd_##cmd_code \ __attribute__((section(".rodata.extensioncmds"))) \ = {.command_code = cmd_code, .handler = func##_wrap} /* Vendor command which takes params as struct */ #define DECLARE_VENDOR_COMMAND_P(cmd_code, func) \ - const struct extension_command __keep __vendor_cmd_##cmd_code \ + const struct extension_command __keep __no_sanitize_address \ + __vendor_cmd_##cmd_code \ __attribute__((section(".rodata.extensioncmds"))) \ = {.command_code = cmd_code, .handler = func} diff --git a/include/hooks.h b/include/hooks.h index ee1d2bc475..d998523126 100644 --- a/include/hooks.h +++ b/include/hooks.h @@ -266,7 +266,8 @@ int hook_call_deferred(const struct deferred_data *data, int us); * order in which hooks are called. */ #define DECLARE_HOOK(hooktype, routine, priority) \ - const struct hook_data __keep CONCAT4(__hook_, hooktype, _, routine) \ + const struct hook_data __keep __no_sanitize_address \ + CONCAT4(__hook_, hooktype, _, routine) \ __attribute__((section(".rodata." STRINGIFY(hooktype)))) \ = {routine, priority} @@ -290,7 +291,8 @@ int hook_call_deferred(const struct deferred_data *data, int us); * @param routine Function pointer, with prototype void routine(void) */ #define DECLARE_DEFERRED(routine) \ - const struct deferred_data __keep CONCAT2(routine, _data) \ + const struct deferred_data __keep __no_sanitize_address \ + CONCAT2(routine, _data) \ __attribute__((section(".rodata.deferred"))) \ = {routine} diff --git a/include/host_command.h b/include/host_command.h index 1f9718fa5f..e68b86c96d 100644 --- a/include/host_command.h +++ b/include/host_command.h @@ -248,8 +248,9 @@ void host_packet_receive(struct host_packet *pkt); * Register a host command handler with * commands starting at offset 0x0000 */ -#define DECLARE_HOST_COMMAND(command, routine, version_mask) \ - const struct host_command __keep EXPAND(0x0000, command) \ +#define DECLARE_HOST_COMMAND(command, routine, version_mask) \ + const struct host_command __keep __no_sanitize_address \ + EXPAND(0x0000, command) \ __attribute__((section(".rodata.hcmds."EXPANDSTR(0x0000, command)))) \ = {routine, command, version_mask} @@ -258,7 +259,7 @@ void host_packet_receive(struct host_packet *pkt); * commands starting at offset EC_CMD_BOARD_SPECIFIC_BASE, */ #define DECLARE_PRIVATE_HOST_COMMAND(command, routine, version_mask) \ - const struct host_command __keep \ + const struct host_command __keep __no_sanitize_address \ EXPAND(EC_CMD_BOARD_SPECIFIC_BASE, command) \ __attribute__((section(".rodata.hcmds."\ EXPANDSTR(EC_CMD_BOARD_SPECIFIC_BASE, command)))) \ diff --git a/include/mkbp_event.h b/include/mkbp_event.h index 68e29c0cd4..3764c40d5b 100644 --- a/include/mkbp_event.h +++ b/include/mkbp_event.h @@ -40,7 +40,8 @@ struct mkbp_event_source { }; #define DECLARE_EVENT_SOURCE(type, func) \ - const struct mkbp_event_source __keep __evt_src_##type \ + const struct mkbp_event_source __keep \ + __no_sanitize_address _evt_src_##type \ __attribute__((section(".rodata.evtsrcs"))) \ = {type, func} diff --git a/include/test_util.h b/include/test_util.h index e3aa1d8c27..a1ab956359 100644 --- a/include/test_util.h +++ b/include/test_util.h @@ -236,7 +236,8 @@ struct test_i2c_write_dev { * @param routine Function pointer, with the same prototype as i2c_xfer() */ #define DECLARE_TEST_I2C_XFER(routine) \ - const struct test_i2c_xfer __test_i2c_xfer_##routine \ + const struct test_i2c_xfer __no_sanitize_address \ + __test_i2c_xfer_##routine \ __attribute__((section(".rodata.test_i2c.xfer"))) \ = {routine} |