Skip to content

LWIP system mailbox overflow fix #11976

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

Merged
merged 2 commits into from
Dec 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions features/lwipstack/lwip-sys/arch/lwip_sys_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ void sys_mbox_post(sys_mbox_t *mbox, void *msg) {

int state = osKernelLock();

mbox->queue[mbox->post_idx % MB_SIZE] = msg;
mbox->post_idx += 1;
mbox->queue[mbox->post_idx] = msg;
mbox->post_idx = (mbox->post_idx + 1) % MB_SIZE;

osEventFlagsSet(mbox->id, SYS_MBOX_FETCH_EVENT);
if (mbox->post_idx - mbox->fetch_idx == MB_SIZE-1)
if ((mbox->post_idx + 1) % MB_SIZE == mbox->fetch_idx)
osEventFlagsClear(mbox->id, SYS_MBOX_POST_EVENT);

osKernelRestoreLock(state);
Expand Down Expand Up @@ -207,11 +207,11 @@ err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) {

int state = osKernelLock();

mbox->queue[mbox->post_idx % MB_SIZE] = msg;
mbox->post_idx += 1;
mbox->queue[mbox->post_idx] = msg;
mbox->post_idx = (mbox->post_idx + 1) % MB_SIZE;

osEventFlagsSet(mbox->id, SYS_MBOX_FETCH_EVENT);
if (mbox->post_idx - mbox->fetch_idx == MB_SIZE-1)
if ((mbox->post_idx + 1) % MB_SIZE == mbox->fetch_idx)
osEventFlagsClear(mbox->id, SYS_MBOX_POST_EVENT);

osKernelRestoreLock(state);
Expand Down Expand Up @@ -261,8 +261,8 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) {
int state = osKernelLock();

if (msg)
*msg = mbox->queue[mbox->fetch_idx % MB_SIZE];
mbox->fetch_idx += 1;
*msg = mbox->queue[mbox->fetch_idx];
mbox->fetch_idx = (mbox->fetch_idx + 1) % MB_SIZE;

osEventFlagsSet(mbox->id, SYS_MBOX_POST_EVENT);
if (mbox->post_idx == mbox->fetch_idx)
Expand Down Expand Up @@ -297,8 +297,8 @@ u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) {
int state = osKernelLock();

if (msg)
*msg = mbox->queue[mbox->fetch_idx % MB_SIZE];
mbox->fetch_idx += 1;
*msg = mbox->queue[mbox->fetch_idx];
mbox->fetch_idx = (mbox->fetch_idx + 1) % MB_SIZE;

osEventFlagsSet(mbox->id, SYS_MBOX_POST_EVENT);
if (mbox->post_idx == mbox->fetch_idx)
Expand Down