port.c revision b955672b950093ff7416d1269dd4d3b69983bd8f
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Wine portability routines
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Copyright 2000 Alexandre Julliard
45e9809aff7304721fddb95654901b32195c9c7avboxsync * This library is free software; you can redistribute it and/or
45e9809aff7304721fddb95654901b32195c9c7avboxsync * modify it under the terms of the GNU Lesser General Public
45e9809aff7304721fddb95654901b32195c9c7avboxsync * License as published by the Free Software Foundation; either
45e9809aff7304721fddb95654901b32195c9c7avboxsync * version 2.1 of the License, or (at your option) any later version.
45e9809aff7304721fddb95654901b32195c9c7avboxsync * This library is distributed in the hope that it will be useful,
45e9809aff7304721fddb95654901b32195c9c7avboxsync * but WITHOUT ANY WARRANTY; without even the implied warranty of
45e9809aff7304721fddb95654901b32195c9c7avboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Lesser General Public License for more details.
45e9809aff7304721fddb95654901b32195c9c7avboxsync * You should have received a copy of the GNU Lesser General Public
45e9809aff7304721fddb95654901b32195c9c7avboxsync * License along with this library; if not, write to the Free Software
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
45e9809aff7304721fddb95654901b32195c9c7avboxsync * other than GPL or LGPL is available it will apply instead, Sun elects to use only
45e9809aff7304721fddb95654901b32195c9c7avboxsync * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
45e9809aff7304721fddb95654901b32195c9c7avboxsync * a choice of LGPL license versions is made available with the language indicating
45e9809aff7304721fddb95654901b32195c9c7avboxsync * that LGPLv2 or any later version may be used, or where a choice of which version
45e9809aff7304721fddb95654901b32195c9c7avboxsync * of the LGPL is applied is otherwise unspecified.
45e9809aff7304721fddb95654901b32195c9c7avboxsyncstatic struct wine_pthread_functions pthread_functions;
45e9809aff7304721fddb95654901b32195c9c7avboxsync/***********************************************************************
45e9809aff7304721fddb95654901b32195c9c7avboxsync * wine_pthread_get_functions
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid wine_pthread_get_functions( struct wine_pthread_functions *functions, size_t size )
45e9809aff7304721fddb95654901b32195c9c7avboxsync memcpy( functions, &pthread_functions, min( size, sizeof(pthread_functions) ));
45e9809aff7304721fddb95654901b32195c9c7avboxsync/***********************************************************************
45e9809aff7304721fddb95654901b32195c9c7avboxsync * wine_pthread_set_functions
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid wine_pthread_set_functions( const struct wine_pthread_functions *functions, size_t size )
45e9809aff7304721fddb95654901b32195c9c7avboxsync memcpy( &pthread_functions, functions, min( size, sizeof(pthread_functions) ));
45e9809aff7304721fddb95654901b32195c9c7avboxsync/***********************************************************************
45e9809aff7304721fddb95654901b32195c9c7avboxsync * wine_switch_to_stack
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Switch to the specified stack and call the function.
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid DECLSPEC_NORETURN wine_switch_to_stack( void (*func)(void *), void *arg, void *stack );
45e9809aff7304721fddb95654901b32195c9c7avboxsync "andl $~15,%esp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "subl $12,%esp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "pushl %edx\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "xorl %ebp,%ebp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "call *%ecx\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync__declspec(naked) void wine_switch_to_stack( void (*func)(void *), void *arg, void *stack )
45e9809aff7304721fddb95654901b32195c9c7avboxsync "subi 1, 1, 16\n\t" /* allocate space for the callee */
45e9809aff7304721fddb95654901b32195c9c7avboxsync "stw 0, 0(1)\n\t" /* create a bottom stack frame */
45e9809aff7304721fddb95654901b32195c9c7avboxsync "movq %rdx,%rsp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "xorq %rbp,%rbp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid DECLSPEC_NORETURN wine_switch_to_stack( void (*func)(void *), void *arg, void *stack )
45e9809aff7304721fddb95654901b32195c9c7avboxsync wine_call_on_stack( (int (*)(void *))func, arg, stack );
45e9809aff7304721fddb95654901b32195c9c7avboxsync/***********************************************************************
45e9809aff7304721fddb95654901b32195c9c7avboxsync * wine_call_on_stack
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Switch to the specified stack to call the function and return.
45e9809aff7304721fddb95654901b32195c9c7avboxsyncint wine_call_on_stack( int (*func)(void *), void *arg, void *stack );
45e9809aff7304721fddb95654901b32195c9c7avboxsync "pushl %ebp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "pushl %esi\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "andl $~15,%esi\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "subl $12,%esi\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "xchgl %esi,%esp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "pushl %edx\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "xorl %ebp,%ebp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "call *%ecx\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "movl %esi,%esp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "popl %esi\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "popl %ebp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync__declspec(naked) int wine_call_on_stack( int (*func)(void *), void *arg, void *stack )
45e9809aff7304721fddb95654901b32195c9c7avboxsync "pushq %rbp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "pushq %rbx\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "movq %rsp,%rbx\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "movq %rdx,%rsp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "xorq %rbp,%rbp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "movq %rbx,%rsp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "popq %rbx\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "popq %rbp\n\t"
45e9809aff7304721fddb95654901b32195c9c7avboxsync "subi 5, 5, 16\n\t" /* reserve space on new stack */
45e9809aff7304721fddb95654901b32195c9c7avboxsync "stwu 1, -16(1)\n\t" /* create a frame for this function */