# FreeRTOS：队列发送因内部损坏而失败，pxQueue->uxMessagesWaiting = 0xDEAD

- **ID:** `embedded/freertos-queue-overflow-corruption`
- **领域:** embedded
- **类别:** runtime_error
- **错误码:** `FRTOS_ERR_QUEUE_CORRUPT`
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

队列控制块内存损坏，通常由其他任务的缓冲区溢出或释放后使用导致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| FreeRTOS v10.4.6 | active | — | — |
| ARM GCC v12.2.1 | active | — | — |

## 解决方案

1. ```
   Add assertions to check queue integrity before each send: `configASSERT(pxQueue->uxMessagesWaiting <= pxQueue->uxLength);` and debug the memory overwrite source
   ```
2. ```
   Use a memory protection unit (MPU) to guard queue control block memory, e.g., `mpu_set_region(MPU_REGION_QUEUE, (uint32_t)queue_cb, MPU_RW_PRIVILEGED);`
   ```

## 无效尝试

- **** — Increasing queue length does not fix memory corruption; the control block is still overwritten by the same bug. (80% 失败率)
- **** — Timing changes may mask the corruption temporarily but do not eliminate the root cause (e.g., buffer overflow). (75% 失败率)
