Fix SGX simulation mode broken by the interrupt subsystem
The new interrupt subsystem breaks the simulation mode in two ways: 1. The signal 64 is not handled by Intel SGX SDK in simulation mode. A handled real-time signal crashes the process. 2. The newly-enabled test case exit_group depends on interrupts. But enclave interrupts, like enclave exceptions, are not supported in simulation mode. This commit ensures signal 64 is ignored by default and exit_group test case is not enabled in simulation mode.
This commit is contained in:
		
							parent
							
								
									3382a68807
								
							
						
					
					
						commit
						a3ad465ce3
					
				| @ -4,6 +4,7 @@ | ||||
| #include "pal_error.h" | ||||
| #include "pal_interrupt_thread.h" | ||||
| #include "pal_log.h" | ||||
| #include "pal_sig_handler.h" | ||||
| #include "pal_syscall.h" | ||||
| #include "pal_thread_counter.h" | ||||
| #include "errno2str.h" | ||||
| @ -29,6 +30,10 @@ int occlum_pal_init(const struct occlum_pal_attr *attr) { | ||||
|         return -1; | ||||
|     } | ||||
| 
 | ||||
|     if (pal_register_sig_handlers() < 0) { | ||||
|         return -1; | ||||
|     } | ||||
| 
 | ||||
|     if (pal_init_enclave(attr->instance_dir) < 0) { | ||||
|         return -1; | ||||
|     } | ||||
|  | ||||
							
								
								
									
										19
									
								
								src/pal/src/pal_sig_handler.c
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										19
									
								
								src/pal/src/pal_sig_handler.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| #include "pal_sig_handler.h" | ||||
| #include "pal_log.h" | ||||
| #include <signal.h> | ||||
| #include <string.h> | ||||
| 
 | ||||
| // Signal 64 is used to notify interrupts
 | ||||
| #define SIGRT_INTERRUPT     64 | ||||
| 
 | ||||
| int pal_register_sig_handlers(void) { | ||||
|     struct sigaction action; | ||||
|     action.sa_handler = SIG_IGN; | ||||
|     memset(&action.sa_mask, 0, sizeof(action.sa_mask)); | ||||
|     action.sa_flags = 0; | ||||
|     if (sigaction(SIGRT_INTERRUPT, &action, NULL) < 0) { | ||||
|         PAL_ERROR("Failed to regiter signal handlers"); | ||||
|         return -1; | ||||
|     } | ||||
|     return 0; | ||||
| } | ||||
							
								
								
									
										15
									
								
								src/pal/src/pal_sig_handler.h
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										15
									
								
								src/pal/src/pal_sig_handler.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| #ifndef __PAL_SIG_HANDLER_H__ | ||||
| #define __PAL_SIG_HANDLER_H__ | ||||
| 
 | ||||
| // Register signal handlers for PAL.
 | ||||
| //
 | ||||
| // Currently, there is only one signal number that needs to be covered: signal
 | ||||
| // 64, which is used to notify interrupts (see LibOS code for more info). For
 | ||||
| // a hardware-mode enclave, the signal is handled by the signal handlers
 | ||||
| // registered by Intel SGX SDK. So we are ok in this case. But for a
 | ||||
| // simulation-mode enclave, there is no signal handler registered by Intel SGX
 | ||||
| // SDK. Without a signal handler, the delivery of the signal will kill the
 | ||||
| // process. This crash can be prevented by this API.
 | ||||
| int pal_register_sig_handlers(void); | ||||
| 
 | ||||
| #endif /* __PAL_SIG_HANDLER_H__ */ | ||||
| @ -38,6 +38,11 @@ static void *futex_wait_thread_func(void *_) { | ||||
| 
 | ||||
| // exit_group syscall should terminate all threads in a thread group.
 | ||||
| int test_exit_group_to_force_threads_terminate(void) { | ||||
| #ifdef SGX_MODE_SIM | ||||
|     printf("WARNING: Skip this test case as we do not support " | ||||
|            "enclave interruption in SGX simulation mode\n"); | ||||
|     return 0; | ||||
| #else | ||||
|     // Create three types of threads that will not exit voluntarily
 | ||||
|     pthread_t busyloop_thread; | ||||
|     if (pthread_create(&busyloop_thread, NULL, busyloop_thread_func, NULL) < 0) { | ||||
| @ -63,6 +68,7 @@ int test_exit_group_to_force_threads_terminate(void) { | ||||
|     // main function returns. If Occlum can terminate normally, this means
 | ||||
|     // exit_group syscall taking effect.
 | ||||
|     return 0; | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| // ============================================================================
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user