-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Message Queue Limit to Prevent Memory Exhaustion in Embedded Devices #629
Changes from all commits
2a9d523
00bcf01
9c9d562
544f82e
da71883
4eec493
7877fd4
cbfcc01
eba31db
cf6bac9
a82dc4a
8170cad
0607c59
5419e5b
4747dee
6a25e74
fcc5352
2b2f467
e3199dc
497f503
129c206
65ffb5d
ec4dac2
0b456a5
95e6cda
3153809
98e3782
26df754
e6338d2
718ce71
4b254d8
30cace2
72f5d63
584a756
bbdd320
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ if(BUILD_TESTING AND UNIX AND (OC_COMPILER_IS_GCC OR OC_COMPILER_IS_CLANG)) | |
endif() | ||
|
||
######## Build configuration options ######## | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
set(BUILD_EXAMPLE_APPLICATIONS ON CACHE BOOL "Build example applications.") | ||
set(BUILD_MBEDTLS ON CACHE BOOL "Build Mbed TLS library. When set to OFF, the Mbed TLS library with the OCF patches has to be provided.") | ||
set(BUILD_MBEDTLS_FORCE_3_5_0 OFF CACHE BOOL "Force v3.5.0 of the MbedTLS library to be used (by default v3.1.0 is used by master)") | ||
|
@@ -57,15 +59,6 @@ set(OC_PUSH_ENABLED OFF CACHE BOOL "Enable Push Notification.") | |
set(OC_PUSHDEBUG_ENABLED OFF CACHE BOOL "Enable debug messages for Push Notification.") | ||
set(OC_RESOURCE_ACCESS_IN_RFOTM_ENABLED OFF CACHE BOOL "Enable resource access in RFOTM.") | ||
set(OC_MEMORY_TRACE_ENABLED OFF CACHE BOOL "Enable memory tracing.") | ||
if (OC_DEBUG_ENABLED) | ||
set(OC_LOG_MAXIMUM_LOG_LEVEL "TRACE" CACHE STRING "Maximum supported log level in compile time.") | ||
else() | ||
set(OC_LOG_MAXIMUM_LOG_LEVEL "DISABLED" CACHE STRING "Maximum supported log level in compile time.") | ||
endif() | ||
set(OC_INOUT_BUFFER_SIZE "" CACHE STRING "Custom static buffer size for network messages.") | ||
set(OC_INOUT_BUFFER_POOL "" CACHE STRING "Custom static pool size of network messages.") | ||
set(OC_APP_DATA_BUFFER_SIZE "" CACHE STRING "Custom static buffer size for application messages.") | ||
set(OC_APP_DATA_BUFFER_POOL "" CACHE STRING "Custom static size of application messages.") | ||
set(OC_VERSION_1_1_0_ENABLED OFF CACHE BOOL "Enable OCF version 1.1") | ||
set(OC_ETAG_ENABLED OFF CACHE BOOL "Enable Entity Tag (ETag) support.") | ||
set(OC_JSON_ENCODER_ENABLED OFF CACHE BOOL "Enable JSON encoder/decoder support.") | ||
|
@@ -75,7 +68,16 @@ if (BUILD_EXAMPLE_APPLICATIONS OR BUILD_TESTING) | |
endif() | ||
set(PLGD_DEV_TIME_ENABLED OFF CACHE BOOL "Enable plgd time feature.") | ||
|
||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
if (OC_DEBUG_ENABLED) | ||
set(OC_LOG_MAXIMUM_LOG_LEVEL "TRACE" CACHE STRING "Maximum supported log level in compile time.") | ||
else() | ||
set(OC_LOG_MAXIMUM_LOG_LEVEL "DISABLED" CACHE STRING "Maximum supported log level in compile time.") | ||
endif() | ||
set(OC_INOUT_BUFFER_SIZE "" CACHE STRING "Custom static buffer size for network messages.") | ||
set(OC_INOUT_BUFFER_POOL "" CACHE STRING "Custom static pool size of network messages.") | ||
set(OC_APP_DATA_BUFFER_SIZE "" CACHE STRING "Custom static buffer size for application messages.") | ||
set(OC_APP_DATA_BUFFER_POOL "" CACHE STRING "Custom static size of application messages.") | ||
set(OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS "" CACHE STRING "Maximum number of messages in the network event queue for a device.") | ||
|
||
set(OC_ASAN_ENABLED OFF CACHE BOOL "Enable address sanitizer build.") | ||
set(OC_LSAN_ENABLED OFF CACHE BOOL "Enable leak sanitizer build.") | ||
|
@@ -399,38 +401,6 @@ if(OC_MEMORY_TRACE_ENABLED) | |
list(APPEND TEST_COMPILE_DEFINITIONS "OC_MEMORY_TRACE") | ||
endif() | ||
|
||
if (NOT("${OC_INOUT_BUFFER_SIZE}" STREQUAL "")) | ||
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED) | ||
message(FATAL_ERROR "Cannot set custom static buffer size for network messages without dynamic allocation") | ||
endif() | ||
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_INOUT_BUFFER_SIZE=(${OC_INOUT_BUFFER_SIZE})") | ||
list(APPEND MBEDTLS_COMPILE_DEFINITIONS "OC_INOUT_BUFFER_SIZE=(${OC_INOUT_BUFFER_SIZE})") | ||
endif() | ||
|
||
if (NOT("${OC_INOUT_BUFFER_POOL}" STREQUAL "")) | ||
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED) | ||
message(FATAL_ERROR "Cannot set custom static pool size for network messages without dynamic allocation") | ||
endif() | ||
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_INOUT_BUFFER_POOL=(${OC_INOUT_BUFFER_POOL})") | ||
list(APPEND MBEDTLS_COMPILE_DEFINITIONS "OC_INOUT_BUFFER_POOL=(${OC_INOUT_BUFFER_POOL})") | ||
endif() | ||
|
||
if (NOT("${OC_APP_DATA_BUFFER_SIZE}" STREQUAL "")) | ||
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED) | ||
message(FATAL_ERROR "Cannot set custom static buffer size for application messages without dynamic allocation") | ||
endif() | ||
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_APP_DATA_BUFFER_SIZE=(${OC_APP_DATA_BUFFER_SIZE})") | ||
list(APPEND MBEDTLS_COMPILE_DEFINITIONS "OC_APP_DATA_BUFFER_SIZE=(${OC_APP_DATA_BUFFER_SIZE})") | ||
endif() | ||
|
||
if (NOT("${OC_APP_DATA_BUFFER_POOL}" STREQUAL "")) | ||
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED) | ||
message(FATAL_ERROR "Cannot set custom static pool size for application messages without dynamic allocation") | ||
endif() | ||
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_APP_DATA_BUFFER_POOL=(${OC_APP_DATA_BUFFER_POOL})") | ||
list(APPEND MBEDTLS_COMPILE_DEFINITIONS "OC_APP_DATA_BUFFER_POOL=(${OC_APP_DATA_BUFFER_POOL})") | ||
endif() | ||
|
||
if(OC_VERSION_1_1_0_ENABLED) | ||
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_SPEC_VER_OIC") | ||
endif() | ||
|
@@ -454,6 +424,53 @@ if(PLGD_DEV_TIME_ENABLED) | |
endif() | ||
endif() | ||
|
||
if(NOT("${OC_INOUT_BUFFER_SIZE}" STREQUAL "")) | ||
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED) | ||
message(FATAL_ERROR "Cannot OC_INOUT_BUFFER_SIZE without dynamic allocation") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error handling for dynamic allocation settings is robust, ensuring that features dependent on dynamic allocation are not mistakenly enabled without it. However, consider enhancing the error messages to guide users more effectively on how to correct their setup. - message(FATAL_ERROR "Cannot set OC_INOUT_BUFFER_SIZE without dynamic allocation")
+ message(FATAL_ERROR "Dynamic allocation is disabled. Enable OC_DYNAMIC_ALLOCATION to set OC_INOUT_BUFFER_SIZE.")
- message(FATAL_ERROR "Cannot set OC_INOUT_BUFFER_POOL without dynamic allocation")
+ message(FATAL_ERROR "Dynamic allocation is disabled. Enable OC_DYNAMIC_ALLOCATION to set OC_INOUT_BUFFER_POOL.")
- message(FATAL_ERROR "Cannot set OC_APP_DATA_BUFFER_SIZE without dynamic allocation")
+ message(FATAL_ERROR "Dynamic allocation is disabled. Enable OC_DYNAMIC_ALLOCATION to set OC_APP_DATA_BUFFER_SIZE.")
- message(FATAL_ERROR "Cannot set OC_APP_DATA_BUFFER_POOL without dynamic allocation")
+ message(FATAL_ERROR "Dynamic allocation is disabled. Enable OC_DYNAMIC_ALLOCATION to set OC_APP_DATA_BUFFER_POOL.")
- message(FATAL_ERROR "Cannot set OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS without dynamic allocation")
+ message(FATAL_ERROR "Dynamic allocation is disabled. Enable OC_DYNAMIC_ALLOCATION to set OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS.") Also applies to: 439-439, 449-449, 459-459, 469-469 |
||
endif() | ||
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_INOUT_BUFFER_SIZE=(${OC_INOUT_BUFFER_SIZE})") | ||
if(BUILD_MBEDTLS) | ||
list(APPEND MBEDTLS_COMPILE_DEFINITIONS "OC_INOUT_BUFFER_SIZE=(${OC_INOUT_BUFFER_SIZE})") | ||
endif() | ||
endif() | ||
|
||
if(NOT("${OC_INOUT_BUFFER_POOL}" STREQUAL "")) | ||
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED) | ||
message(FATAL_ERROR "Cannot set OC_INOUT_BUFFER_POOL without dynamic allocation") | ||
endif() | ||
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_INOUT_BUFFER_POOL=(${OC_INOUT_BUFFER_POOL})") | ||
if(BUILD_MBEDTLS) | ||
list(APPEND MBEDTLS_COMPILE_DEFINITIONS "OC_INOUT_BUFFER_POOL=(${OC_INOUT_BUFFER_POOL})") | ||
endif() | ||
endif() | ||
|
||
if(NOT("${OC_APP_DATA_BUFFER_SIZE}" STREQUAL "")) | ||
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED) | ||
message(FATAL_ERROR "Cannot set OC_APP_DATA_BUFFER_SIZE without dynamic allocation") | ||
endif() | ||
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_APP_DATA_BUFFER_SIZE=(${OC_APP_DATA_BUFFER_SIZE})") | ||
if(BUILD_MBEDTLS) | ||
list(APPEND MBEDTLS_COMPILE_DEFINITIONS "OC_APP_DATA_BUFFER_SIZE=(${OC_APP_DATA_BUFFER_SIZE})") | ||
endif() | ||
endif() | ||
|
||
if(NOT("${OC_APP_DATA_BUFFER_POOL}" STREQUAL "")) | ||
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED) | ||
message(FATAL_ERROR "Cannot OC_APP_DATA_BUFFER_POOL without dynamic allocation") | ||
endif() | ||
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_APP_DATA_BUFFER_POOL=(${OC_APP_DATA_BUFFER_POOL})") | ||
if(BUILD_MBEDTLS) | ||
list(APPEND MBEDTLS_COMPILE_DEFINITIONS "OC_APP_DATA_BUFFER_POOL=(${OC_APP_DATA_BUFFER_POOL})") | ||
endif() | ||
endif() | ||
|
||
if(NOT("${OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS}" STREQUAL "")) | ||
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED) | ||
message(FATAL_ERROR "Cannot set OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS without dynamic allocation") | ||
Danielius1922 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
endif() | ||
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS=(${OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS})") | ||
endif() | ||
|
||
if(BUILD_TESTING) | ||
list(APPEND PRIVATE_COMPILE_DEFINITIONS "OC_TEST") | ||
if(BUILD_MBEDTLS) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The introduction of
OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS
is crucial for managing memory on devices. Ensure this is well-documented in the developer's guide or relevant markdown files to aid understanding and usage.Consider adding a detailed comment here explaining the purpose and usage of
OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS
to improve code readability and maintenance.