Explorar el Código

[comboot] Restore the real-mode stack pointer on exit from a COMBOOT image

COMBOOT images use INTs to issue API calls; these end up making calls
into gPXE from real mode, and so temporarily change the real-mode
stack pointer.  When our COMBOOT code uses a longjmp() to implement
the various "exit COMBOOT image" API calls, this leaves the real-mode
stack pointer stuck with its temporary value, which causes problems if
we eventually try to exit out of gPXE back to the BIOS.

Fix by adding rmsetjmp() and rmlongjmp() calls (analogous to
sigsetjmp()/siglongjmp()); these save and restore the additional state
needed for real-mode calls to function correctly.
tags/v0.9.7
Michael Brown hace 15 años
padre
commit
5026a35fef

+ 1
- 1
src/arch/i386/image/com32.c Ver fichero

@@ -52,7 +52,7 @@ static int com32_exec ( struct image *image ) {
52 52
 	int state;
53 53
 	uint32_t avail_mem_top;
54 54
 
55
-	state = setjmp ( comboot_return );
55
+	state = rmsetjmp ( comboot_return );
56 56
 
57 57
 	switch ( state ) {
58 58
 	case 0: /* First time through; invoke COM32 program */

+ 1
- 1
src/arch/i386/image/comboot.c Ver fichero

@@ -133,7 +133,7 @@ static int comboot_exec ( struct image *image ) {
133 133
 	userptr_t seg_userptr = real_to_user ( COMBOOT_PSP_SEG, 0 );
134 134
 	int state;
135 135
 
136
-	state = setjmp ( comboot_return );
136
+	state = rmsetjmp ( comboot_return );
137 137
 
138 138
 	switch ( state ) {
139 139
 	case 0: /* First time through; invoke COMBOOT program */

+ 1
- 1
src/arch/i386/include/comboot.h Ver fichero

@@ -78,7 +78,7 @@ extern void com32_cfarcall_wrapper ( );
78 78
 extern int comboot_resolv ( const char *name, struct in_addr *address );
79 79
 
80 80
 /* setjmp/longjmp context buffer used to return after loading an image */
81
-extern jmp_buf comboot_return;
81
+extern rmjmp_buf comboot_return;
82 82
 
83 83
 /* Replacement image when exiting with COMBOOT_EXIT_RUN_KERNEL */
84 84
 extern struct image *comboot_replacement_image;

+ 31
- 5
src/arch/i386/include/setjmp.h Ver fichero

@@ -1,12 +1,38 @@
1 1
 #ifndef ETHERBOOT_SETJMP_H
2 2
 #define ETHERBOOT_SETJMP_H
3 3
 
4
+#include <stdint.h>
5
+#include <realmode.h>
4 6
 
5
-/* Define a type for use by setjmp and longjmp */
6
-#define JBLEN 6
7
-typedef unsigned long jmp_buf[JBLEN];
7
+/** A jump buffer */
8
+typedef struct {
9
+	uint32_t retaddr;
10
+	uint32_t ebx;
11
+	uint32_t esp;
12
+	uint32_t ebp;
13
+	uint32_t esi;
14
+	uint32_t edi;
15
+} jmp_buf[1];
8 16
 
9
-extern int __asmcall setjmp (jmp_buf env);
10
-extern void __asmcall longjmp (jmp_buf env, int val);
17
+/** A real-mode-extended jump buffer */
18
+typedef struct {
19
+	jmp_buf env;
20
+	uint16_t rm_ss;
21
+	uint16_t rm_sp;
22
+} rmjmp_buf[1];
23
+
24
+extern int __asmcall setjmp ( jmp_buf env );
25
+extern void __asmcall longjmp ( jmp_buf env, int val );
26
+
27
+#define rmsetjmp( _env ) ( {			\
28
+	(_env)->rm_ss = rm_ss;			\
29
+	(_env)->rm_sp = rm_sp;			\
30
+	setjmp ( (_env)->env ); } )		\
31
+
32
+#define rmlongjmp( _env, _val ) do {		\
33
+	rm_ss = (_env)->rm_ss;			\
34
+	rm_sp = (_env)->rm_sp;			\
35
+	longjmp ( (_env)->env, (_val) );	\
36
+	} while ( 0 )
11 37
 
12 38
 #endif /* ETHERBOOT_SETJMP_H */

+ 6
- 6
src/arch/i386/interface/syslinux/comboot_call.c Ver fichero

@@ -67,7 +67,7 @@ extern void int21_wrapper ( void );
67 67
 extern void int22_wrapper ( void );
68 68
 
69 69
 /* setjmp/longjmp context buffer used to return after loading an image */
70
-jmp_buf comboot_return;
70
+rmjmp_buf comboot_return;
71 71
 
72 72
 /* Replacement image when exiting with COMBOOT_EXIT_RUN_KERNEL */
73 73
 struct image *comboot_replacement_image;
@@ -235,7 +235,7 @@ static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
235 235
  * Terminate program interrupt handler
236 236
  */
237 237
 static __asmcall void int20 ( struct i386_all_regs *ix86 __unused ) {
238
-	longjmp ( comboot_return, COMBOOT_EXIT );
238
+	rmlongjmp ( comboot_return, COMBOOT_EXIT );
239 239
 }
240 240
 
241 241
 
@@ -248,7 +248,7 @@ static __asmcall void int21 ( struct i386_all_regs *ix86 ) {
248 248
 	switch ( ix86->regs.ah ) {
249 249
 	case 0x00:
250 250
 	case 0x4C: /* Terminate program */
251
-		longjmp ( comboot_return, COMBOOT_EXIT );
251
+		rmlongjmp ( comboot_return, COMBOOT_EXIT );
252 252
 		break;
253 253
 
254 254
 	case 0x01: /* Get Key with Echo */
@@ -347,13 +347,13 @@ static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
347 347
 			DBG ( "COMBOOT: executing command '%s'\n", cmd );
348 348
 			system ( cmd );
349 349
 			DBG ( "COMBOOT: exiting after executing command...\n" );
350
-			longjmp ( comboot_return, COMBOOT_EXIT_COMMAND );
350
+			rmlongjmp ( comboot_return, COMBOOT_EXIT_COMMAND );
351 351
 		}
352 352
 		break;
353 353
 
354 354
 	case 0x0004: /* Run default command */
355 355
 		/* FIXME: just exit for now */
356
-		longjmp ( comboot_return, COMBOOT_EXIT_COMMAND );
356
+		rmlongjmp ( comboot_return, COMBOOT_EXIT_COMMAND );
357 357
 		break;
358 358
 
359 359
 	case 0x0005: /* Force text mode */
@@ -552,7 +552,7 @@ static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
552 552
 			 * part of the COMBOOT program's memory space.
553 553
 			 */
554 554
 			DBG ( "COMBOOT: exiting to run kernel...\n" );
555
-			longjmp ( comboot_return, COMBOOT_EXIT_RUN_KERNEL );
555
+			rmlongjmp ( comboot_return, COMBOOT_EXIT_RUN_KERNEL );
556 556
 		}
557 557
 		break;
558 558
 

Loading…
Cancelar
Guardar