History

win32: register SEH in startup code (i386 only)

Needed to handle signal() etc. with msvcrt

grischka committed 16 years ago

Commit 92288421 parent 036d9414 files · +126 −2Browse files

Unified · Split

4 files
  1. win32/include/_mingw.h +2 −0
  2. win32/lib/chkstk.S +122 −0
  3. win32/lib/crt1.c +1 −2
  4. win32/lib/wincrt1.c +1 −0
win32/include/_mingw.h+2−0
@@ -70,11 +70,13 @@ · 69 unmodified lines
70#define __x86_64 170#define __x86_64 1
71#define USE_MINGW_SETJMP_TWO_ARGS71#define USE_MINGW_SETJMP_TWO_ARGS
72#define mingw_getsp tinyc_getbp72#define mingw_getsp tinyc_getbp
73#define __TRY__
73#else74#else
74#define __stdcall __attribute__((__stdcall__))75#define __stdcall __attribute__((__stdcall__))
75#define _X86_ 176#define _X86_ 1
76#define WIN32 177#define WIN32 1
77#define _USE_32BIT_TIME_T78#define _USE_32BIT_TIME_T
79#define __TRY__ void __try__(void**), *_sehrec[6]; __try__(_sehrec);
78#endif80#endif
79 81
80/* in stddef.h */82/* in stddef.h */
win32/lib/chkstk.S+122−0
@@ -75,3 +75,125 @@ t1: · 74 unmodified lines
75/* ---------------------------------------------- */75/* ---------------------------------------------- */
76#endif76#endif
77/* ---------------------------------------------- */77/* ---------------------------------------------- */
78
79
80/* ---------------------------------------------- */
81#ifndef TCC_TARGET_X86_64
82/* ---------------------------------------------- */
83
84/*
85 int _except_handler3(
86 PEXCEPTION_RECORD exception_record,
87 PEXCEPTION_REGISTRATION registration,
88 PCONTEXT context,
89 PEXCEPTION_REGISTRATION dispatcher
90 );
91
92 int __cdecl _XcptFilter(
93 unsigned long xcptnum,
94 PEXCEPTION_POINTERS pxcptinfoptrs
95 );
96
97 struct _sehrec {
98 void *esp; // 0
99 void *exception_pointers; // 1
100 void *prev; // 2
101 void *handler; // 3
102 void *scopetable; // 4
103 int trylevel; // 5
104 void *ebp // 6
105 };
106
107 // this is what the assembler code below means:
108 __try
109 {
110 // ...
111 }
112 __except (_XcptFilter(GetExceptionCode(), GetExceptionInformation()))
113 {
114 exit(GetExceptionCode());
115 }
116*/
117
118.globl _exception_info
119_exception_info:
120 mov 1*4-24(%ebp),%eax
121 ret
122
123.globl _exception_code
124_exception_code:
125 call _exception_info
126 mov (%eax),%eax
127 mov (%eax),%eax
128 ret
129
130seh_filter:
131 call _exception_info
132 push %eax
133 call _exception_code
134 push %eax
135 call _XcptFilter
136 add $ 8,%esp
137 ret
138
139seh_except:
140 mov 0*4-24(%ebp),%esp
141 call _exception_code
142 push %eax
143 call _exit
144
145// msvcrt wants scopetables aligned and in read-only segment (using .text)
146.align 4
147seh_scopetable:
148 .long -1
149 .long seh_filter
150 .long seh_except
151
152seh_handler:
153 jmp _except_handler3
154
155.globl __try__
156__try__:
157 push %ebp
158 mov 8(%esp),%ebp
159
160// void *esp;
161 lea 12(%esp),%eax
162 mov %eax,0*4(%ebp)
163
164// void *exception_pointers;
165 xor %eax,%eax
166 mov %eax,1*4(%ebp)
167
168// void *prev;
169 mov %fs:0,%eax
170 mov %eax,2*4(%ebp)
171
172// void *handler;
173 mov $ seh_handler,%eax
174 mov %eax,3*4(%ebp)
175
176// void *scopetable;
177 mov $ seh_scopetable,%eax
178 mov %eax,4*4(%ebp)
179
180// int trylevel;
181 xor %eax,%eax
182 mov %eax,5*4(%ebp)
183
184// register new SEH
185 lea 2*4(%ebp),%eax
186 mov %eax,%fs:0
187
188 pop %ebp
189 ret
190
191/* ---------------------------------------------- */
192#else
193/* ---------------------------------------------- */
194
195/* SEH on x86-64 not implemented */
196
197/* ---------------------------------------------- */
198#endif
199/* ---------------------------------------------- */
win32/lib/crt1.c+1−2
@@ -15,11 +15,11 @@ typedef struct · 14 unmodified lines
15} _startupinfo;15} _startupinfo;
16 16
17void __getmainargs(int *pargc, char ***pargv, char ***penv, int globb, _startupinfo*);17void __getmainargs(int *pargc, char ***pargv, char ***penv, int globb, _startupinfo*);
18
19int main(int argc, char **argv, char **env);18int main(int argc, char **argv, char **env);
20 19
21int _start(void)20int _start(void)
22{21{
22 __TRY__
23 int argc; char **argv; char **env; int ret;23 int argc; char **argv; char **env; int ret;
24 _startupinfo start_info = {0};24 _startupinfo start_info = {0};
25 25
@@ -32,4 +32,3 @@ int _start(void) · 6 unmodified lines
32}32}
33 33
34// =============================================34// =============================================
35
win32/lib/wincrt1.c+1−0
@@ -10,6 +10,7 @@ void _controlfp(unsigned a, unsigned b); · 9 unmodified lines
10 10
11int _winstart(void)11int _winstart(void)
12{12{
13 __TRY__
13 char *szCmd;14 char *szCmd;
14 STARTUPINFO startinfo;15 STARTUPINFO startinfo;
15 int fShow;16 int fShow;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t