qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC PATCH 0/5] Scoped locks using attribute((cleanup))


From: Richard Henderson
Subject: Re: [Qemu-devel] [RFC PATCH 0/5] Scoped locks using attribute((cleanup))
Date: Fri, 15 Dec 2017 09:50:41 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0

On 12/12/2017 02:41 PM, Eric Blake wrote:
> On 12/11/2017 03:32 PM, Paolo Bonzini wrote:
>> On 11/12/2017 15:11, Eric Blake wrote:
>>> I don't know if there is a way to make gcc insert stack-unwind
>>> directives that are honored across longjmp (I know C++ does it for
>>> exceptions; so there may be a way, and I just don't know it).
>>
>> Probably -fexceptions.
>>
> 
> Well, that's what 'info gcc' mentions:
> 
> 'cleanup (CLEANUP_FUNCTION)'
>      The 'cleanup' attribute runs a function when the variable goes out
>      of scope.  This attribute can only be applied to auto function
>      scope variables; it may not be applied to parameters or variables
>      with static storage duration.  The function must take one
>      parameter, a pointer to a type compatible with the variable.  The
>      return value of the function (if any) is ignored.
> 
>      If '-fexceptions' is enabled, then CLEANUP_FUNCTION is run during
>      the stack unwinding that happens during the processing of the
>      exception.  Note that the 'cleanup' attribute does not allow the
>      exception to be caught, only to perform an action.  It is undefined
>      what happens if CLEANUP_FUNCTION does not return normally.
> 
> but adding -fexceptions to my sample program does NOT make a difference
> (apparently, unwind cleanup triggered by C++ exceptions is NOT the same
> as unwinding done by longjmp()).

longjmp isn't an exception, and so doesn't run stack cleanups.  You'd need to
use _Unwind_Throw ... except for the fact that C doesn't have a mechanism by
which we can catch it.

We would really need to use C++ and throw to get those semantics.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]