82 |
|
dnl If POSIX.4 semaphores are not available, we emulate them with pthread mutexes. |
83 |
|
SEMSRC= |
84 |
|
AC_CHECK_FUNCS(sem_init, , [ |
85 |
< |
if [[ "x$HAVE_PTHREADS" = "xyes" ]]; then |
85 |
> |
if test "x$HAVE_PTHREADS" = "xyes"; then |
86 |
|
SEMSRC=posix_sem.cpp |
87 |
|
fi |
88 |
|
]) |
140 |
|
dnl Checks for header files. |
141 |
|
AC_HEADER_STDC |
142 |
|
AC_HEADER_SYS_WAIT |
143 |
< |
AC_CHECK_HEADERS(unistd.h fcntl.h sys/time.h) |
143 |
> |
AC_CHECK_HEADERS(unistd.h fcntl.h sys/time.h sys/mman.h) |
144 |
|
|
145 |
|
dnl Checks for typedefs, structures, and compiler characteristics. |
146 |
|
AC_C_BIGENDIAN |
150 |
|
AC_CHECK_SIZEOF(int, 4) |
151 |
|
AC_CHECK_SIZEOF(long, 4) |
152 |
|
AC_CHECK_SIZEOF(long long, 8) |
153 |
+ |
AC_CHECK_SIZEOF(float, 4) |
154 |
+ |
AC_CHECK_SIZEOF(double, 8) |
155 |
|
AC_CHECK_SIZEOF(void *, 4) |
156 |
|
AC_TYPE_OFF_T |
157 |
|
AC_CHECK_TYPE(loff_t, off_t) |
158 |
|
AC_TYPE_SIZE_T |
159 |
+ |
AC_TYPE_SIGNAL |
160 |
|
AC_HEADER_TIME |
161 |
|
AC_STRUCT_TM |
162 |
|
|
163 |
|
dnl Checks for library functions. |
164 |
|
AC_CHECK_FUNCS(strdup cfmakeraw) |
165 |
|
AC_CHECK_FUNCS(nanosleep clock_gettime timer_create) |
166 |
+ |
AC_CHECK_FUNCS(sigaction signal) |
167 |
+ |
AC_CHECK_FUNCS(mmap mprotect munmap) |
168 |
+ |
AC_CHECK_FUNCS(vm_allocate vm_deallocate vm_protect) |
169 |
|
|
170 |
|
dnl Select system-dependant sources. |
171 |
|
if [[ "x$HAVE_PPC" = "xyes" ]]; then |
175 |
|
fi |
176 |
|
SYSSRCS="$SYSSRCS $SEMSRCS $UISRCS $MONSRCS" |
177 |
|
|
178 |
+ |
dnl Define a macro that translates a yesno-variable into a C macro definition |
179 |
+ |
dnl to be put into the config.h file |
180 |
+ |
dnl $1 -- the macro to define |
181 |
+ |
dnl $2 -- the value to translate |
182 |
+ |
dnl $3 -- template name |
183 |
+ |
AC_DEFUN(AC_TRANSLATE_DEFINE, [ |
184 |
+ |
if [[ "x$2" = "xyes" -o "x$2" = "xguessing yes" ]]; then |
185 |
+ |
AC_DEFINE($1, 1, $3) |
186 |
+ |
fi |
187 |
+ |
]) |
188 |
+ |
|
189 |
+ |
dnl Various checks if the system supports vm_allocate() and the like functions. |
190 |
+ |
have_mach_vm=no |
191 |
+ |
if [[ "x$ac_cv_func_vm_allocate" = "xyes" -a "x$ac_cv_func_vm_deallocate" = "xyes" -a \ |
192 |
+ |
"x$ac_cv_func_vm_protect" = "xyes" ]]; then |
193 |
+ |
have_mach_vm=yes |
194 |
+ |
fi |
195 |
+ |
AC_TRANSLATE_DEFINE(HAVE_MACH_VM, "$have_mach_vm", |
196 |
+ |
[Define if your system has a working vm_allocate()-based memory allocator.]) |
197 |
+ |
|
198 |
+ |
dnl Check that vm_allocate(), vm_protect() work |
199 |
+ |
if [[ "x$have_mach_vm" = "xyes" ]]; then |
200 |
+ |
|
201 |
+ |
AC_CACHE_CHECK([whether vm_protect works], |
202 |
+ |
ac_cv_vm_protect_works, [ |
203 |
+ |
AC_LANG_SAVE |
204 |
+ |
AC_LANG_CPLUSPLUS |
205 |
+ |
ac_cv_vm_protect_works=yes |
206 |
+ |
dnl First the tests that should segfault |
207 |
+ |
for test_def in NONE_READ NONE_WRITE READ_WRITE; do |
208 |
+ |
AC_TRY_RUN([ |
209 |
+ |
#define CONFIGURE_TEST_VM_MAP |
210 |
+ |
#define TEST_VM_PROT_$test_def |
211 |
+ |
#include "vm_alloc.cpp" |
212 |
+ |
], ac_cv_vm_protect_works=no, rm -f core, |
213 |
+ |
dnl When cross-compiling, do not assume anything |
214 |
+ |
ac_cv_vm_protect_works="guessing no" |
215 |
+ |
) |
216 |
+ |
done |
217 |
+ |
AC_TRY_RUN([ |
218 |
+ |
#define CONFIGURE_TEST_VM_MAP |
219 |
+ |
#define TEST_VM_PROT_RDWR_WRITE |
220 |
+ |
#include "vm_alloc.cpp" |
221 |
+ |
], , ac_cv_vm_protect_works=no, |
222 |
+ |
dnl When cross-compiling, do not assume anything |
223 |
+ |
ac_cv_vm_protect_works="guessing no" |
224 |
+ |
) |
225 |
+ |
AC_LANG_RESTORE |
226 |
+ |
] |
227 |
+ |
) |
228 |
+ |
|
229 |
+ |
dnl Remove support for vm_allocate() if vm_protect() does not work |
230 |
+ |
if [[ "x$have_mach_vm" = "xyes" ]]; then |
231 |
+ |
case $ac_cv_vm_protect_works in |
232 |
+ |
*yes) have_mach_vm=yes;; |
233 |
+ |
*no) have_mach_vm=no;; |
234 |
+ |
esac |
235 |
+ |
fi |
236 |
+ |
AC_TRANSLATE_DEFINE(HAVE_MACH_VM, "$have_mach_vm", |
237 |
+ |
[Define if your system has a working vm_allocate()-based memory allocator.]) |
238 |
+ |
|
239 |
+ |
fi dnl HAVE_MACH_VM |
240 |
+ |
|
241 |
+ |
dnl Various checks if the system supports mmap() and the like functions. |
242 |
+ |
dnl ... and Mach memory allocators are not supported |
243 |
+ |
have_mmap_vm=no |
244 |
+ |
if [[ "x$ac_cv_func_mmap" = "xyes" -a "x$ac_cv_func_munmap" = "xyes" -a \ |
245 |
+ |
"x$ac_cv_func_mprotect" = "xyes" ]]; then |
246 |
+ |
if [[ "x$have_mach_vm" = "xno" ]]; then |
247 |
+ |
have_mmap_vm=yes |
248 |
+ |
fi |
249 |
+ |
fi |
250 |
+ |
AC_TRANSLATE_DEFINE(HAVE_MMAP_VM, "$have_mmap_vm", |
251 |
+ |
[Define if your system has a working mmap()-based memory allocator.]) |
252 |
+ |
|
253 |
+ |
dnl Check that mmap() and associated functions work. |
254 |
+ |
if [[ "x$have_mmap_vm" = "xyes" ]]; then |
255 |
+ |
|
256 |
+ |
dnl Check if we have a working anonymous mmap() |
257 |
+ |
AC_CACHE_CHECK([whether mmap supports MAP_ANON], |
258 |
+ |
ac_cv_mmap_anon, [ |
259 |
+ |
AC_LANG_SAVE |
260 |
+ |
AC_LANG_CPLUSPLUS |
261 |
+ |
AC_TRY_RUN([ |
262 |
+ |
#define HAVE_MMAP_ANON |
263 |
+ |
#define CONFIGURE_TEST_VM_MAP |
264 |
+ |
#define TEST_VM_MMAP_ANON |
265 |
+ |
#include "vm_alloc.cpp" |
266 |
+ |
], ac_cv_mmap_anon=yes, ac_cv_mmap_anon=no, |
267 |
+ |
dnl When cross-compiling, do not assume anything. |
268 |
+ |
ac_cv_mmap_anon="guessing no" |
269 |
+ |
) |
270 |
+ |
AC_LANG_RESTORE |
271 |
+ |
] |
272 |
+ |
) |
273 |
+ |
AC_TRANSLATE_DEFINE(HAVE_MMAP_ANON, "$ac_cv_mmap_anon", |
274 |
+ |
[Define if <sys/mman.h> defines MAP_ANON and mmap()'ing with MAP_ANON works.]) |
275 |
+ |
|
276 |
+ |
AC_CACHE_CHECK([whether mmap supports MAP_ANONYMOUS], |
277 |
+ |
ac_cv_mmap_anonymous, [ |
278 |
+ |
AC_LANG_SAVE |
279 |
+ |
AC_LANG_CPLUSPLUS |
280 |
+ |
AC_TRY_RUN([ |
281 |
+ |
#define HAVE_MMAP_ANONYMOUS |
282 |
+ |
#define CONFIGURE_TEST_VM_MAP |
283 |
+ |
#define TEST_VM_MMAP_ANON |
284 |
+ |
#include "vm_alloc.cpp" |
285 |
+ |
], ac_cv_mmap_anonymous=yes, ac_cv_mmap_anonymous=no, |
286 |
+ |
dnl When cross-compiling, do not assume anything. |
287 |
+ |
ac_cv_mmap_anonymous="guessing no" |
288 |
+ |
) |
289 |
+ |
AC_LANG_RESTORE |
290 |
+ |
] |
291 |
+ |
) |
292 |
+ |
AC_TRANSLATE_DEFINE(HAVE_MMAP_ANONYMOUS, "$ac_cv_mmap_anonymous", |
293 |
+ |
[Define if <sys/mman.h> defines MAP_ANONYMOUS and mmap()'ing with MAP_ANONYMOUS works.]) |
294 |
+ |
|
295 |
+ |
AC_CACHE_CHECK([whether mprotect works], |
296 |
+ |
ac_cv_mprotect_works, [ |
297 |
+ |
AC_LANG_SAVE |
298 |
+ |
AC_LANG_CPLUSPLUS |
299 |
+ |
ac_cv_mprotect_works=yes |
300 |
+ |
dnl First the tests that should segfault |
301 |
+ |
for test_def in NONE_READ NONE_WRITE READ_WRITE; do |
302 |
+ |
AC_TRY_RUN([ |
303 |
+ |
#define CONFIGURE_TEST_VM_MAP |
304 |
+ |
#define TEST_VM_PROT_$test_def |
305 |
+ |
#include "vm_alloc.cpp" |
306 |
+ |
], ac_cv_mprotect_works=no, rm -f core, |
307 |
+ |
dnl When cross-compiling, do not assume anything |
308 |
+ |
ac_cv_mprotect_works="guessing no" |
309 |
+ |
) |
310 |
+ |
done |
311 |
+ |
AC_TRY_RUN([ |
312 |
+ |
#define CONFIGURE_TEST_VM_MAP |
313 |
+ |
#define TEST_VM_PROT_RDWR_WRITE |
314 |
+ |
#include "vm_alloc.cpp" |
315 |
+ |
], , ac_cv_mprotect_works=no, |
316 |
+ |
dnl When cross-compiling, do not assume anything |
317 |
+ |
ac_cv_mprotect_works="guessing no" |
318 |
+ |
) |
319 |
+ |
AC_LANG_RESTORE |
320 |
+ |
] |
321 |
+ |
) |
322 |
+ |
|
323 |
+ |
dnl Remove support for mmap() if mprotect() does not work |
324 |
+ |
if [[ "x$have_mmap_vm" = "xyes" ]]; then |
325 |
+ |
case $ac_cv_mprotect_works in |
326 |
+ |
*yes) have_mmap_vm=yes;; |
327 |
+ |
*no) have_mmap_vm=no;; |
328 |
+ |
esac |
329 |
+ |
fi |
330 |
+ |
AC_TRANSLATE_DEFINE(HAVE_MMAP_VM, $have_mmap_vm, |
331 |
+ |
[Define if your system has a working mmap()-based memory allocator.]) |
332 |
+ |
|
333 |
+ |
fi dnl HAVE_MMAP_VM |
334 |
+ |
|
335 |
+ |
dnl Check if we can mmap 0x2000 bytes from 0x0000 |
336 |
+ |
AC_CACHE_CHECK([whether we can map Low Memory area 0x0000-0x2000], |
337 |
+ |
ac_cv_can_map_lm, [ |
338 |
+ |
AC_LANG_SAVE |
339 |
+ |
AC_LANG_CPLUSPLUS |
340 |
+ |
AC_TRY_RUN([ |
341 |
+ |
#include "vm_alloc.cpp" |
342 |
+ |
int main(void) { /* returns 0 if we could map the lowmem globals */ |
343 |
+ |
volatile char * lm = 0; |
344 |
+ |
if (vm_init() < 0) exit(1); |
345 |
+ |
if (vm_acquire_fixed(0, 0x2000) < 0) exit(1); |
346 |
+ |
lm[0] = 'z'; |
347 |
+ |
if (vm_release((char *)lm, 0x2000) < 0) exit(1); |
348 |
+ |
vm_exit(); exit(0); |
349 |
+ |
} |
350 |
+ |
], ac_cv_can_map_lm=yes, ac_cv_can_map_lm=no, |
351 |
+ |
dnl When cross-compiling, do not assume anything. |
352 |
+ |
ac_cv_can_map_lm="guessing no" |
353 |
+ |
) |
354 |
+ |
AC_LANG_RESTORE |
355 |
+ |
] |
356 |
+ |
) |
357 |
+ |
|
358 |
+ |
dnl Check signal handlers need to be reinstalled |
359 |
+ |
AC_CACHE_CHECK([whether signal handlers need to be reinstalled], |
360 |
+ |
ac_cv_signal_need_reinstall, [ |
361 |
+ |
AC_LANG_SAVE |
362 |
+ |
AC_LANG_CPLUSPLUS |
363 |
+ |
AC_TRY_RUN([ |
364 |
+ |
#include <stdlib.h> |
365 |
+ |
#ifdef HAVE_UNISTD_H |
366 |
+ |
#include <unistd.h> |
367 |
+ |
#endif |
368 |
+ |
#include <signal.h> |
369 |
+ |
static int handled_signal = 0; |
370 |
+ |
RETSIGTYPE sigusr1_handler(int) { handled_signal++; } |
371 |
+ |
int main(void) { /* returns 0 if signals need not to be reinstalled */ |
372 |
+ |
signal(SIGUSR1, sigusr1_handler); raise(SIGUSR1); raise(SIGUSR1); |
373 |
+ |
exit(handled_signal == 2); |
374 |
+ |
} |
375 |
+ |
], ac_cv_signal_need_reinstall=yes, ac_cv_signal_need_reinstall=no, |
376 |
+ |
dnl When cross-compiling, do not assume anything. |
377 |
+ |
ac_cv_signal_need_reinstall="guessing yes" |
378 |
+ |
) |
379 |
+ |
AC_LANG_RESTORE |
380 |
+ |
] |
381 |
+ |
) |
382 |
+ |
AC_TRANSLATE_DEFINE(SIGNAL_NEED_REINSTALL, "$ac_cv_signal_need_reinstall", |
383 |
+ |
[Define if your system requires signals to be reinstalled.]) |
384 |
+ |
|
385 |
+ |
dnl Check if sigaction handlers need to be reinstalled |
386 |
+ |
AC_CACHE_CHECK([whether sigaction handlers need to be reinstalled], |
387 |
+ |
ac_cv_sigaction_need_reinstall, [ |
388 |
+ |
AC_LANG_SAVE |
389 |
+ |
AC_LANG_CPLUSPLUS |
390 |
+ |
AC_TRY_RUN([ |
391 |
+ |
#include <stdlib.h> |
392 |
+ |
#ifdef HAVE_UNISTD_H |
393 |
+ |
#include <unistd.h> |
394 |
+ |
#endif |
395 |
+ |
#include <signal.h> |
396 |
+ |
static int handled_signal = 0; |
397 |
+ |
RETSIGTYPE sigusr1_handler(int) { handled_signal++; } |
398 |
+ |
typedef RETSIGTYPE (*signal_handler)(int); |
399 |
+ |
static signal_handler mysignal(int sig, signal_handler handler) { |
400 |
+ |
struct sigaction old_sa; |
401 |
+ |
struct sigaction new_sa; |
402 |
+ |
new_sa.sa_handler = handler; |
403 |
+ |
return ((sigaction(sig,&new_sa,&old_sa) < 0) ? SIG_IGN : old_sa.sa_handler); |
404 |
+ |
} |
405 |
+ |
int main(void) { /* returns 0 if signals need not to be reinstalled */ |
406 |
+ |
mysignal(SIGUSR1, sigusr1_handler); raise(SIGUSR1); raise(SIGUSR1); |
407 |
+ |
exit(handled_signal == 2); |
408 |
+ |
} |
409 |
+ |
], ac_cv_sigaction_need_reinstall=yes, ac_cv_sigaction_need_reinstall=no, |
410 |
+ |
dnl When cross-compiling, do not assume anything. |
411 |
+ |
ac_cv_sigaction_need_reinstall="guessing yes" |
412 |
+ |
) |
413 |
+ |
AC_LANG_RESTORE |
414 |
+ |
] |
415 |
+ |
) |
416 |
+ |
AC_TRANSLATE_DEFINE(SIGACTION_NEED_REINSTALL, "$ac_cv_sigaction_need_reinstall", |
417 |
+ |
[Define if your system requires sigactions to be reinstalled.]) |
418 |
+ |
|
419 |
+ |
dnl Check if extended signals are supported. |
420 |
+ |
AC_CACHE_CHECK([whether your system supports extended signal handlers], |
421 |
+ |
ac_cv_have_extended_signals, [ |
422 |
+ |
AC_LANG_SAVE |
423 |
+ |
AC_LANG_CPLUSPLUS |
424 |
+ |
AC_TRY_RUN([ |
425 |
+ |
#define HAVE_SIGINFO_T 1 |
426 |
+ |
#define CONFIGURE_TEST_SIGSEGV_RECOVERY |
427 |
+ |
#include "vm_alloc.cpp" |
428 |
+ |
#include "sigsegv.cpp" |
429 |
+ |
], ac_cv_have_extended_signals=yes, ac_cv_have_extended_signals=no, |
430 |
+ |
dnl When cross-compiling, do not assume anything. |
431 |
+ |
ac_cv_have_extended_signals=no |
432 |
+ |
) |
433 |
+ |
AC_LANG_RESTORE |
434 |
+ |
] |
435 |
+ |
) |
436 |
+ |
AC_TRANSLATE_DEFINE(HAVE_SIGINFO_T, "$ac_cv_have_extended_signals", |
437 |
+ |
[Define if your system support extended signals.]) |
438 |
+ |
|
439 |
+ |
dnl Otherwise, check for subterfuges. |
440 |
+ |
if [[ "x$ac_cv_have_extended_signals" = "xno" ]]; then |
441 |
+ |
AC_CACHE_CHECK([whether we then have a subterfuge for your system], |
442 |
+ |
ac_cv_have_sigcontext_hack, [ |
443 |
+ |
AC_LANG_SAVE |
444 |
+ |
AC_LANG_CPLUSPLUS |
445 |
+ |
AC_TRY_RUN([ |
446 |
+ |
#define HAVE_SIGCONTEXT_SUBTERFUGE 1 |
447 |
+ |
#define CONFIGURE_TEST_SIGSEGV_RECOVERY |
448 |
+ |
#include "vm_alloc.cpp" |
449 |
+ |
#include "sigsegv.cpp" |
450 |
+ |
], ac_cv_have_sigcontext_hack=yes, ac_cv_have_sigcontext_hack=no, |
451 |
+ |
dnl When cross-compiling, do not assume anything. |
452 |
+ |
ac_cv_have_sigcontext_hack=no |
453 |
+ |
) |
454 |
+ |
AC_LANG_RESTORE |
455 |
+ |
]) |
456 |
+ |
AC_TRANSLATE_DEFINE(HAVE_SIGCONTEXT_SUBTERFUGE, "$ac_cv_have_sigcontext_hack", |
457 |
+ |
[Define if we know a hack to replace siginfo_t->si_addr member.]) |
458 |
+ |
fi |
459 |
+ |
|
460 |
+ |
dnl Check if we can ignore the fault (instruction skipping in SIGSEGV handler) |
461 |
+ |
AC_CACHE_CHECK([whether we can skip instruction in SIGSEGV handler], |
462 |
+ |
ac_cv_have_skip_instruction, [ |
463 |
+ |
AC_LANG_SAVE |
464 |
+ |
AC_LANG_CPLUSPLUS |
465 |
+ |
AC_TRY_RUN([ |
466 |
+ |
#define HAVE_SIGSEGV_SKIP_INSTRUCTION 1 |
467 |
+ |
#define CONFIGURE_TEST_SIGSEGV_RECOVERY |
468 |
+ |
#include "vm_alloc.cpp" |
469 |
+ |
#include "sigsegv.cpp" |
470 |
+ |
], ac_cv_have_skip_instruction=yes, ac_cv_have_skip_instruction=no, |
471 |
+ |
dnl When cross-compiling, do not assume anything. |
472 |
+ |
ac_cv_have_skip_instruction=no |
473 |
+ |
) |
474 |
+ |
AC_LANG_RESTORE |
475 |
+ |
] |
476 |
+ |
) |
477 |
+ |
AC_TRANSLATE_DEFINE(HAVE_SIGSEGV_SKIP_INSTRUCTION, "$ac_cv_have_skip_instruction", |
478 |
+ |
[Define if we can ignore the fault (instruction skipping in SIGSEGV handler).]) |
479 |
+ |
|
480 |
|
dnl Generate Makefile. |
481 |
|
AC_SUBST(SYSSRCS) |
482 |
|
AC_OUTPUT(Makefile) |