gdiplus: Implemented GdipGetPenEndCap.
[wine.git] / libs / wine / port.c
blob859818f9828b4a42a3b97cfd47996414bc39715f
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"
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/types.h>
28 #include "wine/library.h"
29 #include "wine/pthread.h"
31 static struct wine_pthread_functions pthread_functions;
33 /***********************************************************************
34 * wine_pthread_get_functions
36 void wine_pthread_get_functions( struct wine_pthread_functions *functions, size_t size )
38 memcpy( functions, &pthread_functions, min( size, sizeof(pthread_functions) ));
42 /***********************************************************************
43 * wine_pthread_set_functions
45 void wine_pthread_set_functions( const struct wine_pthread_functions *functions, size_t size )
47 memcpy( &pthread_functions, functions, min( size, sizeof(pthread_functions) ));
51 /***********************************************************************
52 * wine_switch_to_stack
54 * Switch to the specified stack and call the function.
56 void DECLSPEC_NORETURN wine_switch_to_stack( void (*func)(void *), void *arg, void *stack );
57 #if defined(__i386__) && defined(__GNUC__)
58 __ASM_GLOBAL_FUNC( wine_switch_to_stack,
59 "movl 4(%esp),%ecx\n\t" /* func */
60 "movl 8(%esp),%edx\n\t" /* arg */
61 "movl 12(%esp),%esp\n\t" /* stack */
62 "andl $~15,%esp\n\t"
63 "subl $12,%esp\n\t"
64 "pushl %edx\n\t"
65 "xorl %ebp,%ebp\n\t"
66 "call *%ecx\n\t"
67 "int $3" /* we never return here */ )
68 #elif defined(__i386__) && defined(_MSC_VER)
69 __declspec(naked) void wine_switch_to_stack( void (*func)(void *), void *arg, void *stack )
71 __asm mov ecx, 4[esp];
72 __asm mov edx, 8[esp];
73 __asm mov esp, 12[esp];
74 __asm push edx;
75 __asm xor ebp, ebp;
76 __asm call [ecx];
77 __asm int 3;
79 #elif defined(__sparc__) && defined(__GNUC__)
80 __ASM_GLOBAL_FUNC( wine_switch_to_stack,
81 "mov %o0, %l0\n\t" /* store first argument */
82 "mov %o1, %l1\n\t" /* store second argument */
83 "sub %o2, 96, %sp\n\t" /* store stack */
84 "call %l0, 0\n\t" /* call func */
85 "mov %l1, %o0\n\t" /* delay slot: arg for func */
86 "ta 0x01") /* breakpoint - we never get here */
87 #elif defined(__powerpc__) && defined(__APPLE__)
88 __ASM_GLOBAL_FUNC( wine_switch_to_stack,
89 "mtctr r3\n\t" /* func -> ctr */
90 "mr r3,r4\n\t" /* args -> function param 1 (r3) */
91 "mr r1,r5\n\t" /* stack */
92 "subi r1,r1,0x100\n\t" /* adjust stack pointer */
93 "bctrl\n" /* call ctr */
94 "1:\tb 1b") /* loop */
95 #elif defined(__powerpc__) && defined(__GNUC__)
96 __ASM_GLOBAL_FUNC( wine_switch_to_stack,
97 "mtctr 3\n\t" /* func -> ctr */
98 "mr 3,4\n\t" /* args -> function param 1 (r3) */
99 "mr 1,5\n\t" /* stack */
100 "subi 1, 1, 16\n\t" /* allocate space for the callee */
101 "li 0, 0\n\t" /* load zero */
102 "stw 0, 0(1)\n\t" /* create a bottom stack frame */
103 "bctrl\n\t" /* call ctr */
104 "1:\tb 1b") /* loop */
105 #elif defined(__ALPHA__) && defined(__GNUC__)
106 __ASM_GLOBAL_FUNC( wine_switch_to_stack,
107 "mov $16,$0\n\t" /* func */
108 "mov $17,$16\n\t" /* arg */
109 "mov $18,$30\n\t" /* stack */
110 "jsr $31,($0),0\n\t" /* call func */
111 "L1:\tbr $31,L1") /* loop */
112 #elif defined(__x86_64__) && defined(__GNUC__)
113 __ASM_GLOBAL_FUNC( wine_switch_to_stack,
114 "movq %rdi,%rax\n\t" /* func */
115 "movq %rsi,%rdi\n\t" /* arg */
116 "andq $~15,%rdx\n\t" /* stack */
117 "movq %rdx,%rsp\n\t"
118 "xorq %rbp,%rbp\n\t"
119 "callq *%rax\n\t" /* call func */
120 "int $3")
121 #else
122 void DECLSPEC_NORETURN wine_switch_to_stack( void (*func)(void *), void *arg, void *stack )
124 wine_call_on_stack( (int (*)(void *))func, arg, stack );
125 abort();
127 #endif
130 /***********************************************************************
131 * wine_call_on_stack
133 * Switch to the specified stack to call the function and return.
135 int wine_call_on_stack( int (*func)(void *), void *arg, void *stack );
136 #if defined(__i386__) && defined(__GNUC__)
137 __ASM_GLOBAL_FUNC( wine_call_on_stack,
138 "pushl %ebp\n\t"
139 "pushl %esi\n\t"
140 "movl 12(%esp),%ecx\n\t" /* func */
141 "movl 16(%esp),%edx\n\t" /* arg */
142 "movl 20(%esp),%esi\n\t" /* stack */
143 "andl $~15,%esi\n\t"
144 "subl $12,%esi\n\t"
145 "xchgl %esi,%esp\n\t"
146 "pushl %edx\n\t"
147 "xorl %ebp,%ebp\n\t"
148 "call *%ecx\n\t"
149 "movl %esi,%esp\n\t"
150 "popl %esi\n\t"
151 "popl %ebp\n\t"
152 "ret" )
153 #elif defined(__i386__) && defined(_MSC_VER)
154 __declspec(naked) int wine_call_on_stack( int (*func)(void *), void *arg, void *stack )
156 __asm push ebp;
157 __asm push esi;
158 __asm mov ecx, 12[esp];
159 __asm mov edx, 16[esp];
160 __asm mov esi, 20[esp];
161 __asm xchg esp, esi;
162 __asm push edx;
163 __asm xor ebp, ebp;
164 __asm call [ecx];
165 __asm mov esp, esi;
166 __asm pop esi;
167 __asm pop ebp
168 __asm ret;
170 #elif defined(__x86_64__) && defined(__GNUC__)
171 __ASM_GLOBAL_FUNC( wine_call_on_stack,
172 "pushq %rbp\n\t"
173 "pushq %rbx\n\t"
174 "movq %rsp,%rbx\n\t"
175 "movq %rdi,%rax\n\t" /* func */
176 "movq %rsi,%rdi\n\t" /* arg */
177 "andq $~15,%rdx\n\t" /* stack */
178 "movq %rdx,%rsp\n\t"
179 "xorq %rbp,%rbp\n\t"
180 "callq *%rax\n\t" /* call func */
181 "movq %rbx,%rsp\n\t"
182 "popq %rbx\n\t"
183 "popq %rbp\n\t"
184 "ret")
185 #elif defined(__powerpc__) && defined(__GNUC__)
186 __ASM_GLOBAL_FUNC( wine_call_on_stack,
187 "mflr 0\n\t" /* get return address */
188 "stw 0, 4(1)\n\t" /* save return address */
189 "subi 5, 5, 16\n\t" /* reserve space on new stack */
190 "stw 1, 12(5)\n\t" /* store old sp */
191 "mtctr 3\n\t" /* func -> ctr */
192 "mr 3,4\n\t" /* args -> function param 1 (r3) */
193 "mr 1,5\n\t" /* stack */
194 "li 0, 0\n\t" /* zero */
195 "stw 0, 0(1)\n\t" /* bottom of stack */
196 "stwu 1, -16(1)\n\t" /* create a frame for this function */
197 "bctrl\n\t" /* call ctr */
198 "lwz 1, 28(1)\n\t" /* fetch old sp */
199 "lwz 0, 4(1)\n\t" /* fetch return address */
200 "mtlr 0\n\t" /* return address -> lr */
201 "blr") /* return */
202 #else
203 #error You must implement wine_switch_to_stack for your platform
204 #endif