xref: /openbsd-src/regress/sys/kern/stackpivot/syscall/stackpivot.c (revision 802163a16b27f525fc2afe5dae956e57fc08dbe6)
1897fc685Smortimer /*
2897fc685Smortimer  * Copyright (c) 2018 Todd Mortimer <mortimer@openbsd.org>
3897fc685Smortimer  *
4897fc685Smortimer  * Permission to use, copy, modify, and distribute this software for any
5897fc685Smortimer  * purpose with or without fee is hereby granted, provided that the above
6897fc685Smortimer  * copyright notice and this permission notice appear in all copies.
7897fc685Smortimer  *
8897fc685Smortimer  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9897fc685Smortimer  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10897fc685Smortimer  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11897fc685Smortimer  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12897fc685Smortimer  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13897fc685Smortimer  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14897fc685Smortimer  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15897fc685Smortimer  */
16897fc685Smortimer 
17897fc685Smortimer #include <stdio.h>
18897fc685Smortimer #include <stdlib.h>
19505ee9eaSderaadt #include <unistd.h>
20897fc685Smortimer 
21897fc685Smortimer #include "../pivot.h"
22897fc685Smortimer 
doexit()23897fc685Smortimer void doexit() {
24505ee9eaSderaadt     _exit(0);
25897fc685Smortimer }
26897fc685Smortimer 
main()27897fc685Smortimer int main() {
28897fc685Smortimer     /* set up an alt stack on the heap that just calls doexit */
29897fc685Smortimer     size_t *newstack = calloc(10, sizeof(size_t));
30*802163a1Sderaadt     printf("non-MAP_STACK stack at %p\n", newstack);
31897fc685Smortimer     newstack[0] = (size_t)doexit;
32897fc685Smortimer     pivot(newstack);
33897fc685Smortimer     return 0;
34897fc685Smortimer }
35