From: Brian Norris Date: Thu, 4 Apr 2013 20:19:50 +0000 (-0700) Subject: context: move Mac swapcontext() to separate compilation unit X-Git-Tag: oopsla2013~102 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e9d2d6e08dcf6962aa7b2818389d9a6d451d7d14;p=model-checker.git context: move Mac swapcontext() to separate compilation unit We really don't want model_swapcontext() to ever be inlined on Mac OSX, since this could potentially cause subtle getcontext()-related bugs to resurface. Just make it a separate compilation unit (*.cc file). --- diff --git a/Makefile b/Makefile index b653e76..5120cce 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,8 @@ include common.mk OBJECTS = libthreads.o schedule.o model.o threads.o librace.o action.o \ nodestack.o clockvector.o main.o snapshot-interface.o cyclegraph.o \ datarace.o impatomic.o cmodelint.o \ - snapshot.o malloc.o mymemory.o common.o mutex.o promise.o conditionvariable.o + snapshot.o malloc.o mymemory.o common.o mutex.o promise.o conditionvariable.o \ + context.o CPPFLAGS += -Iinclude -I. LDFLAGS = -ldl -lrt -rdynamic diff --git a/context.cc b/context.cc new file mode 100644 index 0000000..b5ae0ba --- /dev/null +++ b/context.cc @@ -0,0 +1,27 @@ +#include "context.h" + +#ifdef MAC + +int model_swapcontext(ucontext_t *oucp, ucontext_t *ucp) +{ + /* + * Mac OSX swapcontext() clobbers some registers, so use a hand-rolled + * version with {get,set}context(). We can avoid the same problem + * (where optimizations can break the following code) because we don't + * statically link with the C library + */ + + /* volatile, so that 'i' doesn't get promoted to a register */ + volatile int i = 0; + + getcontext(oucp); + + if (i == 0) { + i = 1; + setcontext(ucp); + } + + return 0; +} + +#endif /* MAC */ diff --git a/context.h b/context.h index 862cda5..ea32d2f 100644 --- a/context.h +++ b/context.h @@ -8,30 +8,17 @@ #include -static inline int model_swapcontext(ucontext_t *oucp, ucontext_t *ucp) -{ #ifdef MAC - /* - * Mac OSX swapcontext() clobbers some registers, so use a hand-rolled - * version with {get,set}context(). We can avoid the same problem - * (where optimizations can break the following code) because we don't - * statically link with the C library - */ - - /* volatile, so that 'i' doesn't get promoted to a register */ - volatile int i = 0; - getcontext(oucp); +int model_swapcontext(ucontext_t *oucp, ucontext_t *ucp); - if (i == 0) { - i = 1; - setcontext(ucp); - } +#else /* !MAC */ - return 0; -#else +static inline int model_swapcontext(ucontext_t *oucp, ucontext_t *ucp) +{ return swapcontext(oucp, ucp); -#endif } +#endif /* !MAC */ + #endif /* __CONTEXT_H__ */