From f3f7ac9a4b136ed360439363bdde333c237a740c Mon Sep 17 00:00:00 2001
From: Chris Johns <chrisj@rtems.org>
Date: Mon, 22 Dec 2014 11:50:31 +1100
Subject: [PATCH] Panic on RTEMS_FAST_MUTEX network semaphore claim/release.
Fix the code to panic rather than perform a bad access if the network
semaphore is accessed without the stack being intialised.
Closes #2229.
---
cpukit/libnetworking/rtems/rtems_glue.c | 34 +++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/cpukit/libnetworking/rtems/rtems_glue.c b/cpukit/libnetworking/rtems/rtems_glue.c
index 897b868..be57706 100644
a
|
b
|
uint32_t |
117 | 117 | rtems_bsdnet_semaphore_release_recursive(void) |
118 | 118 | { |
119 | 119 | #ifdef RTEMS_FAST_MUTEX |
120 | | uint32_t nest_count = the_networkSemaphore->Core_control.mutex.nest_count; |
| 120 | uint32_t nest_count; |
121 | 121 | uint32_t i; |
122 | 122 | |
| 123 | nest_count = |
| 124 | the_networkSemaphore ? the_networkSemaphore->Core_control.mutex.nest_count : 0; |
123 | 125 | for (i = 0; i < nest_count; ++i) { |
124 | 126 | rtems_bsdnet_semaphore_release(); |
125 | 127 | } |
… |
… |
rtems_bsdnet_semaphore_obtain (void) |
379 | 381 | _Thread_Disable_dispatch(); |
380 | 382 | #endif |
381 | 383 | _ISR_Disable (level); |
382 | | executing = _Thread_Executing; |
383 | | _CORE_mutex_Seize ( |
384 | | &the_networkSemaphore->Core_control.mutex, |
385 | | executing, |
386 | | networkSemaphore, |
387 | | 1, /* wait */ |
388 | | 0, /* forever */ |
389 | | level |
390 | | ); |
| 384 | if (!the_networkSemaphore) |
| 385 | rtems_panic ("rtems-net: network sema obtain: network not initialised\n"); |
| 386 | executing = _Thread_Executing; |
| 387 | _CORE_mutex_Seize ( |
| 388 | &the_networkSemaphore->Core_control.mutex, |
| 389 | executing, |
| 390 | networkSemaphore, |
| 391 | 1, /* wait */ |
| 392 | 0, /* forever */ |
| 393 | level |
| 394 | ); |
391 | 395 | #ifdef RTEMS_SMP |
392 | | _Thread_Enable_dispatch(); |
| 396 | _Thread_Enable_dispatch(); |
393 | 397 | #endif |
394 | | if (executing->Wait.return_code) |
395 | | rtems_panic ("rtems-net: can't obtain network sema: %d\n", |
396 | | executing->Wait.return_code); |
| 398 | if (executing->Wait.return_code) |
| 399 | rtems_panic ("rtems-net: can't obtain network sema: %d\n", |
| 400 | executing->Wait.return_code); |
397 | 401 | #else |
398 | 402 | rtems_status_code sc; |
399 | 403 | |
… |
… |
rtems_bsdnet_semaphore_release (void) |
414 | 418 | int i; |
415 | 419 | |
416 | 420 | _Thread_Disable_dispatch(); |
| 421 | if (!the_networkSemaphore) |
| 422 | rtems_panic ("rtems-net: network sema obtain: network not initialised\n"); |
417 | 423 | i = _CORE_mutex_Surrender ( |
418 | 424 | &the_networkSemaphore->Core_control.mutex, |
419 | 425 | networkSemaphore, |