ntdll: Exclude large integer APIs from relay tracing.
[wine.git] / libs / wine / port.c
blob8e56ada52aaddb8ca5d5d81eb3089432400fd1c1
1 /*
2 * Wine portability routines
4 * Copyright 2000 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
23 #include "wine/asm.h"
25 #ifdef __ASM_OBSOLETE
27 #include <stdlib.h>
28 #include <string.h>
29 #include <sys/types.h>
30 #include <stdarg.h>
31 #include <windef.h>
33 /* no longer used, for backwards compatibility only */
34 struct wine_pthread_functions;
35 static void *pthread_functions[8];
37 /***********************************************************************
38 * wine_pthread_get_functions
40 void wine_pthread_get_functions_obsolete( struct wine_pthread_functions *functions, size_t size )
42 memcpy( functions, &pthread_functions, min( size, sizeof(pthread_functions) ));
46 /***********************************************************************
47 * wine_pthread_set_functions
49 void wine_pthread_set_functions_obsolete( const struct wine_pthread_functions *functions, size_t size )
51 memcpy( &pthread_functions, functions, min( size, sizeof(pthread_functions) ));
55 /***********************************************************************
56 * wine_call_on_stack
58 * Switch to the specified stack to call the function and return.
61 extern int wine_call_on_stack_obsolete( int (*func)(void *), void *arg, void *stack );
62 #if defined(__i386__) && defined(__GNUC__)
63 __ASM_GLOBAL_FUNC( wine_call_on_stack_obsolete,
64 "pushl %ebp\n\t"
65 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
66 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
67 "pushl %esi\n\t"
68 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
69 __ASM_CFI(".cfi_rel_offset %esi,0\n\t")
70 "movl %esp,%esi\n\t"
71 __ASM_CFI(".cfi_def_cfa_register %esi\n\t")
72 "movl 12(%esp),%ecx\n\t" /* func */
73 "movl 16(%esp),%edx\n\t" /* arg */
74 "movl 20(%esp),%eax\n\t" /* stack */
75 "andl $~15,%eax\n\t"
76 "subl $12,%eax\n\t"
77 "movl %eax,%esp\n\t"
78 "pushl %edx\n\t"
79 "xorl %ebp,%ebp\n\t"
80 "call *%ecx\n\t"
81 "movl %esi,%esp\n\t"
82 "popl %esi\n\t"
83 __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
84 __ASM_CFI(".cfi_same_value %esi\n\t")
85 "popl %ebp\n\t"
86 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
87 __ASM_CFI(".cfi_same_value %ebp\n\t")
88 "ret" )
89 #elif defined(__x86_64__) && defined(__GNUC__)
90 __ASM_GLOBAL_FUNC( wine_call_on_stack_obsolete,
91 "pushq %rbp\n\t"
92 __ASM_CFI(".cfi_adjust_cfa_offset 8\n\t")
93 __ASM_CFI(".cfi_rel_offset %rbp,0\n\t")
94 "movq %rsp,%rbp\n\t"
95 __ASM_CFI(".cfi_def_cfa_register %rbp\n\t")
96 "movq %rdi,%rax\n\t" /* func */
97 "movq %rsi,%rdi\n\t" /* arg */
98 "andq $~15,%rdx\n\t" /* stack */
99 "movq %rdx,%rsp\n\t"
100 "callq *%rax\n\t" /* call func */
101 "movq %rbp,%rsp\n\t"
102 __ASM_CFI(".cfi_def_cfa_register %rsp\n\t")
103 "popq %rbp\n\t"
104 __ASM_CFI(".cfi_adjust_cfa_offset -8\n\t")
105 __ASM_CFI(".cfi_same_value %rbp\n\t")
106 "ret")
107 #elif defined(__arm__) && defined(__GNUC__)
108 __ASM_GLOBAL_FUNC( wine_call_on_stack_obsolete,
109 "push {r4,LR}\n\t" /* save return address on stack */
110 "mov r4, sp\n\t" /* store old sp in local var */
111 "mov sp, r2\n\t" /* stack */
112 "mov r2, r0\n\t" /* func -> scratch register */
113 "mov r0, r1\n\t" /* arg */
114 "blx r2\n\t" /* call func */
115 "mov sp, r4\n\t" /* restore old sp from local var */
116 "pop {r4,PC}") /* fetch return address into pc */
117 #elif defined(__aarch64__) && defined(__GNUC__)
118 __ASM_GLOBAL_FUNC( wine_call_on_stack_obsolete,
119 "stp x29, x30, [sp,#-32]!\n\t" /* save return address on stack */
120 "str x19, [sp,#16]\n\t" /* save register on stack */
121 "mov x19, sp\n\t" /* store old sp in local var */
122 "mov sp, x2\n\t" /* stack */
123 "mov x2, x0\n\t" /* func -> scratch register */
124 "mov x0, x1\n\t" /* arg */
125 "blr x2\n\t" /* call func */
126 "mov sp, x19\n\t" /* restore old sp from local var */
127 "ldr x19, [sp,#16]\n\t" /* restore register from stack */
128 "ldp x29, x30, [sp],#32\n\t" /* restore return address */
129 "ret") /* return */
130 #endif
132 /***********************************************************************
133 * wine_switch_to_stack
135 * Switch to the specified stack and call the function.
137 void DECLSPEC_NORETURN wine_switch_to_stack_obsolete( void (*func)(void *), void *arg, void *stack )
139 wine_call_on_stack_obsolete( (int (*)(void *))func, arg, stack );
140 abort();
143 __ASM_OBSOLETE(wine_pthread_get_functions);
144 __ASM_OBSOLETE(wine_pthread_set_functions);
145 __ASM_OBSOLETE(wine_call_on_stack);
146 __ASM_OBSOLETE(wine_switch_to_stack);
148 #endif /* __ASM_OBSOLETE */