Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the type `stack_t` no longer defined on linux?

Tags:

c

linux

ucontext

The linux platform is Ubuntu 12.04

I have the following headers included in my source code:

#include <unistd.h>
#include <signal.h>
#include <ucontext.h>

...

When I compile it however, it complains /usr/include/x86_64-linux-gnu/sys/ucontext.h:139:5: error: unknown type name 'stack_t'

I googled and found that stack_t should be defined in signal.h, but here it doesn't seem to be defined?

like image 844
Jimmy Lu Avatar asked Dec 11 '22 08:12

Jimmy Lu


2 Answers

This is meant to be a comment but I cannot make it readable there. Sorry.

Did you #define one of the following:

 _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
           _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
           || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
like image 57
jim mcnamara Avatar answered Dec 26 '22 19:12

jim mcnamara


According to SUS v2 (1997), stack_t should be defined in <signal.h> - http://pubs.opengroup.org/onlinepubs/7908799/xsh/ucontext.h.html

The types sigset_t and stack_t are defined as in .

http://pubs.opengroup.org/onlinepubs/007908799/xsh/signal.h.html

The header defines the stack_t type as a structure that includes at least the following members:

void     *ss_sp       stack base or pointer
size_t    ss_size     stack size
int       ss_flags    flags

The type is also listed in glibc documentation: http://www.gnu.org/software/libc/manual/html_node/Signal-Stack.html

Data Type: stack_t

This type is used in sigaltstack function, described as:

sigaltstack is the newer interface, and comes from 4.4 BSD. ...

And the official Linux man page for sigaltstack (version 2015-07-23) says: http://man7.org/linux/man-pages/man2/sigaltstack.2.html

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

   sigaltstack():
       _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
       _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
       || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L

CONFORMING TO POSIX.1-2001, POSIX.1-2009, SUSv2, SVr4.

So, when you use glibc newer than 2.12, you must define some of macro to be able to use sigaltstack and stack_t. Since glibc 2.10 you can just define #define _GNU_SOURCE to enable _BSD_SOURCE and _POSIX_C_SOURCE = 200809L

like image 22
osgx Avatar answered Dec 26 '22 19:12

osgx