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>
|
|
|
|
|
2019-03-27 10:03:38 +01:00
|
|
|
#define WINE_UNICODE_INLINE /* nothing */
|
2016-02-18 06:10:26 +01:00
|
|
|
#include "wine/unicode.h"
|
2003-08-30 00:23:42 +02:00
|
|
|
#include "wine/library.h"
|
|
|
|
|
2016-03-14 11:28:51 +01:00
|
|
|
/* functions from libwine_port that are also exported from libwine for backwards compatibility,
|
|
|
|
* on platforms that require it */
|
|
|
|
#ifndef __ANDROID__
|
2016-02-18 06:10:26 +01:00
|
|
|
const void *libwine_port_functions[] =
|
|
|
|
{
|
2019-03-27 10:03:38 +01:00
|
|
|
strtolW,
|
|
|
|
vsnprintfW,
|
2019-03-23 13:43:17 +01:00
|
|
|
wine_compare_string,
|
2016-02-18 06:33:10 +01:00
|
|
|
wine_cp_enum_table,
|
|
|
|
wine_cp_get_table,
|
2016-02-19 03:41:44 +01:00
|
|
|
wine_cp_mbstowcs,
|
2016-02-19 03:43:35 +01:00
|
|
|
wine_cp_wcstombs,
|
2016-02-18 10:49:28 +01:00
|
|
|
wine_cpsymbol_mbstowcs,
|
|
|
|
wine_cpsymbol_wcstombs,
|
2016-02-19 03:43:35 +01:00
|
|
|
wine_fold_string,
|
|
|
|
wine_utf8_mbstowcs,
|
|
|
|
wine_utf8_wcstombs
|
2016-02-18 06:10:26 +01:00
|
|
|
};
|
2016-03-14 11:28:51 +01:00
|
|
|
#endif
|
2016-02-18 06:10:26 +01:00
|
|
|
|
2009-07-04 11:36:44 +02:00
|
|
|
/* no longer used, for backwards compatibility only */
|
|
|
|
struct wine_pthread_functions;
|
|
|
|
static void *pthread_functions[8];
|
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.
|
|
|
|
*/
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* wine_call_on_stack
|
|
|
|
*
|
|
|
|
* Switch to the specified stack to call the function and return.
|
|
|
|
*/
|
2009-05-15 15:51:53 +02:00
|
|
|
|
2008-03-26 15:38:00 +01:00
|
|
|
#if defined(__i386__) && defined(__GNUC__)
|
|
|
|
__ASM_GLOBAL_FUNC( wine_call_on_stack,
|
|
|
|
"pushl %ebp\n\t"
|
2009-06-25 11:54:02 +02:00
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
|
2008-03-26 15:38:00 +01:00
|
|
|
"pushl %esi\n\t"
|
2009-06-25 11:54:02 +02:00
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %esi,0\n\t")
|
|
|
|
"movl %esp,%esi\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa_register %esi\n\t")
|
2008-03-26 15:38:00 +01:00
|
|
|
"movl 12(%esp),%ecx\n\t" /* func */
|
|
|
|
"movl 16(%esp),%edx\n\t" /* arg */
|
2009-06-25 11:54:02 +02:00
|
|
|
"movl 20(%esp),%eax\n\t" /* stack */
|
|
|
|
"andl $~15,%eax\n\t"
|
|
|
|
"subl $12,%eax\n\t"
|
|
|
|
"movl %eax,%esp\n\t"
|
2008-03-26 15:38:00 +01:00
|
|
|
"pushl %edx\n\t"
|
|
|
|
"xorl %ebp,%ebp\n\t"
|
|
|
|
"call *%ecx\n\t"
|
|
|
|
"movl %esi,%esp\n\t"
|
|
|
|
"popl %esi\n\t"
|
2009-06-25 11:54:02 +02:00
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
|
|
|
|
__ASM_CFI(".cfi_same_value %esi\n\t")
|
2008-03-26 15:38:00 +01:00
|
|
|
"popl %ebp\n\t"
|
2009-06-25 11:54:02 +02:00
|
|
|
__ASM_CFI(".cfi_def_cfa %esp,4\n\t")
|
|
|
|
__ASM_CFI(".cfi_same_value %ebp\n\t")
|
2008-03-26 15:38:00 +01:00
|
|
|
"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;
|
2018-12-06 10:31:33 +01:00
|
|
|
__asm pop ebp;
|
2008-03-26 15:38:00 +01:00
|
|
|
__asm ret;
|
|
|
|
}
|
|
|
|
#elif defined(__x86_64__) && defined(__GNUC__)
|
|
|
|
__ASM_GLOBAL_FUNC( wine_call_on_stack,
|
|
|
|
"pushq %rbp\n\t"
|
2010-04-12 12:37:35 +02:00
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 8\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %rbp,0\n\t")
|
2009-06-16 14:26:20 +02:00
|
|
|
"movq %rsp,%rbp\n\t"
|
2010-04-12 12:37:35 +02:00
|
|
|
__ASM_CFI(".cfi_def_cfa_register %rbp\n\t")
|
2008-03-26 15:38:00 +01:00
|
|
|
"movq %rdi,%rax\n\t" /* func */
|
|
|
|
"movq %rsi,%rdi\n\t" /* arg */
|
|
|
|
"andq $~15,%rdx\n\t" /* stack */
|
|
|
|
"movq %rdx,%rsp\n\t"
|
|
|
|
"callq *%rax\n\t" /* call func */
|
2009-06-16 14:26:20 +02:00
|
|
|
"movq %rbp,%rsp\n\t"
|
2010-04-12 12:37:35 +02:00
|
|
|
__ASM_CFI(".cfi_def_cfa_register %rsp\n\t")
|
2008-03-26 15:38:00 +01:00
|
|
|
"popq %rbp\n\t"
|
2010-04-12 12:37:35 +02:00
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset -8\n\t")
|
|
|
|
__ASM_CFI(".cfi_same_value %rbp\n\t")
|
2008-03-26 15:38:00 +01:00
|
|
|
"ret")
|
2008-05-31 10:50:36 +02:00
|
|
|
#elif defined(__powerpc__) && defined(__GNUC__)
|
|
|
|
__ASM_GLOBAL_FUNC( wine_call_on_stack,
|
|
|
|
"mflr 0\n\t" /* get return address */
|
|
|
|
"stw 0, 4(1)\n\t" /* save return address */
|
|
|
|
"subi 5, 5, 16\n\t" /* reserve space on new stack */
|
|
|
|
"stw 1, 12(5)\n\t" /* store old sp */
|
|
|
|
"mtctr 3\n\t" /* func -> ctr */
|
|
|
|
"mr 3,4\n\t" /* args -> function param 1 (r3) */
|
|
|
|
"mr 1,5\n\t" /* stack */
|
|
|
|
"li 0, 0\n\t" /* zero */
|
|
|
|
"stw 0, 0(1)\n\t" /* bottom of stack */
|
|
|
|
"stwu 1, -16(1)\n\t" /* create a frame for this function */
|
|
|
|
"bctrl\n\t" /* call ctr */
|
|
|
|
"lwz 1, 28(1)\n\t" /* fetch old sp */
|
|
|
|
"lwz 0, 4(1)\n\t" /* fetch return address */
|
|
|
|
"mtlr 0\n\t" /* return address -> lr */
|
|
|
|
"blr") /* return */
|
2010-09-18 18:01:06 +02:00
|
|
|
#elif defined(__arm__) && defined(__GNUC__)
|
2009-10-02 14:56:50 +02:00
|
|
|
__ASM_GLOBAL_FUNC( wine_call_on_stack,
|
2010-09-18 18:01:06 +02:00
|
|
|
"push {r4,LR}\n\t" /* save return address on stack */
|
|
|
|
"mov r4, sp\n\t" /* store old sp in local var */
|
|
|
|
"mov sp, r2\n\t" /* stack */
|
|
|
|
"mov r2, r0\n\t" /* func -> scratch register */
|
|
|
|
"mov r0, r1\n\t" /* arg */
|
2012-04-07 22:02:28 +02:00
|
|
|
"blx r2\n\t" /* call func */
|
2010-09-18 18:01:06 +02:00
|
|
|
"mov sp, r4\n\t" /* restore old sp from local var */
|
|
|
|
"pop {r4,PC}") /* fetch return address into pc */
|
2013-01-16 00:41:58 +01:00
|
|
|
#elif defined(__aarch64__) && defined(__GNUC__)
|
|
|
|
__ASM_GLOBAL_FUNC( wine_call_on_stack,
|
|
|
|
"stp x29, x30, [sp,#-32]!\n\t" /* save return address on stack */
|
|
|
|
"str x19, [sp,#16]\n\t" /* save register on stack */
|
|
|
|
"mov x19, sp\n\t" /* store old sp in local var */
|
|
|
|
"mov sp, x2\n\t" /* stack */
|
|
|
|
"mov x2, x0\n\t" /* func -> scratch register */
|
|
|
|
"mov x0, x1\n\t" /* arg */
|
|
|
|
"blr x2\n\t" /* call func */
|
|
|
|
"mov sp, x19\n\t" /* restore old sp from local var */
|
|
|
|
"ldr x19, [sp,#16]\n\t" /* restore register from stack */
|
|
|
|
"ldp x29, x30, [sp],#32\n\t" /* restore return address */
|
|
|
|
"ret") /* return */
|
2008-03-26 15:38:00 +01:00
|
|
|
#else
|
2011-01-17 12:49:31 +01:00
|
|
|
#error You must implement wine_call_on_stack for your platform
|
2003-08-30 00:23:42 +02:00
|
|
|
#endif
|