diff options
| author | yangwei <[email protected]> | 2024-07-24 16:42:14 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2024-07-24 16:42:14 +0800 |
| commit | 8fd46fb28331a3899b7a813da08358776a821907 (patch) | |
| tree | 51d520785da1d6371630435b0b5dd5720c819ea5 | |
| parent | 42149eae4a2eccd4bd104d8e5757766edd8cf477 (diff) | |
🔧 build(cmake): add UndefinedBehaviorSanitizerRefactor-mq-api
| -rw-r--r-- | CMakeLists.txt | 8 | ||||
| -rw-r--r-- | examples/stellar_plugin/simple_stellar_plugin.c | 10 | ||||
| -rw-r--r-- | src/plugin_manager/plugin_manager.c | 17 | ||||
| -rw-r--r-- | src/stellar_on_sapp/stellar_on_sapp_api.c | 4 | ||||
| -rw-r--r-- | src/stellar_on_sapp/stellar_on_sapp_loader.c | 4 | ||||
| -rw-r--r-- | test/plugin_manager/plugin_manager_gtest_main.cpp | 12 |
6 files changed, 37 insertions, 18 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 261d071..c5db14b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_C_STANDARD 11) #set warning as error -add_compile_options(-Wall -Wextra -Werror -Wno-error=unused-variable -Wno-error=unused-parameter) +add_compile_options(-Wall -Wextra -Werror) if(NOT CMAKE_BUILD_TYPE) @@ -57,7 +57,7 @@ endif() #ASAN option set(ASAN_OPTION "OFF" CACHE STRING " set asan type chosen by the user, using OFF as default") -set_property(CACHE ASAN_OPTION PROPERTY STRINGS OFF ADDRESS THREAD) +set_property(CACHE ASAN_OPTION PROPERTY STRINGS OFF ADDRESS THREAD UBSAN) message(STATUS "ASAN_OPTION='${ASAN_OPTION}'") if(ASAN_OPTION STREQUAL "ADDRESS") @@ -72,6 +72,10 @@ elseif(ASAN_OPTION STREQUAL "THREAD") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan") add_definitions(-DASAN_ENABLED=1) +elseif(ASAN_OPTION STREQUAL "UBSAN") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=undefined -fno-sanitize-recover=all") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=undefined -fno-sanitize-recover=all") + endif() include_directories(${CMAKE_SOURCE_DIR}) diff --git a/examples/stellar_plugin/simple_stellar_plugin.c b/examples/stellar_plugin/simple_stellar_plugin.c index a9cc0ee..aa6bc37 100644 --- a/examples/stellar_plugin/simple_stellar_plugin.c +++ b/examples/stellar_plugin/simple_stellar_plugin.c @@ -1,3 +1,5 @@ +#pragma GCC diagnostic ignored "-Wunused-parameter" + #include "stellar/stellar.h" #include "stellar/packet.h" #include "stellar/session.h" @@ -161,7 +163,7 @@ void simple_plugin_packet_get_exdata(struct packet *pkt, unsigned char ip_proto { struct simple_stellar_plugin_env *env = (struct simple_stellar_plugin_env *)plugin_env; struct simple_stellar_plugin_env *exdata = (struct simple_stellar_plugin_env *)packet_exdata_get(pkt, env->packet_exdata_idx); - assert(memcmp(env, exdata, sizeof(struct simple_stellar_plugin_env)) == 0); + if(memcmp(env, exdata, sizeof(struct simple_stellar_plugin_env)) != 0)abort(); return; } @@ -178,7 +180,7 @@ static void simple_plugin_packet_exdata_free(int idx, void *ex_ptr, void *arg) struct simple_stellar_plugin_env *env = (struct simple_stellar_plugin_env *)arg; assert(env); struct simple_stellar_plugin_env *exdata = (struct simple_stellar_plugin_env *)ex_ptr; - assert(memcmp(env, exdata, sizeof(struct simple_stellar_plugin_env)) == 0); + if(memcmp(env, exdata, sizeof(struct simple_stellar_plugin_env)) != 0)abort(); } static void simple_plugin_packet_msg_free(void *msg, void *msg_free_arg) @@ -186,7 +188,7 @@ static void simple_plugin_packet_msg_free(void *msg, void *msg_free_arg) struct simple_stellar_plugin_env *env = (struct simple_stellar_plugin_env *)msg_free_arg; assert(env); struct simple_stellar_plugin_env *exdata = (struct simple_stellar_plugin_env *)msg; - assert(memcmp(env, exdata, sizeof(struct simple_stellar_plugin_env)) == 0); + if(memcmp(env, exdata, sizeof(struct simple_stellar_plugin_env)) != 0)abort(); } static void simple_plugin_on_packet_msg_cb(struct packet *pkt, int topic_id, const void *msg, void *plugin_env) @@ -194,7 +196,7 @@ static void simple_plugin_on_packet_msg_cb(struct packet *pkt, int topic_id, con struct simple_stellar_plugin_env *env = (struct simple_stellar_plugin_env *)plugin_env; assert(env); struct simple_stellar_plugin_env *exdata = (struct simple_stellar_plugin_env *)msg; - assert(memcmp(env, exdata, sizeof(struct simple_stellar_plugin_env)) == 0); + if(memcmp(env, exdata, sizeof(struct simple_stellar_plugin_env)) != 0)abort(); } void *simple_session_packet_plugin_init(struct stellar *st) diff --git a/src/plugin_manager/plugin_manager.c b/src/plugin_manager/plugin_manager.c index 239b13a..700646f 100644 --- a/src/plugin_manager/plugin_manager.c +++ b/src/plugin_manager/plugin_manager.c @@ -259,7 +259,7 @@ static struct stellar_exdata *per_thread_packet_exdata_arrary_get(struct plugin_ return plug_mgr->per_thread_data[tid].per_thread_pkt_exdata_array.exdata_array; } -static void per_thread_packet_exdata_arrary_clean(struct plugin_manager_schema *plug_mgr, struct packet *pkt) +static void per_thread_packet_exdata_arrary_clean(struct plugin_manager_schema *plug_mgr) { if(plug_mgr==NULL || plug_mgr->stellar_exdata_schema_array == NULL)return; unsigned int len=utarray_len(plug_mgr->stellar_exdata_schema_array); @@ -593,7 +593,7 @@ static void stellar_mq_dispatch(struct stellar_message *priority_mq[], struct st return; } -static void stellar_mq_free(struct session *sess, struct packet *pkt, struct stellar_message **head, UT_array *mq_schema_array) +static void stellar_mq_free(struct stellar_message **head, UT_array *mq_schema_array) { struct stellar_message *mq_elt, *tmp; struct stellar_mq_topic_schema *topic; @@ -780,7 +780,7 @@ static struct stellar_exdata *session_exdata_runtime_new(struct plugin_manager_s return exdata_rt; } -static void session_exdata_runtime_free(struct plugin_manager_schema *plug_mgr, struct session *sess, struct stellar_exdata *exdata_rt) +static void session_exdata_runtime_free(struct plugin_manager_schema *plug_mgr, struct stellar_exdata *exdata_rt) { if(exdata_rt==NULL)return; if(plug_mgr->stellar_exdata_schema_array==NULL)return; @@ -844,7 +844,7 @@ void plugin_manager_session_runtime_free(struct plugin_manager_runtime *rt) } FREE(rt->plugin_ctx_array); } - session_exdata_runtime_free(rt->plug_mgr, rt->sess, rt->sess_exdata_array); + session_exdata_runtime_free(rt->plug_mgr, rt->sess_exdata_array); FREE(rt->sess_exdata_array); FREE(rt); } @@ -896,10 +896,9 @@ void plugin_manager_on_packet_egress(struct plugin_manager_schema *plug_mgr, str int tid=stellar_get_current_thread_id(plug_mgr->st); stellar_mq_dispatch(plug_mgr->per_thread_data[tid].priority_mq, &plug_mgr->per_thread_data[tid].dealth_letter_queue, NULL, pkt); plug_mgr->per_thread_data[tid].pub_packet_msg_cnt=-1;//disable packet message publish - stellar_mq_free(NULL, pkt, - &plug_mgr->per_thread_data[stellar_get_current_thread_id(plug_mgr->st)].dealth_letter_queue, + stellar_mq_free(&plug_mgr->per_thread_data[tid].dealth_letter_queue, plug_mgr->stellar_mq_schema_array); - per_thread_packet_exdata_arrary_clean(plug_mgr, pkt); + per_thread_packet_exdata_arrary_clean(plug_mgr); } /********************************************* @@ -1001,7 +1000,7 @@ void plugin_manager_on_session_egress(struct session *sess, struct packet *pkt) int tid=stellar_get_current_thread_id(plug_mgr_rt->plug_mgr->st); stellar_mq_dispatch(plug_mgr_rt->plug_mgr->per_thread_data[tid].priority_mq, &plug_mgr_rt->plug_mgr->per_thread_data[tid].dealth_letter_queue, sess, pkt); plug_mgr_rt->pub_session_msg_cnt=-1;//disable session message publish - stellar_mq_free(plug_mgr_rt->sess,pkt, &plug_mgr_rt->plug_mgr->per_thread_data[tid].dealth_letter_queue, plug_mgr_rt->plug_mgr->stellar_mq_schema_array); + stellar_mq_free(&plug_mgr_rt->plug_mgr->per_thread_data[tid].dealth_letter_queue, plug_mgr_rt->plug_mgr->stellar_mq_schema_array); return; } @@ -1025,7 +1024,7 @@ void plugin_manager_on_session_closing(struct session *sess) int tid=stellar_get_current_thread_id(plug_mgr_rt->plug_mgr->st); stellar_mq_dispatch(plug_mgr_rt->plug_mgr->per_thread_data[tid].priority_mq, &plug_mgr_rt->plug_mgr->per_thread_data[tid].dealth_letter_queue, sess, NULL); plug_mgr_rt->pub_session_msg_cnt=-1;//disable session message publish - stellar_mq_free(plug_mgr_rt->sess,NULL,&plug_mgr_rt->plug_mgr->per_thread_data[tid].dealth_letter_queue, plug_mgr_rt->plug_mgr->stellar_mq_schema_array); + stellar_mq_free(&plug_mgr_rt->plug_mgr->per_thread_data[tid].dealth_letter_queue, plug_mgr_rt->plug_mgr->stellar_mq_schema_array); return; } diff --git a/src/stellar_on_sapp/stellar_on_sapp_api.c b/src/stellar_on_sapp/stellar_on_sapp_api.c index 269a41c..2574910 100644 --- a/src/stellar_on_sapp/stellar_on_sapp_api.c +++ b/src/stellar_on_sapp/stellar_on_sapp_api.c @@ -223,6 +223,8 @@ inline int polling_on_sapp(struct stellar *st) /********************************************* * STELLAR INFO INTERFACE WRAPPER ON SAPP *********************************************/ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" int stellar_get_worker_thread_num(struct stellar *st) { @@ -234,6 +236,8 @@ int stellar_get_current_thread_id(struct stellar *st) return get_current_worker_thread_id(); } +#pragma GCC diagnostic pop + /********************************************* * PACKET INFO INTERFACE WRAPPER ON SAPP* *********************************************/ diff --git a/src/stellar_on_sapp/stellar_on_sapp_loader.c b/src/stellar_on_sapp/stellar_on_sapp_loader.c index 2e59f87..f0c7536 100644 --- a/src/stellar_on_sapp/stellar_on_sapp_loader.c +++ b/src/stellar_on_sapp/stellar_on_sapp_loader.c @@ -1,8 +1,8 @@ +#pragma GCC diagnostic ignored "-Wunused-parameter" + #include "stellar/stellar.h" #include "stellar/stellar_exdata.h" - #include "stellar_on_sapp.h" - #include <MESA/stream.h> diff --git a/test/plugin_manager/plugin_manager_gtest_main.cpp b/test/plugin_manager/plugin_manager_gtest_main.cpp index d412ee6..6040d72 100644 --- a/test/plugin_manager/plugin_manager_gtest_main.cpp +++ b/test/plugin_manager/plugin_manager_gtest_main.cpp @@ -1,5 +1,6 @@ -#include <gtest/gtest.h> +#pragma GCC diagnostic ignored "-Wunused-parameter" +#include <gtest/gtest.h> #include "stellar/utils.h" #include "plugin_manager_gtest_mock.h" @@ -1078,7 +1079,10 @@ TEST(plugin_manager, session_plugin_on_intrinsic_ingress_egress) { struct session sess[env.N_session]; for(int i=0; i < env.N_session; i++) + { sess[i].plug_mgr_rt=plugin_manager_session_runtime_new(plug_mgr, &sess[i]); + sess[i].type=SESSION_TYPE_TCP; + } for (int j = 0; j < env.N_per_session_pkt_cnt; j++) { @@ -1220,7 +1224,10 @@ TEST(plugin_manager, session_plugin_ignore_on_ctx_new_sub_other_msg) { struct session sess[env.N_session]; for(int i=0; i < env.N_session; i++) + { sess[i].plug_mgr_rt=plugin_manager_session_runtime_new(plug_mgr, &sess[i]); + sess[i].type=SESSION_TYPE_TCP; + } for (int j = 0; j < env.N_per_session_pkt_cnt; j++) { @@ -1385,7 +1392,10 @@ TEST(plugin_manager, session_plugin_pub_msg_overlimt) { struct session sess[env.N_session]; for(int i=0; i < env.N_session; i++) + { sess[i].plug_mgr_rt=plugin_manager_session_runtime_new(plug_mgr, &sess[i]); + sess[i].type=SESSION_TYPE_TCP; + } for (int j = 0; j < env.N_per_session_pkt_cnt; j++) { |
