diff options
| author | Eli Zaretskii | 2017-10-14 11:13:47 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2017-10-14 11:13:47 +0300 |
| commit | aa0c38f3586d462c7b4d489542b32580f489fdc5 (patch) | |
| tree | 1838179ddc22be065247fe00d1c2cb5e922d097c /src | |
| parent | d7038020aa0a868c74cddaed5733ad6eeb73406b (diff) | |
| download | emacs-aa0c38f3586d462c7b4d489542b32580f489fdc5.tar.gz emacs-aa0c38f3586d462c7b4d489542b32580f489fdc5.zip | |
Make sure thread stack is properly aligned on MS-Windows
* src/systhread.c: Include w32term.h instead of windows.h.
(w32_beginthread_wrapper): Add ALIGN_STACK attribute, to ensure
the thread's stack is correctly aligned.
* src/w32term.h (ALIGN_STACK): Update commentary.
Diffstat (limited to 'src')
| -rw-r--r-- | src/systhread.c | 7 | ||||
| -rw-r--r-- | src/w32term.h | 15 |
2 files changed, 12 insertions, 10 deletions
diff --git a/src/systhread.c b/src/systhread.c index ee89a1ed3ff..6f9baabaf2e 100644 --- a/src/systhread.c +++ b/src/systhread.c | |||
| @@ -187,7 +187,7 @@ sys_thread_yield (void) | |||
| 187 | 187 | ||
| 188 | #elif defined (WINDOWSNT) | 188 | #elif defined (WINDOWSNT) |
| 189 | 189 | ||
| 190 | #include <windows.h> | 190 | #include <w32term.h> |
| 191 | 191 | ||
| 192 | /* Cannot include <process.h> because of the local header by the same | 192 | /* Cannot include <process.h> because of the local header by the same |
| 193 | name, sigh. */ | 193 | name, sigh. */ |
| @@ -326,8 +326,9 @@ sys_thread_self (void) | |||
| 326 | static thread_creation_function *thread_start_address; | 326 | static thread_creation_function *thread_start_address; |
| 327 | 327 | ||
| 328 | /* _beginthread wants a void function, while we are passed a function | 328 | /* _beginthread wants a void function, while we are passed a function |
| 329 | that returns a pointer. So we use a wrapper. */ | 329 | that returns a pointer. So we use a wrapper. See the command in |
| 330 | static void | 330 | w32term.h about the need for ALIGN_STACK attribute. */ |
| 331 | static void ALIGN_STACK | ||
| 331 | w32_beginthread_wrapper (void *arg) | 332 | w32_beginthread_wrapper (void *arg) |
| 332 | { | 333 | { |
| 333 | (void)thread_start_address (arg); | 334 | (void)thread_start_address (arg); |
diff --git a/src/w32term.h b/src/w32term.h index 16b44b0ca2f..8d08ca0a2bf 100644 --- a/src/w32term.h +++ b/src/w32term.h | |||
| @@ -22,13 +22,14 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 22 | #include "frame.h" | 22 | #include "frame.h" |
| 23 | #include "atimer.h" | 23 | #include "atimer.h" |
| 24 | 24 | ||
| 25 | /* Stack alignment stuff. Every CALLBACK function should have the | 25 | /* Stack alignment stuff. Every CALLBACK and thread function should |
| 26 | ALIGN_STACK attribute if it manipulates Lisp objects, because | 26 | have the ALIGN_STACK attribute if it manipulates Lisp objects, |
| 27 | Windows x86 32-bit ABI only guarantees 4-byte stack alignment, and | 27 | because Windows x86 32-bit ABI only guarantees 4-byte stack |
| 28 | that is what we will get when a Windows function calls us. The | 28 | alignment, and that is what we will get when a Windows function |
| 29 | ALIGN_STACK attribute forces GCC to emit a preamble code to | 29 | calls us. The ALIGN_STACK attribute forces GCC to emit a preamble |
| 30 | re-align the stack at function entry. Further details about this | 30 | code to re-align the stack at function entry. Further details |
| 31 | can be found in http://www.peterstock.co.uk/games/mingw_sse/. */ | 31 | about this can be found in |
| 32 | http://www.peterstock.co.uk/games/mingw_sse/. */ | ||
| 32 | #ifdef __GNUC__ | 33 | #ifdef __GNUC__ |
| 33 | # if USE_STACK_LISP_OBJECTS && !defined _WIN64 && !defined __x86_64__ \ | 34 | # if USE_STACK_LISP_OBJECTS && !defined _WIN64 && !defined __x86_64__ \ |
| 34 | && __GNUC__ + (__GNUC_MINOR__ > 1) >= 5 | 35 | && __GNUC__ + (__GNUC_MINOR__ > 1) >= 5 |