From 2978e725960f6bb66e83906679b677571e1246ff Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Thu, 19 Mar 2009 13:04:28 +0000 Subject: [PATCH] Use _beginthreadex if available. git-svn-id: file:///svn/unbound/trunk@1537 be551aaa-1e26-0410-a405-d3ace91eadb9 --- config.h.in | 3 +++ configure | 3 ++- configure.ac | 2 +- doc/Changelog | 1 + util/locks.c | 5 +++++ 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/config.h.in b/config.h.in index 11f1c3af6..95f7acfd4 100644 --- a/config.h.in +++ b/config.h.in @@ -299,6 +299,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_WS2TCPIP_H +/* Define to 1 if you have the `_beginthreadex' function. */ +#undef HAVE__BEGINTHREADEX + /* Define to the maximum message length to pass to syslog. */ #undef MAXSYSLOGMSGLEN diff --git a/configure b/configure index 53c92ffec..2d468ea48 100755 --- a/configure +++ b/configure @@ -24308,7 +24308,8 @@ fi -for ac_func in tzset sigprocmask fcntl getpwnam getrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev setresuid setreuid setresgid setregid glob initgroups daemon strftime localtime_r setusercontext + +for ac_func in tzset sigprocmask fcntl getpwnam getrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev setresuid setreuid setresgid setregid glob initgroups daemon strftime localtime_r setusercontext _beginthreadex do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 diff --git a/configure.ac b/configure.ac index 2a2e156c2..2b4de86dc 100644 --- a/configure.ac +++ b/configure.ac @@ -869,7 +869,7 @@ if test $ac_cv_func_getaddrinfo = no; then AC_LIBOBJ([fake-rfc2553]) fi AC_SEARCH_LIBS([setusercontext], [util]) -AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam getrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev setresuid setreuid setresgid setregid glob initgroups daemon strftime localtime_r setusercontext]) +AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam getrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev setresuid setreuid setresgid setregid glob initgroups daemon strftime localtime_r setusercontext _beginthreadex]) # check if setreuid en setregid fail, on MacOSX10.4(darwin8). if echo $build_os | grep darwin8 > /dev/null; then diff --git a/doc/Changelog b/doc/Changelog index 8854855b7..d6de1e95e 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,6 +1,7 @@ 19 March 2009: Wouter - winrc/README.txt dos-format text file. - iana portlist updated. + - use _beginthreadex() when available (performs stack alignment). 18 March 2009: Wouter - Added tests, unknown algorithms become insecure. fallback works. diff --git a/util/locks.c b/util/locks.c index dec7a1e6e..3f58e92d0 100644 --- a/util/locks.c +++ b/util/locks.c @@ -230,11 +230,16 @@ void* ub_thread_key_get(ub_thread_key_t key) void ub_thread_create(ub_thread_t* thr, void* (*func)(void*), void* arg) { +#ifndef HAVE__BEGINTHREADEX *thr = CreateThread(NULL, /* default security (no inherit handle) */ 0, /* default stack size */ (LPTHREAD_START_ROUTINE)func, arg, 0, /* default flags, run immediately */ NULL); /* do not store thread identifier anywhere */ +#else + /* the begintheadex routine setups for the C lib; aligns stack */ + *thr=(ub_thread_t)_beginthreadex(NULL, 0, (void*)func, arg, 0, NULL); +#endif if(*thr == NULL) { log_win_err("CreateThread failed", GetLastError()); fatal_exit("thread create failed"); -- 2.47.3