-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Based on a change recommended by Mark Shulte:
Signal handlers maybe run with interrupts enabled or disabled, depending on how the task the received the signal was blocked. (i.e.: If sem_wait() is called, then we disable interrupts, then block the currently running task). This could be dangerous, because user code would be running with interrupts disabled. This change forces interrupts to be enabled in up_sigdeliver() before executing the signal handler calling up_irq_enable() explicitly. This is safe because, when we return to normal execution, interrupts will be restored to their previous state when the signal handler returns.
- Loading branch information
1 parent
9222f50
commit 977d41d
Showing
20 changed files
with
134 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/**************************************************************************** | ||
* arch/arm/src/arm/up_sigdeliver.c | ||
* | ||
* Copyright (C) 2007-2010, 2015 Gregory Nutt. All rights reserved. | ||
* Copyright (C) 2007-2010, 2015, 2018 Gregory Nutt. All rights reserved. | ||
* Author: Gregory Nutt <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -113,9 +113,13 @@ void up_sigdeliver(void) | |
sigdeliver = rtcb->xcp.sigdeliver; | ||
rtcb->xcp.sigdeliver = NULL; | ||
|
||
/* Then restore the task interrupt state */ | ||
#ifndef CONFIG_SUPPRESS_INTERRUPTS | ||
/* Then make sure that interrupts are enabled. Signal handlers must always | ||
* run with interrupts enabled. | ||
*/ | ||
|
||
up_irq_restore(regs[REG_CPSR]); | ||
up_irq_enable(); | ||
#endif | ||
|
||
/* Deliver the signals */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/**************************************************************************** | ||
* arch/arm/src/armv6-m/up_sigdeliver.c | ||
* | ||
* Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. | ||
* Copyright (C) 2013-2015, 2018 Gregory Nutt. All rights reserved. | ||
* Author: Gregory Nutt <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -54,18 +54,6 @@ | |
|
||
#ifndef CONFIG_DISABLE_SIGNALS | ||
|
||
/**************************************************************************** | ||
* Pre-processor Definitions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Private Data | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Private Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Public Functions | ||
****************************************************************************/ | ||
|
@@ -122,9 +110,13 @@ void up_sigdeliver(void) | |
sigdeliver = rtcb->xcp.sigdeliver; | ||
rtcb->xcp.sigdeliver = NULL; | ||
|
||
/* Then restore the task interrupt state */ | ||
#ifndef CONFIG_SUPPRESS_INTERRUPTS | ||
/* Then make sure that interrupts are enabled. Signal handlers must always | ||
* run with interrupts enabled. | ||
*/ | ||
|
||
up_irq_restore((uint8_t)regs[REG_PRIMASK]); | ||
up_irq_enable(); | ||
#endif | ||
|
||
/* Deliver the signal */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/**************************************************************************** | ||
* arch/arm/src/armv7-a/arm_sigdeliver.c | ||
* | ||
* Copyright (C) 2013, 2015-2016 Gregory Nutt. All rights reserved. | ||
* Copyright (C) 2013, 2015-2016, 2018 Gregory Nutt. All rights reserved. | ||
* Author: Gregory Nutt <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -101,9 +101,13 @@ void up_sigdeliver(void) | |
sigdeliver = rtcb->xcp.sigdeliver; | ||
rtcb->xcp.sigdeliver = NULL; | ||
|
||
/* Then restore the task interrupt state */ | ||
#ifndef CONFIG_SUPPRESS_INTERRUPTS | ||
/* Then make sure that interrupts are enabled. Signal handlers must always | ||
* run with interrupts enabled. | ||
*/ | ||
|
||
leave_critical_section(regs[REG_CPSR]); | ||
up_irq_enable(); | ||
#endif | ||
|
||
/* Deliver the signal */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
/**************************************************************************** | ||
* arch/arm/src/armv7-m/up_sigdeliver.c | ||
* | ||
* Copyright (C) 2009-2010, 2013-2016 Gregory Nutt. All rights reserved. | ||
* Copyright (C) 2009-2010, 2013-2016, 2018 Gregory Nutt. All rights | ||
* reserved. | ||
* Author: Gregory Nutt <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -109,12 +110,12 @@ void up_sigdeliver(void) | |
sigdeliver = (sig_deliver_t)rtcb->xcp.sigdeliver; | ||
rtcb->xcp.sigdeliver = NULL; | ||
|
||
/* Then restore the task interrupt state */ | ||
#ifndef CONFIG_SUPPRESS_INTERRUPTS | ||
/* Then make sure that interrupts are enabled. Signal handlers must always | ||
* run with interrupts enabled. | ||
*/ | ||
|
||
#ifdef CONFIG_ARMV7M_USEBASEPRI | ||
leave_critical_section((uint8_t)regs[REG_BASEPRI]); | ||
#else | ||
leave_critical_section((uint16_t)regs[REG_PRIMASK]); | ||
up_irq_enable(); | ||
#endif | ||
|
||
/* Deliver the signal */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/**************************************************************************** | ||
* arch/arm/src/armv7-r/arm_sigdeliver.c | ||
* | ||
* Copyright (C) 2015 Gregory Nutt. All rights reserved. | ||
* Copyright (C) 2015, 2018 Gregory Nutt. All rights reserved. | ||
* Author: Gregory Nutt <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -101,9 +101,13 @@ void up_sigdeliver(void) | |
sigdeliver = rtcb->xcp.sigdeliver; | ||
rtcb->xcp.sigdeliver = NULL; | ||
|
||
/* Then restore the task interrupt state */ | ||
#ifndef CONFIG_SUPPRESS_INTERRUPTS | ||
/* Then make sure that interrupts are enabled. Signal handlers must always | ||
* run with interrupts enabled. | ||
*/ | ||
|
||
up_irq_restore(regs[REG_CPSR]); | ||
up_irq_enable(); | ||
#endif | ||
|
||
/* Deliver the signals */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/**************************************************************************** | ||
* arch/avr/src/avr/up_sigdeliver.c | ||
* | ||
* Copyright (C) 2011, 2015 Gregory Nutt. All rights reserved. | ||
* Copyright (C) 2011, 2015, 2018 Gregory Nutt. All rights reserved. | ||
* Author: Gregory Nutt <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -104,9 +104,13 @@ void up_sigdeliver(void) | |
sigdeliver = rtcb->xcp.sigdeliver; | ||
rtcb->xcp.sigdeliver = NULL; | ||
|
||
/* Then restore the task interrupt state */ | ||
#ifndef CONFIG_SUPPRESS_INTERRUPTS | ||
/* Then make sure that interrupts are enabled. Signal handlers must always | ||
* run with interrupts enabled. | ||
*/ | ||
|
||
up_irq_restore(regs[REG_SREG]); | ||
up_irq_enable(); | ||
#endif | ||
|
||
/* Deliver the signals */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/**************************************************************************** | ||
* arch/avr/src/avr32/up_sigdeliver.c | ||
* | ||
* Copyright (C) 2010, 2015 Gregory Nutt. All rights reserved. | ||
* Copyright (C) 2010, 2015, 2018 Gregory Nutt. All rights reserved. | ||
* Author: Gregory Nutt <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -104,9 +104,13 @@ void up_sigdeliver(void) | |
sigdeliver = rtcb->xcp.sigdeliver; | ||
rtcb->xcp.sigdeliver = NULL; | ||
|
||
/* Then restore the task interrupt state */ | ||
#ifndef CONFIG_SUPPRESS_INTERRUPTS | ||
/* Then make sure that interrupts are enabled. Signal handlers must always | ||
* run with interrupts enabled. | ||
*/ | ||
|
||
up_irq_restore(regs[REG_SR]); | ||
up_irq_enable(); | ||
#endif | ||
|
||
/* Deliver the signals */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/**************************************************************************** | ||
* arch/mips/src/mips32/up_sigdeliver.c | ||
* | ||
* Copyright (C) 2011, 2015 Gregory Nutt. All rights reserved. | ||
* Copyright (C) 2011, 2015, 2018 Gregory Nutt. All rights reserved. | ||
* Author: Gregory Nutt <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -114,9 +114,13 @@ void up_sigdeliver(void) | |
sigdeliver = rtcb->xcp.sigdeliver; | ||
rtcb->xcp.sigdeliver = NULL; | ||
|
||
/* Then restore the task interrupt state */ | ||
#ifndef CONFIG_SUPPRESS_INTERRUPTS | ||
/* Then make sure that interrupts are enabled. Signal handlers must always | ||
* run with interrupts enabled. | ||
*/ | ||
|
||
up_irq_restore((irqstate_t)regs[REG_STATUS]); | ||
up_irq_enable(); | ||
#endif | ||
|
||
/* Deliver the signals */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/**************************************************************************** | ||
* arch/misoc/src/lm32/lm32_sigdeliver.c | ||
* | ||
* Copyright (C) 2016 Gregory Nutt. All rights reserved. | ||
* Copyright (C) 2016, 2018 Gregory Nutt. All rights reserved. | ||
* Author: Gregory Nutt <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -101,9 +101,13 @@ void lm32_sigdeliver(void) | |
sigdeliver = rtcb->xcp.sigdeliver; | ||
rtcb->xcp.sigdeliver = NULL; | ||
|
||
/* Then restore the task interrupt state */ | ||
#ifndef CONFIG_SUPPRESS_INTERRUPTS | ||
/* Then make sure that interrupts are enabled. Signal handlers must always | ||
* run with interrupts enabled. | ||
*/ | ||
|
||
up_irq_restore((irqstate_t)regs[REG_INT_CTX]); | ||
up_irq_enable(); | ||
#endif | ||
|
||
/* Deliver the signals */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/**************************************************************************** | ||
* arch/renesas/src/m16c/m16c_sigdeliver.c | ||
* | ||
* Copyright (C) 2009-2010, 2015 Gregory Nutt. All rights reserved. | ||
* Copyright (C) 2009-2010, 2015, 2018 Gregory Nutt. All rights reserved. | ||
* Author: Gregory Nutt <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -115,9 +115,13 @@ void up_sigdeliver(void) | |
sigdeliver = rtcb->xcp.sigdeliver; | ||
rtcb->xcp.sigdeliver = NULL; | ||
|
||
/* Then restore the task interrupt state. */ | ||
#ifndef CONFIG_SUPPRESS_INTERRUPTS | ||
/* Then make sure that interrupts are enabled. Signal handlers must always | ||
* run with interrupts enabled. | ||
*/ | ||
|
||
up_irq_restore(rtcb->xcp.saved_flg); | ||
up_irq_enable(); | ||
#endif | ||
|
||
/* Deliver the signals */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/**************************************************************************** | ||
* arch/renesas/src/common/up_sigdeliver.c | ||
* | ||
* Copyright (C) 2008-2010, 2015 Gregory Nutt. All rights reserved. | ||
* Copyright (C) 2008-2010, 2015, 2018 Gregory Nutt. All rights reserved. | ||
* Author: Gregory Nutt <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -114,9 +114,13 @@ void up_sigdeliver(void) | |
sigdeliver = rtcb->xcp.sigdeliver; | ||
rtcb->xcp.sigdeliver = NULL; | ||
|
||
/* Then restore the task interrupt state. */ | ||
#ifndef CONFIG_SUPPRESS_INTERRUPTS | ||
/* Then make sure that interrupts are enabled. Signal handlers must always | ||
* run with interrupts enabled. | ||
*/ | ||
|
||
up_irq_restore(regs[REG_SR] & 0x000000f0); | ||
up_irq_enable(); | ||
#endif | ||
|
||
/* Deliver the signals */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/**************************************************************************** | ||
* arch/risc-v/src/rv32im/up_sigdeliver.c | ||
* | ||
* Copyright (C) 2011, 2015 Gregory Nutt. All rights reserved. | ||
* Copyright (C) 2011, 2015, 2018 Gregory Nutt. All rights reserved. | ||
* Author: Gregory Nutt <[email protected]> | ||
* | ||
* Modified for RISC-V: | ||
|
@@ -60,18 +60,6 @@ | |
|
||
#ifndef CONFIG_DISABLE_SIGNALS | ||
|
||
/**************************************************************************** | ||
* Pre-processor Definitions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Private Data | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Private Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Public Functions | ||
****************************************************************************/ | ||
|
@@ -119,9 +107,13 @@ void up_sigdeliver(void) | |
sigdeliver = rtcb->xcp.sigdeliver; | ||
rtcb->xcp.sigdeliver = NULL; | ||
|
||
/* Then restore the task interrupt state */ | ||
#ifndef CONFIG_SUPPRESS_INTERRUPTS | ||
/* Then make sure that interrupts are enabled. Signal handlers must always | ||
* run with interrupts enabled. | ||
*/ | ||
|
||
up_irq_restore((irqstate_t)regs[REG_INT_CTX]); | ||
up_irq_enable(); | ||
#endif | ||
|
||
/* Deliver the signals */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/**************************************************************************** | ||
* arch/x86/src/i486/up_sigdeliver.c | ||
* | ||
* Copyright (C) 2011, 2015 Gregory Nutt. All rights reserved. | ||
* Copyright (C) 2011, 2015, 2018 Gregory Nutt. All rights reserved. | ||
* Author: Gregory Nutt <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
|
@@ -54,18 +54,6 @@ | |
|
||
#ifndef CONFIG_DISABLE_SIGNALS | ||
|
||
/**************************************************************************** | ||
* Pre-processor Definitions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Private Data | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Private Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Public Functions | ||
****************************************************************************/ | ||
|
@@ -113,9 +101,13 @@ void up_sigdeliver(void) | |
sigdeliver = rtcb->xcp.sigdeliver; | ||
rtcb->xcp.sigdeliver = NULL; | ||
|
||
/* Then restore the task interrupt state */ | ||
#ifndef CONFIG_SUPPRESS_INTERRUPTS | ||
/* Then make sure that interrupts are enabled. Signal handlers must always | ||
* run with interrupts enabled. | ||
*/ | ||
|
||
up_irq_restore(regs[REG_EFLAGS]); | ||
up_irq_enable(); | ||
#endif | ||
|
||
/* Deliver the signals */ | ||
|
||
|
Oops, something went wrong.