| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | #include "master.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | namespace factor | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-05 12:33:35 -04:00
										 |  |  | s64 current_micros() | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	FILETIME t; | 
					
						
							|  |  |  | 	GetSystemTimeAsFileTime(&t); | 
					
						
							|  |  |  | 	return (((s64)t.dwLowDateTime | (s64)t.dwHighDateTime<<32) | 
					
						
							|  |  |  | 		- EPOCH_OFFSET) / 10; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-05 15:17:02 -04:00
										 |  |  | FACTOR_STDCALL LONG exception_handler(PEXCEPTION_POINTERS pe) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	PEXCEPTION_RECORD e = (PEXCEPTION_RECORD)pe->ExceptionRecord; | 
					
						
							|  |  |  | 	CONTEXT *c = (CONTEXT*)pe->ContextRecord; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(in_code_heap_p(c->EIP)) | 
					
						
							| 
									
										
										
										
											2009-05-05 14:03:24 -04:00
										 |  |  | 		signal_callstack_top = (stack_frame *)c->ESP; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		signal_callstack_top = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(e->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		signal_fault_addr = e->ExceptionInformation[1]; | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		c->EIP = (cell)memory_signal_handler_impl; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	/* If the Widcomm bluetooth stack is installed, the BTTray.exe process
 | 
					
						
							|  |  |  | 	injects code into running programs. For some reason this results in | 
					
						
							|  |  |  | 	random SEH exceptions with this (undocumented) exception code being | 
					
						
							|  |  |  | 	raised. The workaround seems to be ignoring this altogether, since that | 
					
						
							|  |  |  | 	is what happens if SEH is not enabled. Don't really have any idea what | 
					
						
							|  |  |  | 	this exception means. */ | 
					
						
							|  |  |  | 	else if(e->ExceptionCode != 0x40010006) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		signal_number = e->ExceptionCode; | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		c->EIP = (cell)misc_signal_handler_impl; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return EXCEPTION_CONTINUE_EXECUTION; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void c_to_factor_toplevel(cell quot) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-05 15:17:02 -04:00
										 |  |  | 	if(!AddVectoredExceptionHandler(0, (PVECTORED_EXCEPTION_HANDLER)exception_handler)) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		fatal_error("AddVectoredExceptionHandler failed", 0); | 
					
						
							|  |  |  | 	c_to_factor(quot); | 
					
						
							| 
									
										
										
										
											2009-05-05 15:17:02 -04:00
										 |  |  | 	RemoveVectoredExceptionHandler((void *)exception_handler); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-05 12:33:35 -04:00
										 |  |  | void open_console() | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |