Page MenuHomePhabricator

[libc] Create abort and _Exit
ClosedPublic

Authored by abrachet on Feb 20 2020, 10:42 PM.

Details

Summary

This revision creates abort and _Exit implementations

Diff Detail

Event Timeline

abrachet created this revision.Feb 20 2020, 10:42 PM
abrachet marked an inline comment as done.Feb 20 2020, 10:48 PM

There are no tests at the moment, although I have tested them. I am waiting for D74665 (which I am waiting for D74652 to hopeful reuse some code), but didn't want this patch to block on these. I'd be happy to rebase against D74665 and add tests here though.

libc/spec/stdc.td
175–176

These should both be _Noreturn or __attribute__((noreturn)) I'm not sure how best to express this. Should I add a noreturn macro to include/__llvm_libc_common.h? Then how would I express this in stdc.td?

MaskRay added inline comments.Feb 20 2020, 11:11 PM
libc/src/stdlib/abort.cpp
19

If there is a signal handler for SIGABRT, the code should try blocking the signal. Since signals are not available, this is fine.

libc/src/stdlib/linux/_Exit.cpp
19

Which arch does not define SYS_exit_group?

abrachet updated this revision to Diff 245796.Feb 20 2020, 11:29 PM

Remove #ifdef for exit_group.
Add todo to ignore SIGABRT before raise.

abrachet marked 2 inline comments as done.Feb 20 2020, 11:39 PM
abrachet added inline comments.
libc/src/stdlib/abort.cpp
19

I have added the above TODO. Maybe it is wrong as I think more about it though, maybe sigprocmask is a better choice to remove the signal handler.

I think there also needs to be some kind of lock once we start playing with signal handlers. WDYT?

libc/src/stdlib/linux/_Exit.cpp
19

It is since 2.5.35. I guess that is old enough to remove the check, so I have removed it.

abrachet updated this revision to Diff 246066.Feb 22 2020, 1:51 AM

Rebase against D74665 to provide tests for this patch.

sivachandra added inline comments.Feb 28 2020, 4:16 PM
libc/spec/stdc.td
175–176
libc/src/stdlib/abort.cpp
19

Yeah. Please add a big TODO comment explaining what you intend to do in follow-up patches. To get it right, I agree with you that we will need a lock (or multiple locks). So, once the mutex patch lands, we can get back to finishing this.

abrachet updated this revision to Diff 247477.Feb 29 2020, 7:54 PM
  • Added more descriptive TODO to abort
  • Added forgotten entry points in lib/CMakeLists.txt
  • Added changes from D75393
  • Rebased against d1536673c68d

Just a few comments on comments. But, overall LGTM.

libc/src/stdlib/abort.cpp
19

Do you need sigaction also?

20

I think you mean SIG_DFL?

22

I am being pedantic but I think it is important to leave a more detailed comment here: I think I understand why we need a recursive mutex, but can you also explicitly detail in the comment why a recursive mutex et al is required.

abrachet updated this revision to Diff 248405.Mar 5 2020, 12:01 AM

Update todo comment for abort

abrachet marked 6 inline comments as done.Mar 5 2020, 12:06 AM
abrachet added inline comments.
libc/src/stdlib/abort.cpp
19

Yes to remove the user installed SIGABRT handler.

19

Yeah. Please add a big TODO comment explaining what you intend to do in follow-up patches. To get it right, I agree with you that we will need a lock (or multiple locks). So, once the mutex patch lands, we can get back to finishing this.

I have added what I think I will do in the future but the more I think about this the more complicated it is. The future patches here should be interesting :)

20

Indeed, good catch

sivachandra accepted this revision.Mar 5 2020, 9:12 AM
This revision is now accepted and ready to land.Mar 5 2020, 9:12 AM
This revision was automatically updated to reflect the committed changes.
abrachet marked 2 inline comments as done.
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2020, 11:32 AM