Ticket #514: win32_darwin.diff
| File win32_darwin.diff, 6.7 KB (added by , 20 years ago) |
|---|
-
win32.c
old new 19 19 20 20 #include "config.h" 21 21 22 23 /* 24 * Modified by DarkSoul (darksoul@darkbsd.org) 25 * 26 * Added prefixes and suffixes to every non-WINAPI 27 * function. This is for use with ia32/Darwin, in 28 * order to ensure a clean %esp register. 29 */ 30 31 #ifdef CONFIG_DARWIN 32 # define STACK_CLEANER_PREFIX __asm__( "pushl %ebp \n\t" \ 33 "movl %esp, %ebp \n\t" \ 34 "andl $-16, %esp \n\t" \ 35 "subl $16, %esp \n\t" ) 36 # define STACK_CLEANER_SUFFIX __asm__( "leave \n\t" ) 37 #else 38 /* No need for stack cleaner unless for Darwin, is there ? */ 39 # define STACK_CLEANER_PREFIX 40 # define STACK_CLEANER_SUFFIX 41 #endif 42 22 43 #ifdef MPLAYER 23 44 #ifdef USE_QTX_CODECS 24 45 #define QTX … … 193 214 #endif 194 215 int LOADER_DEBUG=1; // active only if compiled with -DDETAILED_OUT 195 216 //#define DETAILED_OUT 196 static inlinevoid dbgprintf(char* fmt, ...)217 static void dbgprintf(char* fmt, ...) 197 218 { 219 #ifndef CONFIG_DARWIN 198 220 #ifdef DETAILED_OUT 199 221 if(LOADER_DEBUG) 200 222 { 223 STACK_CLEANER_PREFIX; 201 224 FILE* f; 202 225 va_list va; 203 226 va_start(va, fmt); … … 211 234 fclose(f); 212 235 } 213 236 va_end(va); 237 STACK_CLEANER_SUFFIX; 214 238 } 215 239 #endif 216 240 #ifdef MPLAYER … … 223 247 // mp_dbg(MSGT_WIN32, MSGL_DBG3, fmt, va); 224 248 va_end(va); 225 249 } 250 STACK_CLEANER_PREFIX; 226 251 fflush(stdout); 252 STACK_CLEANER_SUFFIX; 253 #endif 227 254 #endif 228 255 } 229 256 … … 465 492 } 466 493 #endif 467 494 495 #ifndef MEMORY_DEBUG 468 496 static inline void* my_mreq(int size, int to_zero) 469 497 { 470 498 return mreq_private(size, to_zero, AREATYPE_CLIENT); 471 499 } 500 #endif 472 501 473 502 static int my_size(void* memory) 474 503 { … … 3170 3199 #define SECS_1601_TO_1970 ((369 * 365 + 89) * 86400ULL) 3171 3200 static void WINAPI expGetSystemTimeAsFileTime(FILETIME* systime) 3172 3201 { 3202 STACK_CLEANER_PREFIX; 3173 3203 struct tm *local_tm; 3174 3204 struct timeval tv; 3175 3205 unsigned long long secs; 3176 3206 3207 #ifndef CONFIG_DARWIN 3208 // This calls fflush(), which is not really liked on Darwin() in a DLL-code context 3209 // which maims %esp register. 3177 3210 dbgprintf("GetSystemTime(0x%x)\n", systime); 3211 #endif /* !CONFIG_DARWIN */ 3178 3212 gettimeofday(&tv, NULL); 3179 3213 secs = (tv.tv_sec + SECS_1601_TO_1970) * 10000000; 3180 3214 secs += tv.tv_usec * 10; 3181 3215 systime->dwLowDateTime = secs & 0xffffffff; 3182 3216 systime->dwHighDateTime = (secs >> 32); 3217 STACK_CLEANER_SUFFIX; 3183 3218 } 3184 3219 3185 3220 static int WINAPI expGetEnvironmentVariableA(const char* name, char* field, int size) … … 3886 3921 */ 3887 3922 static void* expmalloc(int size) 3888 3923 { 3924 STACK_CLEANER_PREFIX; 3889 3925 //printf("malloc"); 3890 3926 // return malloc(size); 3891 3927 void* result=my_mreq(size,0); 3892 3928 dbgprintf("malloc(0x%x) => 0x%x\n", size,result); 3893 3929 if(result==0) 3894 printf("WARNING: malloc() failed\n"); 3930 printf("WARNING: malloc(%d) failed\n", size); 3931 STACK_CLEANER_SUFFIX; 3895 3932 return result; 3896 3933 } 3897 3934 static void expfree(void* mem) 3898 3935 { 3936 STACK_CLEANER_PREFIX; 3899 3937 // return free(mem); 3900 3938 dbgprintf("free(%p)\n", mem); 3901 3939 my_release(mem); 3940 STACK_CLEANER_SUFFIX; 3902 3941 } 3903 3942 /* needed by atrac3.acm */ 3904 3943 static void *expcalloc(int num, int size) 3905 3944 { 3945 STACK_CLEANER_PREFIX; 3906 3946 void* result=my_mreq(num*size,1); 3907 3947 dbgprintf("calloc(%d,%d) => %p\n", num,size,result); 3908 3948 if(result==0) 3909 3949 printf("WARNING: calloc() failed\n"); 3950 STACK_CLEANER_SUFFIX; 3910 3951 return result; 3911 3952 } 3912 3953 static void* expnew(int size) 3913 3954 { 3955 STACK_CLEANER_PREFIX; 3914 3956 // printf("NEW:: Call from address %08x\n STACK DUMP:\n", *(-1+(int*)&size)); 3915 3957 // printf("%08x %08x %08x %08x\n", 3916 3958 // size, *(1+(int*)&size), … … 3922 3964 dbgprintf("new(%d) => %p\n", size, result); 3923 3965 if (result==0) 3924 3966 printf("WARNING: new() failed\n"); 3967 STACK_CLEANER_SUFFIX; 3925 3968 return result; 3926 3969 3927 3970 } 3928 3971 static int expdelete(void* memory) 3929 3972 { 3973 STACK_CLEANER_PREFIX; 3930 3974 dbgprintf("delete(%p)\n", memory); 3931 3975 my_release(memory); 3976 STACK_CLEANER_SUFFIX; 3932 3977 return 0; 3933 3978 } 3934 3979 … … 4018 4063 #if 0 4019 4064 static int exp_initterm(int v1, int v2) 4020 4065 { 4066 STACK_CLEANER_PREFIX; 4021 4067 dbgprintf("_initterm(0x%x, 0x%x) => 0\n", v1, v2); 4022 4068 return 0; 4069 STACK_CLEANER_SUFFIX; 4023 4070 } 4024 4071 #else 4025 4072 /* merged from wine - 2002.04.21 */ 4026 4073 typedef void (*_INITTERMFUNC)(); 4027 4074 static int exp_initterm(_INITTERMFUNC *start, _INITTERMFUNC *end) 4028 4075 { 4029 dbgprintf("_initterm(0x%x, 0x%x) %p\n", start, end, *start);4076 //dbgprintf("_initterm(0x%x, 0x%x) %p\n", start, end, *start); 4030 4077 while (start < end) 4031 4078 { 4032 4079 if (*start) … … 4037 4084 void* p = *start; 4038 4085 __asm__ __volatile__ 4039 4086 ( 4087 "pushl %ebp \n\t" 4088 "movl %esp, %ebp \n\t" 4089 "andl $-16, %esp \n\t" 4090 "subl $16, %esp \n\t" ); 4091 __asm__ __volatile__ 4092 ( 4040 4093 "pushl %%ebx \n\t" 4041 4094 "pushl %%ecx \n\t" 4042 4095 "pushl %%edx \n\t" … … 4048 4101 "popl %%edx \n\t" 4049 4102 "popl %%ecx \n\t" 4050 4103 "popl %%ebx \n\t" 4104 "leave \n\t" 4051 4105 : 4052 4106 : "a"(p) 4053 4107 : "memory" … … 4068 4122 4069 4123 static int expwsprintfA(char* string, const char* format, ...) 4070 4124 { 4125 STACK_CLEANER_PREFIX; 4071 4126 va_list va; 4072 4127 int result; 4073 4128 va_start(va, format); 4074 4129 result = vsprintf(string, format, va); 4075 4130 dbgprintf("wsprintfA(0x%x, '%s', ...) => %d\n", string, format, result); 4076 4131 va_end(va); 4132 STACK_CLEANER_SUFFIX; 4077 4133 return result; 4078 4134 } 4079 4135 4080 4136 static int expsprintf(char* str, const char* format, ...) 4081 4137 { 4138 STACK_CLEANER_PREFIX; 4082 4139 va_list args; 4083 4140 int r; 4084 4141 dbgprintf("sprintf(0x%x, %s)\n", str, format); 4085 4142 va_start(args, format); 4086 4143 r = vsprintf(str, format, args); 4087 4144 va_end(args); 4145 STACK_CLEANER_SUFFIX; 4088 4146 return r; 4089 4147 } 4090 4148 static int expsscanf(const char* str, const char* format, ...) 4091 4149 { 4150 STACK_CLEANER_PREFIX; 4092 4151 va_list args; 4093 4152 int r; 4094 4153 dbgprintf("sscanf(%s, %s)\n", str, format); 4095 4154 va_start(args, format); 4096 4155 r = vsscanf(str, format, args); 4097 4156 va_end(args); 4157 STACK_CLEANER_SUFFIX; 4098 4158 return r; 4099 4159 } 4100 4160 static void* expfopen(const char* path, const char* mode) … … 4105 4165 } 4106 4166 static int expfprintf(void* stream, const char* format, ...) 4107 4167 { 4168 STACK_CLEANER_PREFIX; 4108 4169 va_list args; 4109 4170 int r = 0; 4110 4171 dbgprintf("fprintf(%p, %s, ...)\n", stream, format); … … 4113 4174 r = vfprintf((FILE*) stream, format, args); 4114 4175 va_end(args); 4115 4176 #endif 4177 STACK_CLEANER_SUFFIX; 4116 4178 return r; 4117 4179 } 4118 4180 4119 4181 static int expprintf(const char* format, ...) 4120 4182 { 4183 STACK_CLEANER_PREFIX; 4121 4184 va_list args; 4122 4185 int r; 4123 4186 dbgprintf("printf(%s, ...)\n", format); 4124 4187 va_start(args, format); 4125 4188 r = vprintf(format, args); 4126 4189 va_end(args); 4190 STACK_CLEANER_SUFFIX; 4127 4191 return r; 4128 4192 } 4129 4193 4130 4194 static char* expgetenv(const char* varname) 4131 4195 { 4196 STACK_CLEANER_PREFIX; 4132 4197 char* v = getenv(varname); 4133 4198 dbgprintf("getenv(%s) => %s\n", varname, v); 4199 STACK_CLEANER_SUFFIX; 4134 4200 return v; 4135 4201 } 4136 4202
