Bug 207079 - #include <signal.h> doesn't make ucontext_t available
Summary: #include <signal.h> doesn't make ucontext_t available
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: standards (show other bugs)
Version: 10.2-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-standards mailing list
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2016-02-10 14:35 UTC by Ting-Wei Lan
Modified: 2019-02-22 00:09 UTC (History)
2 users (show)

See Also:


Attachments
A fix (3.65 KB, patch)
2016-02-10 15:27 UTC, Konstantin Belousov
no flags Details | Diff
Updated fix (7.61 KB, patch)
2016-02-11 16:07 UTC, Konstantin Belousov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ting-Wei Lan 2016-02-10 14:35:09 UTC
According to POSIX standard (
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html), including signal.h should define the mcontext_t and the ucontext_t type.

However, this doesn't work on FreeBSD. Compiling this simple program:
#include <signal.h>
int main (int argc, char *argv[]) { ucontext_t u; }

causes this error to be showed:
<filename.c>:2:37: error: use of undeclared identifier 'ucontext_t'


This problem also causes the current WebKit trunk build to fail. Can this problem be fixed, so we don't have to add a workaround for it in WebKit? I am using FreeBSD 10.3-BETA1.
Comment 1 Konstantin Belousov freebsd_committer 2016-02-10 15:27:46 UTC
Created attachment 166831 [details]
A fix

Split struct __ucontext into sys/_ucontext.h and use the header both in sys/ucontext.h and signal.h.
Comment 2 Konstantin Belousov freebsd_committer 2016-02-10 15:28:52 UTC
(In reply to Konstantin Belousov from comment #1)
Please try the attached patch, it is for HEAD, but might be applicable for stable/10.  I am somewhat sceptical that the patch could be included into 10.3 due to the stage of the releng process.
Comment 3 Ting-Wei Lan 2016-02-11 09:38:24 UTC
'make buildworld' fails:

===> usr.bin/xlint/llib (all)
lint -cghapbx -Cposix <freebsd_source>/usr.bin/xlint/llib/llib-lposix
llib-lposix:
warning: unknown warning option '-Wtraditional' [-Wunknown-warning-option]
1 warning generated.
...
_ucontext.h(44): syntax error [249]
_ucontext.h(47): syntax error [249]
...
*** Error code 1

Stop.
make[5]: stopped in <freebsd_source>/usr.bin/xlint/llib
Comment 4 Konstantin Belousov freebsd_committer 2016-02-11 16:07:16 UTC
Created attachment 166868 [details]
Updated fix

Yes, there were issues with lint libs and with some architectures.

Replaced patch should be in better shape, but I did not run make universe with it yet. x86 arches built.
Comment 5 Ting-Wei Lan 2016-02-12 06:01:25 UTC
The new patch works on 10.3 after manually resolving rejected hunks.
Comment 6 commit-hook freebsd_committer 2016-02-12 07:38:37 UTC
A commit references this bug:

Author: kib
Date: Fri Feb 12 07:38:20 UTC 2016
New revision: 295561
URL: https://svnweb.freebsd.org/changeset/base/295561

Log:
  POSIX states that #include <signal.h> shall make both mcontext_t and
  ucontext_t available.  Our code even has XXX comment about this.

  Add a bit of compliance by moving struct __ucontext definition into
  sys/_ucontext.h and including it into signal.h and sys/ucontext.h.

  Several machine/ucontext.h headers were changed to use namespace-safe
  types (like uint64_t->__uint64_t) to not depend on sys/types.h.
  struct __stack_t from sys/signal.h is made always visible in private
  namespace to satisfy sys/_ucontext.h requirements.

  Apparently mips _types.h pollutes global namespace with f_register_t
  type definition.  This commit does not try to fix the issue.

  PR:	207079
  Reported and tested by:	Ting-Wei Lan <lantw44@gmail.com>
  Sponsored by:	The FreeBSD Foundation
  MFC after:	2 weeks

Changes:
  head/include/signal.h
  head/sys/mips/include/ucontext.h
  head/sys/powerpc/include/ucontext.h
  head/sys/sparc64/include/ucontext.h
  head/sys/sys/_ucontext.h
  head/sys/sys/signal.h
  head/sys/sys/ucontext.h
  head/sys/x86/include/ucontext.h
Comment 7 Andriy Voskoboinyk freebsd_committer 2019-02-22 00:09:58 UTC
Looks like the issue was resolved ~3 years ago and both ucontext_t and mcontext_t are defined in <signal.h> on 11-STABLE / 12-STABLE / 13-CURRENT branches, so the PR can be closed now.