[Development] Using platform-native APIs for terminating QThreads

Viktor Engelmann viktor.engelmann at qt.io
Mon Sep 5 16:08:41 CEST 2016


So what if the user adds an asm statement that changes a register and
doesn't declare that register to be changed? That would also cause his
"Qt" application to misbehave... or what if he links the object files to
a custom loader that doesn't call the constructors for global objects?

We can lock away OUR guns so the user can't shoot himself in the foot
with them, but if he goes out and buys his own gun, there is nothing we
can (or should) do about it.

Just my 2 cents.

Viktor


Am 03.09.2016 um 09:03 schrieb Thiago Macieira:
> Em sexta-feira, 2 de setembro de 2016, às 23:45:26 CEST, Marc Mutz escreveu:
>> On Friday 02 September 2016 22:35:59 Thiago Macieira wrote:
>>> However, the documentation from the ABI says that forced unwinds cannot be
>>> stopped, so you can't swallow the exception even if you wanted to. Are you
>>> sure that the application crashes when you pthread_exit() when
>>> QThreadPrivate::start() is noexcept?
>> Can't swallow doesn't mean can't catch. You can catch it, but you can't not
>> rethrow. But if you call std::terminate(), the rethrow will never be
>> reached.
> But that doesn't do what we want. We want to rethrow the __forced_unwind 
> exception so that it terminates the thread, but not the entire application.
>
> But anyway, what I asked didn't work. Test app:
>
> #include <pthread.h>
>
> void do_exit() noexcept
> {
>     pthread_exit(nullptr);
> }
>
> int dummy;
> void *thread_function(void *)
> {
>     do_exit();
>     return &dummy;
> }
>
> int main()
> {
>     pthread_t thr;
>     void *retval;
>     pthread_create(&thr, nullptr, thread_function, nullptr);
>     pthread_join(thr, &retval);
>     return retval == nullptr ? 0 : 1;
> }
>
> Crash backtrace:
> #0  0x00007ffff6fa9975 in raise () from /lib64/libc.so.6
> #1  0x00007ffff6faad8a in abort () from /lib64/libc.so.6
> #2  0x00007ffff78ca6bd in __gnu_cxx::__verbose_terminate_handler() () from /
> usr/lib64/libstdc++.so.6
> #3  0x00007ffff78c8696 in ?? () from /usr/lib64/libstdc++.so.6
> #4  0x00007ffff78c86e1 in std::terminate() () from /usr/lib64/libstdc++.so.6
> #5  0x00007ffff78c8314 in __gxx_personality_v0 () from /usr/lib64/libstdc+
> +.so.6
> #6  0x00007ffff73275a9 in ?? () from /lib64/libgcc_s.so.1
> #7  0x00007ffff7327904 in _Unwind_ForcedUnwind () from /lib64/libgcc_s.so.1
> #8  0x00007ffff7bcacb0 in __pthread_unwind () from /lib64/libpthread.so.0
> #9  0x00007ffff7bc3595 in pthread_exit () from /lib64/libpthread.so.0
> #10 0x0000000000400794 in do_exit() ()
> #11 0x00000000004007a5 in thread_function(void*) ()
> #12 0x00007ffff7bc2474 in start_thread () from /lib64/libpthread.so.0
> #13 0x00007ffff705d3ed in clone () from /lib64/libc.so.6
>
> I'll post to cxxabi and ask that __forced_unwind be made public API.

-- 


Viktor Engelmann
Software Engineer

The Qt Company GmbH
Rudower Chaussee 13
D-12489 Berlin
Viktor.Engelmann at qt.io
+49 151 26784521
http://qt.io

Geschäftsführer: Mika Pälsi, Juha Varelius, Mika Harjuaho
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht
Charlottenburg, HRB 144331 B
<http://qt.io>
<http://www.facebook.com/Qt> 	<http://www.twitter.com/qtproject>
<https://www.linkedin.com/company/the-qt-company/>
<https://plus.google.com/104580575722059274792>
<https://www.youtube.com/QtStudios>

Qt World Summit 2016 <http://qtworldsummit.com/>
Qt World Summit 2016 | Pier 27, San Francisco, CA
Experience Exponential Potential on October 18-20
www.qtworldsummit.com <http://www.qtworldsummit.com>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160905/523cdb34/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_logo_with_text_green_rgb_400x141.png
Type: image/png
Size: 16849 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160905/523cdb34/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_facebook.png
Type: image/png
Size: 1407 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160905/523cdb34/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_twitter.png
Type: image/png
Size: 1778 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160905/523cdb34/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_linkedin.png
Type: image/png
Size: 1532 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160905/523cdb34/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_googleplus.png
Type: image/png
Size: 1957 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160905/523cdb34/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_youtube.png
Type: image/png
Size: 1610 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160905/523cdb34/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qtworldsummit2016_banner.jpg
Type: image/jpeg
Size: 35183 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160905/523cdb34/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: viktor_engelmann.vcf
Type: text/x-vcard
Size: 271 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160905/523cdb34/attachment.vcf>


More information about the Development mailing list