Kconfig 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. menu "Memory protection"
  2. config RT_USING_MEM_PROTECTION
  3. bool "Enable memory protection"
  4. default n
  5. select RT_USING_HEAP
  6. help
  7. Enable memory protection framework using MPU (Memory Protection Unit).
  8. Provides hardware-based memory protection to prevent:
  9. - Stack overflow and underflow
  10. - Buffer overruns
  11. - Unauthorized access to memory regions
  12. - Corruption of kernel data structures
  13. Features:
  14. - Per-thread memory protection
  15. - Stack guard regions
  16. - Configurable memory regions with access permissions
  17. - Exclusive regions for sensitive data
  18. Requirements:
  19. - CPU with MPU support (Cortex-M3/M4/M7/M33/R52, etc.)
  20. - ARCH_MM_MPU or ARCH_ARM_MPU enabled
  21. - RT_USING_HEAP (dynamic memory)
  22. Benefits:
  23. - Catch memory bugs early (development)
  24. - Improve system safety (production)
  25. - Isolate thread memory spaces
  26. Costs:
  27. - Context switch overhead (save/restore MPU regions)
  28. - Configuration complexity
  29. - Slight runtime overhead
  30. Ideal for safety-critical applications and debugging memory issues.
  31. config RT_USING_HW_STACK_GUARD
  32. bool "Enable hardware stack guard"
  33. default n
  34. select RT_USING_MEM_PROTECTION
  35. help
  36. Enable hardware-based stack overflow protection using MPU.
  37. Automatically creates guard regions at the end of each thread's stack
  38. to detect stack overflow at the moment it occurs.
  39. How it works:
  40. - Configures MPU region below stack as no-access
  41. - Stack overflow triggers immediate MPU fault
  42. - Exception handler identifies the overflowing thread
  43. Benefits:
  44. - Immediate detection (vs periodic checks)
  45. - Precise identification of overflow location
  46. - No runtime overhead (hardware-based)
  47. - Catches stack corruption before it spreads
  48. Requirements:
  49. - RT_USING_MEM_PROTECTION enabled
  50. - Sufficient MPU regions (at least 1 per thread)
  51. Recommended for:
  52. - Development and debugging
  53. - Safety-critical systems
  54. - Systems with limited stack space
  55. Note: Requires one MPU region per thread. Check NUM_MEM_REGIONS configuration.
  56. if RT_USING_MEM_PROTECTION
  57. config USE_MEM_PROTECTION_EXAMPLES
  58. bool "Use memory protection examples"
  59. default y
  60. help
  61. Build and include memory protection example code.
  62. Provides demonstration code showing how to:
  63. - Configure memory protection regions
  64. - Set up stack guards
  65. - Add exclusive regions
  66. - Handle protection faults
  67. Useful for:
  68. - Learning memory protection concepts
  69. - Testing MPU functionality
  70. - Debugging protection configurations
  71. Disable for production builds to save code space.
  72. config NUM_MEM_REGIONS
  73. int "Total number of memory protection regions supported by hardware"
  74. help
  75. Total number of MPU regions available in hardware.
  76. This depends on your CPU architecture:
  77. - Cortex-M3/M4: Typically 8 regions
  78. - Cortex-M7: 8 or 16 regions
  79. - Cortex-M33/M85: 8 or 16 regions (configurable in silicon)
  80. - Cortex-R52: 16 or 32 regions
  81. Check your MCU datasheet or reference manual for exact count.
  82. Usage breakdown:
  83. - Stack guard per thread: 1 region per thread
  84. - Exclusive regions: NUM_EXCLUSIVE_REGIONS
  85. - Configurable per thread: NUM_CONFIGURABLE_REGIONS
  86. Formula: NUM_MEM_REGIONS = 1 (stack) + NUM_EXCLUSIVE_REGIONS + NUM_CONFIGURABLE_REGIONS
  87. Example for 8-region MPU with 2 threads:
  88. - Thread 1 stack guard: 1 region
  89. - Thread 2 stack guard: 1 region
  90. - Shared exclusive regions: 2 regions
  91. - Per-thread config: 2 regions per thread
  92. Total: 2 + 2 + 4 = 8 regions
  93. config NUM_EXCLUSIVE_REGIONS
  94. int "Total number of exclusive memory regions added using rt_mprotect_add_exclusive_region API"
  95. help
  96. Number of shared exclusive memory protection regions.
  97. Exclusive regions are memory areas with specific access permissions
  98. shared across all threads (e.g., peripheral registers, kernel data).
  99. Use cases:
  100. - Protect peripheral registers from thread access
  101. - Mark flash memory as read-only/execute-only
  102. - Protect kernel data structures
  103. - Define shared memory with specific permissions
  104. Example configurations:
  105. - Peripheral protection: 1-2 regions
  106. - Kernel data protection: 1 region
  107. - Shared buffers: 0-2 regions
  108. Note: These regions are configured once and apply to all threads.
  109. Set based on your system's protection requirements.
  110. config NUM_CONFIGURABLE_REGIONS
  111. int "Maximum number of configurable memory regions for each thread, excluding stack guard and exclusive regions added using rt_mprotect_add_exclusive_region API"
  112. help
  113. Per-thread configurable memory protection regions.
  114. These regions are specific to each thread and can be configured independently
  115. for thread-specific memory protection needs.
  116. Use cases:
  117. - Protect thread's private data buffers
  118. - Restrict access to thread-local peripherals
  119. - Define custom memory permissions per thread
  120. Calculation:
  121. NUM_CONFIGURABLE_REGIONS = NUM_MEM_REGIONS - 1 (stack) - NUM_EXCLUSIVE_REGIONS
  122. Example for 8-region MPU with 2 exclusive regions:
  123. NUM_CONFIGURABLE_REGIONS = 8 - 1 - 2 = 5 regions per thread
  124. More regions = more flexibility but:
  125. - Increased configuration complexity
  126. - Longer context switch time
  127. - More memory for region descriptors
  128. Set based on your application's per-thread protection needs.
  129. Typical values: 1-4 regions per thread.
  130. endif
  131. endmenu