Kernel: align userspace stacks
I was getting #GP on sse instructions
This commit is contained in:
		
							parent
							
								
									e715d52f80
								
							
						
					
					
						commit
						20eafb4cc4
					
				|  | @ -2,6 +2,11 @@ | ||||||
| 
 | 
 | ||||||
| #include <sys/syscall.h> | #include <sys/syscall.h> | ||||||
| 
 | 
 | ||||||
|  | // stack contains | ||||||
|  | //    return address | ||||||
|  | //    signal number | ||||||
|  | //    signal handler | ||||||
|  | 
 | ||||||
| .global signal_trampoline
 | .global signal_trampoline
 | ||||||
| signal_trampoline: | signal_trampoline: | ||||||
| 	pushq %rax | 	pushq %rax | ||||||
|  | @ -20,6 +25,8 @@ signal_trampoline: | ||||||
| 	pushq %r14 | 	pushq %r14 | ||||||
| 	pushq %r15 | 	pushq %r15 | ||||||
| 
 | 
 | ||||||
|  | 	// This is 16 byte aligned | ||||||
|  | 
 | ||||||
| 	movq 128(%rsp), %rdi | 	movq 128(%rsp), %rdi | ||||||
| 	movq 120(%rsp), %rax | 	movq 120(%rsp), %rax | ||||||
| 	call *%rax | 	call *%rax | ||||||
|  | @ -46,4 +53,5 @@ signal_trampoline: | ||||||
| 
 | 
 | ||||||
| 	addq $16, %rsp | 	addq $16, %rsp | ||||||
| 
 | 
 | ||||||
| 	ret | 	// return over red-zone | ||||||
|  | 	ret $128 | ||||||
|  |  | ||||||
|  | @ -83,6 +83,7 @@ namespace Kernel | ||||||
| 		thread->m_rip = (uintptr_t)entry; | 		thread->m_rip = (uintptr_t)entry; | ||||||
| 
 | 
 | ||||||
| 		// Initialize stack for returning
 | 		// Initialize stack for returning
 | ||||||
|  | 		write_to_stack(thread->m_rsp, nullptr); // alignment
 | ||||||
| 		write_to_stack(thread->m_rsp, thread); | 		write_to_stack(thread->m_rsp, thread); | ||||||
| 		write_to_stack(thread->m_rsp, &Thread::on_exit); | 		write_to_stack(thread->m_rsp, &Thread::on_exit); | ||||||
| 		write_to_stack(thread->m_rsp, data); | 		write_to_stack(thread->m_rsp, data); | ||||||
|  | @ -179,6 +180,7 @@ namespace Kernel | ||||||
| 		{ | 		{ | ||||||
| 			// FIXME: don't use PageTableScope
 | 			// FIXME: don't use PageTableScope
 | ||||||
| 			PageTableScope _(process().page_table()); | 			PageTableScope _(process().page_table()); | ||||||
|  | 			write_to_stack(m_rsp, nullptr); // alignment
 | ||||||
| 			write_to_stack(m_rsp, this); | 			write_to_stack(m_rsp, this); | ||||||
| 			write_to_stack(m_rsp, &Thread::on_exit); | 			write_to_stack(m_rsp, &Thread::on_exit); | ||||||
| 			write_to_stack(m_rsp, nullptr); | 			write_to_stack(m_rsp, nullptr); | ||||||
|  | @ -206,6 +208,7 @@ namespace Kernel | ||||||
| 		{ | 		{ | ||||||
| 			// FIXME: don't use PageTableScope
 | 			// FIXME: don't use PageTableScope
 | ||||||
| 			PageTableScope _(process().page_table()); | 			PageTableScope _(process().page_table()); | ||||||
|  | 			write_to_stack(m_rsp, nullptr); // alignment
 | ||||||
| 			write_to_stack(m_rsp, this); | 			write_to_stack(m_rsp, this); | ||||||
| 			write_to_stack(m_rsp, &Thread::on_exit); | 			write_to_stack(m_rsp, &Thread::on_exit); | ||||||
| 			write_to_stack(m_rsp, m_process); | 			write_to_stack(m_rsp, m_process); | ||||||
|  | @ -275,6 +278,7 @@ namespace Kernel | ||||||
| 			// FIXME: signal trampoline should take a hash etc
 | 			// FIXME: signal trampoline should take a hash etc
 | ||||||
| 			//        to only allow marking signals done from it
 | 			//        to only allow marking signals done from it
 | ||||||
| 			m_handling_signal = signal; | 			m_handling_signal = signal; | ||||||
|  | 			return_rsp += 128; // skip possible red-zone
 | ||||||
| 			write_to_stack(return_rsp, return_rip); | 			write_to_stack(return_rsp, return_rip); | ||||||
| 			write_to_stack(return_rsp, signal); | 			write_to_stack(return_rsp, signal); | ||||||
| 			write_to_stack(return_rsp, signal_handler); | 			write_to_stack(return_rsp, signal_handler); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue