2003-08-30 00:23:42 +02:00
|
|
|
/*
|
|
|
|
* Wine portability routines
|
|
|
|
*
|
|
|
|
* Copyright 2000 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-08-30 00:23:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include "wine/library.h"
|
2003-10-10 02:22:19 +02:00
|
|
|
#include "wine/pthread.h"
|
2003-08-30 00:23:42 +02:00
|
|
|
|
2005-09-03 17:11:29 +02:00
|
|
|
static struct wine_pthread_functions pthread_functions;
|
2003-11-06 00:31:11 +01:00
|
|
|
|
2003-10-14 03:27:31 +02:00
|
|
|
/***********************************************************************
|
2005-09-03 17:11:29 +02:00
|
|
|
* wine_pthread_get_functions
|
2003-10-14 03:27:31 +02:00
|
|
|
*/
|
2005-09-03 17:11:29 +02:00
|
|
|
void wine_pthread_get_functions( struct wine_pthread_functions *functions, size_t size )
|
2003-10-14 03:27:31 +02:00
|
|
|
{
|
2005-09-03 17:11:29 +02:00
|
|
|
memcpy( functions, &pthread_functions, min( size, sizeof(pthread_functions) ));
|
2003-10-14 03:27:31 +02:00
|
|
|
}
|
|
|
|
|
2003-11-06 00:31:11 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
2005-09-03 17:11:29 +02:00
|
|
|
* wine_pthread_set_functions
|
2003-11-06 00:31:11 +01:00
|
|
|
*/
|
2005-09-03 17:11:29 +02:00
|
|
|
void wine_pthread_set_functions( const struct wine_pthread_functions *functions, size_t size )
|
2003-11-06 00:31:11 +01:00
|
|
|
{
|
2005-09-03 17:11:29 +02:00
|
|
|
memcpy( &pthread_functions, functions, min( size, sizeof(pthread_functions) ));
|
2003-11-06 00:31:11 +01:00
|
|
|
}
|
2003-10-14 03:27:31 +02:00
|
|
|
|
|
|
|
|
2003-08-30 00:23:42 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* wine_switch_to_stack
|
|
|
|
*
|
|
|
|
* Switch to the specified stack and call the function.
|
|
|
|
*/
|
|
|
|
void DECLSPEC_NORETURN wine_switch_to_stack( void (*func)(void *), void *arg, void *stack );
|
|
|
|
#if defined(__i386__) && defined(__GNUC__)
|
|
|
|
__ASM_GLOBAL_FUNC( wine_switch_to_stack,
|
|
|
|
"movl 4(%esp),%ecx\n\t" /* func */
|
|
|
|
"movl 8(%esp),%edx\n\t" /* arg */
|
|
|
|
"movl 12(%esp),%esp\n\t" /* stack */
|
2005-11-23 19:55:06 +01:00
|
|
|
"andl $~15,%esp\n\t"
|
|
|
|
"subl $12,%esp\n\t"
|
2003-08-30 00:23:42 +02:00
|
|
|
"pushl %edx\n\t"
|
|
|
|
"xorl %ebp,%ebp\n\t"
|
|
|
|
"call *%ecx\n\t"
|
2007-01-13 00:38:07 +01:00
|
|
|
"int $3" /* we never return here */ )
|
2003-08-30 00:23:42 +02:00
|
|
|
#elif defined(__i386__) && defined(_MSC_VER)
|
|
|
|
__declspec(naked) void wine_switch_to_stack( void (*func)(void *), void *arg, void *stack )
|
|
|
|
{
|
|
|
|
__asm mov ecx, 4[esp];
|
|
|
|
__asm mov edx, 8[esp];
|
|
|
|
__asm mov esp, 12[esp];
|
|
|
|
__asm push edx;
|
|
|
|
__asm xor ebp, ebp;
|
|
|
|
__asm call [ecx];
|
|
|
|
__asm int 3;
|
|
|
|
}
|
|
|
|
#elif defined(__sparc__) && defined(__GNUC__)
|
|
|
|
__ASM_GLOBAL_FUNC( wine_switch_to_stack,
|
|
|
|
"mov %o0, %l0\n\t" /* store first argument */
|
|
|
|
"mov %o1, %l1\n\t" /* store second argument */
|
2004-11-22 20:50:38 +01:00
|
|
|
"sub %o2, 96, %sp\n\t" /* store stack */
|
2003-08-30 00:23:42 +02:00
|
|
|
"call %l0, 0\n\t" /* call func */
|
|
|
|
"mov %l1, %o0\n\t" /* delay slot: arg for func */
|
2007-01-13 00:38:07 +01:00
|
|
|
"ta 0x01") /* breakpoint - we never get here */
|
2003-08-30 00:23:42 +02:00
|
|
|
#elif defined(__powerpc__) && defined(__APPLE__)
|
|
|
|
__ASM_GLOBAL_FUNC( wine_switch_to_stack,
|
|
|
|
"mtctr r3\n\t" /* func -> ctr */
|
|
|
|
"mr r3,r4\n\t" /* args -> function param 1 (r3) */
|
|
|
|
"mr r1,r5\n\t" /* stack */
|
2004-05-25 06:03:05 +02:00
|
|
|
"subi r1,r1,0x100\n\t" /* adjust stack pointer */
|
2003-08-30 00:23:42 +02:00
|
|
|
"bctr\n" /* call ctr */
|
2007-01-13 00:38:07 +01:00
|
|
|
"1:\tb 1b") /* loop */
|
2003-08-30 00:23:42 +02:00
|
|
|
#elif defined(__powerpc__) && defined(__GNUC__)
|
|
|
|
__ASM_GLOBAL_FUNC( wine_switch_to_stack,
|
|
|
|
"mtctr 3\n\t" /* func -> ctr */
|
|
|
|
"mr 3,4\n\t" /* args -> function param 1 (r3) */
|
|
|
|
"mr 1,5\n\t" /* stack */
|
|
|
|
"bctr\n\t" /* call ctr */
|
2007-01-13 00:38:07 +01:00
|
|
|
"1:\tb 1b") /* loop */
|
2004-10-11 21:50:52 +02:00
|
|
|
#elif defined(__ALPHA__) && defined(__GNUC__)
|
|
|
|
__ASM_GLOBAL_FUNC( wine_switch_to_stack,
|
|
|
|
"mov $16,$0\n\t" /* func */
|
|
|
|
"mov $17,$16\n\t" /* arg */
|
|
|
|
"mov $18,$30\n\t" /* stack */
|
|
|
|
"jsr $31,($0),0\n\t" /* call func */
|
2007-01-13 00:38:07 +01:00
|
|
|
"L1:\tbr $31,L1") /* loop */
|
2005-09-08 21:16:12 +02:00
|
|
|
#elif defined(__x86_64__) && defined(__GNUC__)
|
|
|
|
__ASM_GLOBAL_FUNC( wine_switch_to_stack,
|
|
|
|
"movq %rdi,%rax\n\t" /* func */
|
|
|
|
"movq %rsi,%rdi\n\t" /* arg */
|
|
|
|
"andq $~15,%rdx\n\t" /* stack */
|
|
|
|
"movq %rdx,%rsp\n\t"
|
|
|
|
"xorq %rbp,%rbp\n\t"
|
|
|
|
"callq *%rax\n\t" /* call func */
|
2007-01-13 00:38:07 +01:00
|
|
|
"int $3")
|
2003-08-30 00:23:42 +02:00
|
|
|
#else
|
2008-03-26 15:38:00 +01:00
|
|
|
void DECLSPEC_NORETURN wine_switch_to_stack( void (*func)(void *), void *arg, void *stack )
|
|
|
|
{
|
|
|
|
wine_call_on_stack( (int (*)(void *))func, arg, stack );
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* wine_call_on_stack
|
|
|
|
*
|
|
|
|
* Switch to the specified stack to call the function and return.
|
|
|
|
*/
|
|
|
|
int wine_call_on_stack( int (*func)(void *), void *arg, void *stack );
|
|
|
|
#if defined(__i386__) && defined(__GNUC__)
|
|
|
|
__ASM_GLOBAL_FUNC( wine_call_on_stack,
|
|
|
|
"pushl %ebp\n\t"
|
|
|
|
"pushl %esi\n\t"
|
|
|
|
"movl 12(%esp),%ecx\n\t" /* func */
|
|
|
|
"movl 16(%esp),%edx\n\t" /* arg */
|
|
|
|
"movl 20(%esp),%esi\n\t" /* stack */
|
|
|
|
"andl $~15,%esi\n\t"
|
|
|
|
"subl $12,%esi\n\t"
|
|
|
|
"xchgl %esi,%esp\n\t"
|
|
|
|
"pushl %edx\n\t"
|
|
|
|
"xorl %ebp,%ebp\n\t"
|
|
|
|
"call *%ecx\n\t"
|
|
|
|
"movl %esi,%esp\n\t"
|
|
|
|
"popl %esi\n\t"
|
|
|
|
"popl %ebp\n\t"
|
|
|
|
"ret" )
|
|
|
|
#elif defined(__i386__) && defined(_MSC_VER)
|
|
|
|
__declspec(naked) int wine_call_on_stack( int (*func)(void *), void *arg, void *stack )
|
|
|
|
{
|
|
|
|
__asm push ebp;
|
|
|
|
__asm push esi;
|
|
|
|
__asm mov ecx, 12[esp];
|
|
|
|
__asm mov edx, 16[esp];
|
|
|
|
__asm mov esi, 20[esp];
|
|
|
|
__asm xchg esp, esi;
|
|
|
|
__asm push edx;
|
|
|
|
__asm xor ebp, ebp;
|
|
|
|
__asm call [ecx];
|
|
|
|
__asm mov esp, esi;
|
|
|
|
__asm pop esi;
|
|
|
|
__asm pop ebp
|
|
|
|
__asm ret;
|
|
|
|
}
|
|
|
|
#elif defined(__x86_64__) && defined(__GNUC__)
|
|
|
|
__ASM_GLOBAL_FUNC( wine_call_on_stack,
|
|
|
|
"pushq %rbp\n\t"
|
|
|
|
"pushq %rbx\n\t"
|
|
|
|
"movq %rsp,%rbx\n\t"
|
|
|
|
"movq %rdi,%rax\n\t" /* func */
|
|
|
|
"movq %rsi,%rdi\n\t" /* arg */
|
|
|
|
"andq $~15,%rdx\n\t" /* stack */
|
|
|
|
"movq %rdx,%rsp\n\t"
|
|
|
|
"xorq %rbp,%rbp\n\t"
|
|
|
|
"callq *%rax\n\t" /* call func */
|
|
|
|
"movq %rbx,%rsp\n\t"
|
|
|
|
"popq %rbx\n\t"
|
|
|
|
"popq %rbp\n\t"
|
|
|
|
"ret")
|
|
|
|
#else
|
2003-08-30 00:23:42 +02:00
|
|
|
#error You must implement wine_switch_to_stack for your platform
|
|
|
|
#endif
|