[libc-commits] [PATCH] D75802: [libc] Add sigaction

Alex Brachet via Phabricator via libc-commits libc-commits at lists.llvm.org
Sat Mar 7 02:42:53 PST 2020


abrachet created this revision.
abrachet added reviewers: sivachandra, MaskRay, PaulkaToast.
Herald added subscribers: tschuett, mgorny.
abrachet marked 3 inline comments as done.
abrachet added inline comments.


================
Comment at: libc/config/linux/signal.h.in:11
 
+#define sigaction __kernel_sigaction
 #include <linux/signal.h>
----------------
This is very not ideal, but the Linux headers expose a different `struct sigaction` than POSIX expects, it has no `sa_action` member.


================
Comment at: libc/spec/stdc.td:217
       [
-        NamedType<"sigset_t">,
         SizeTType,
----------------
I moved this in this patch because I realized `sigset_t` doesn't belong here but rather posix.td, I can do this in a separate patch if reviewers want.


================
Comment at: libc/src/signal/linux/sigaction.cpp:20
+// the signals stack context.
+asm(".text\n"
+    "nop\n"
----------------
To elaborate more on why we can't use a function written in C, we need a way to guarantee that no stack allocations can be made, to my knowledge there is no attribute which satisfies this. The closest is `optimize("O1")` which we can assume wouldn't bother pushing anything but clang doesn't have this. Also see __restore_rt.s, to make this useable with gdb there are a lot of prerequisites which must be met that we cannot do in C (at least easily) unfortunately.


This is a work in progress and is very much not ready.

There are CMake problems to iron out right now, `add_entrypoint_object` cannot take more than 1 source file because `$<TARGET_OBJECTS:${target_name}_objects>` gets expanded to separate objects by a `;`. I also had a hard time just using `add_library` and using that target as a dependency, this has not worked. So for now I have x86 assembly inline in the .cpp file, although I have kept the .s file, I have not bothered to name it according to its architecture or choose an arch specific directory for it because I am just trying to get CMake to work.


https://reviews.llvm.org/D75802

Files:
  libc/config/linux/api.td
  libc/config/linux/signal.h.in
  libc/lib/CMakeLists.txt
  libc/spec/posix.td
  libc/spec/stdc.td
  libc/src/signal/linux/CMakeLists.txt
  libc/src/signal/linux/__restore_rt.s
  libc/src/signal/linux/sigaction.cpp
  libc/src/signal/sigaction.h
  libc/test/src/signal/CMakeLists.txt
  libc/test/src/signal/sigaction_test.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75802.248916.patch
Type: text/x-patch
Size: 10602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20200307/276c8cc3/attachment.bin>


More information about the libc-commits mailing list