1 /* Bug 18125: Verify setcontext calls exit() and not _exit().
2 Copyright (C) 2015-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
27 #include <sys/types.h>
31 /* Please note that depending on the outcome of Bug 18135 this test
32 may become invalid, and instead of testing for calling exit it
33 should be reworked to test for the last context calling
36 static ucontext_t ctx
;
37 static char *filename
;
39 /* It is intended that this function does nothing. */
43 printf ("called context function\n");
51 const char buf
[] = "Called exit function\n";
53 fd
= open (filename
, O_WRONLY
| O_CREAT
, S_IRUSR
| S_IWUSR
);
56 printf ("FAIL: Unable to create test file %s\n", filename
);
59 res
= write (fd
, buf
, sizeof (buf
));
60 if (res
!= sizeof (buf
))
62 printf ("FAIL: Expected to write test file in one write call.\n");
68 printf ("FAIL: Failed to close test file.\n");
71 printf ("PASS: %s", buf
);
74 /* The test expects a filename given by the wrapper calling script.
75 The test then registers an atexit handler that will create the
76 file to indicate that the atexit handler ran. Then the test
77 creates a context, modifies it with makecontext, and sets it.
78 The context has only a single context which then must exit.
79 If it incorrectly exits via _exit then the atexit handler is
80 not run, the file is not created, and the wrapper detects this
81 and fails the test. This test cannot be done using an _exit
82 interposer since setcontext avoids the PLT and calls _exit
85 do_test (int argc
, char **argv
)
89 ucontext_t tempctx
= ctx
;
93 printf ("FAIL: Test missing filename argument.\n");
101 puts ("making contexts");
102 if (getcontext (&ctx
) != 0)
106 /* Exit with 77 to mark the test as UNSUPPORTED. */
107 printf ("UNSUPPORTED: getcontext not implemented.\n");
111 printf ("FAIL: getcontext failed.\n");
115 ctx
.uc_stack
.ss_sp
= st1
;
116 ctx
.uc_stack
.ss_size
= sizeof (st1
);
118 makecontext (&ctx
, cf
, 0);
120 /* Without this check, a stub makecontext can make us spin forever. */
121 if (memcmp (&tempctx
, &ctx
, sizeof ctx
) == 0)
123 puts ("UNSUPPORTED: makecontext was a no-op, presuming not implemented");
127 ret
= setcontext (&ctx
);
130 printf ("FAIL: setcontext returned with %d and errno of %d.\n", ret
, errno
);
134 printf ("FAIL: Impossibly returned to main.\n");
138 #include "../test-skeleton.c"