This is the mail archive of the
mailing list for the GCC project.
How do I set SIG_ATOMIC_TYPE to a variant of a C-type?
- From: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 15 May 2012 21:34:40 +0200
- Subject: How do I set SIG_ATOMIC_TYPE to a variant of a C-type?
I'm considering changing SIG_ATOMIC_TYPE for CRIS (*-elf and
*-linux-gnu) to the effect of
#define SIG_ATOMIC_TYPE "int __attribute__((__aligned__(4)))"
but that by itself doesn't work. It causes a SEGV on the 4.7
branch and no doubt also on trunk; the code is the same. From a
gdb session it appears the type is expected to already exist as
a built-in C type, like the (undecorated) "int" or "char" types,
which are created much earlier in the same function.
How do I accomplish setting SIG_ATOMIC_TYPE as above?
Ok, someone is going to ask "why": in the ABI used for CRIS, all
types have byte alignment; structs are "packed". Linux could
(AFAIU, theoretically) perform a context-switch if a process
gets a page-fault writing to a "sigatomic_t" plain "int" that's
straddling a page boundary where one of the pages isn't present
(say, not yet in the TLB, or paged out). When the process gets
to execute again, a signal could be waiting (say, SIGALRM) and
the signal handler entered, but that plain "int" is not written
in whole; presto, the access not atomic as seen by the
signal-handler. (In case of a very possible thinko here, please
don't forget the first question.)