Work around changes in newer versions of glibc
[satcheck.git] / context.cc
1 /*      Copyright (c) 2015 Regents of the University of California
2  *
3  *      Author: Brian Demsky <bdemsky@uci.edu>
4  *
5  *      This program is free software; you can redistribute it and/or
6  *      modify it under the terms of the GNU General Public License
7  *      version 2 as published by the Free Software Foundation.
8  */
9
10 #include "context.h"
11
12 #ifdef MAC
13
14 int model_swapcontext(ucontext_t *oucp, ucontext_t *ucp)
15 {
16         /*
17          * Mac OSX swapcontext() clobbers some registers, so use a hand-rolled
18          * version with {get,set}context(). We can avoid the same problem
19          * (where optimizations can break the following code) because we don't
20          * statically link with the C library
21          */
22
23         /* volatile, so that 'i' doesn't get promoted to a register */
24         volatile int i = 0;
25
26         getcontext(oucp);
27
28         if (i == 0) {
29                 i = 1;
30                 setcontext(ucp);
31         }
32
33         return 0;
34 }
35
36 #endif /* MAC */