vm: allocate stacks and data heap segments without execute permissions
							parent
							
								
									85b746e7b5
								
							
						
					
					
						commit
						c04412219b
					
				|  | @ -3,7 +3,7 @@ | ||||||
| namespace factor | namespace factor | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
| code_heap::code_heap(bool secure_gc, cell size) : heap(secure_gc,size) {} | code_heap::code_heap(bool secure_gc, cell size) : heap(secure_gc,size,true) {} | ||||||
| 
 | 
 | ||||||
| void code_heap::write_barrier(code_block *compiled) | void code_heap::write_barrier(code_block *compiled) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -44,8 +44,8 @@ context *factor_vm::alloc_context() | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		new_context = new context; | 		new_context = new context; | ||||||
| 		new_context->datastack_region = new segment(ds_size); | 		new_context->datastack_region = new segment(ds_size,false); | ||||||
| 		new_context->retainstack_region = new segment(rs_size); | 		new_context->retainstack_region = new segment(rs_size,false); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return new_context; | 	return new_context; | ||||||
|  |  | ||||||
|  | @ -23,7 +23,7 @@ data_heap::data_heap(cell young_size_, cell aging_size_, cell tenured_size_) | ||||||
| 
 | 
 | ||||||
| 	total_size += deck_size; | 	total_size += deck_size; | ||||||
| 
 | 
 | ||||||
| 	seg = new segment(total_size); | 	seg = new segment(total_size,false); | ||||||
| 
 | 
 | ||||||
| 	cell cards_size = addr_to_card(total_size); | 	cell cards_size = addr_to_card(total_size); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -11,10 +11,10 @@ void heap::clear_free_list() | ||||||
| 	memset(&free,0,sizeof(heap_free_list)); | 	memset(&free,0,sizeof(heap_free_list)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| heap::heap(bool secure_gc_, cell size) : secure_gc(secure_gc_) | heap::heap(bool secure_gc_, cell size, bool executable_p) : secure_gc(secure_gc_) | ||||||
| { | { | ||||||
| 	if(size > (1L << (sizeof(cell) * 8 - 6))) fatal_error("Heap too large",size); | 	if(size > (1L << (sizeof(cell) * 8 - 6))) fatal_error("Heap too large",size); | ||||||
| 	seg = new segment(align_page(size)); | 	seg = new segment(align_page(size),executable_p); | ||||||
| 	if(!seg) fatal_error("Out of memory in heap allocator",size); | 	if(!seg) fatal_error("Out of memory in heap allocator",size); | ||||||
| 	clear_free_list(); | 	clear_free_list(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ struct heap { | ||||||
| 	heap_free_list free; | 	heap_free_list free; | ||||||
| 	unordered_map<heap_block *, char *> forwarding; | 	unordered_map<heap_block *, char *> forwarding; | ||||||
| 
 | 
 | ||||||
| 	explicit heap(bool secure_gc_, cell size); | 	explicit heap(bool secure_gc_, cell size, bool executable_p); | ||||||
| 
 | 
 | ||||||
| 	inline heap_block *next_block(heap_block *block) | 	inline heap_block *next_block(heap_block *block) | ||||||
| 	{ | 	{ | ||||||
|  |  | ||||||
|  | @ -83,16 +83,19 @@ void factor_vm::primitive_existsp() | ||||||
| 	box_boolean(stat(path,&sb) >= 0); | 	box_boolean(stat(path,&sb) >= 0); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| segment::segment(cell size_) | segment::segment(cell size_, bool executable_p) | ||||||
| { | { | ||||||
| 	size = size_; | 	size = size_; | ||||||
| 
 | 
 | ||||||
| 	int pagesize = getpagesize(); | 	int pagesize = getpagesize(); | ||||||
| 
 | 
 | ||||||
| 	char *array = (char *)mmap(NULL,pagesize + size + pagesize, | 	int prot; | ||||||
| 		PROT_READ | PROT_WRITE | PROT_EXEC, | 	if(executable_p) | ||||||
| 		MAP_ANON | MAP_PRIVATE,-1,0); | 		prot = (PROT_READ | PROT_WRITE | PROT_EXEC); | ||||||
|  | 	else | ||||||
|  | 		prot = (PROT_READ | PROT_WRITE); | ||||||
| 
 | 
 | ||||||
|  | 	char *array = (char *)mmap(NULL,pagesize + size + pagesize,prot,MAP_ANON | MAP_PRIVATE,-1,0); | ||||||
| 	if(array == (char*)-1) out_of_memory(); | 	if(array == (char*)-1) out_of_memory(); | ||||||
| 
 | 
 | ||||||
| 	if(mprotect(array,pagesize,PROT_NONE) == -1) | 	if(mprotect(array,pagesize,PROT_NONE) == -1) | ||||||
|  |  | ||||||
|  | @ -96,7 +96,7 @@ void factor_vm::primitive_existsp() | ||||||
| 	box_boolean(windows_stat(path)); | 	box_boolean(windows_stat(path)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| segment::segment(cell size_) | segment::segment(cell size_, bool executable_p) | ||||||
| { | { | ||||||
| 	size = size_; | 	size = size_; | ||||||
| 
 | 
 | ||||||
|  | @ -104,7 +104,7 @@ segment::segment(cell size_) | ||||||
| 	DWORD ignore; | 	DWORD ignore; | ||||||
| 
 | 
 | ||||||
| 	if((mem = (char *)VirtualAlloc(NULL, getpagesize() * 2 + size, | 	if((mem = (char *)VirtualAlloc(NULL, getpagesize() * 2 + size, | ||||||
| 		MEM_COMMIT, PAGE_EXECUTE_READWRITE)) == 0) | 		MEM_COMMIT, executable_p ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE)) == 0) | ||||||
| 		out_of_memory(); | 		out_of_memory(); | ||||||
| 
 | 
 | ||||||
| 	if (!VirtualProtect(mem, getpagesize(), PAGE_NOACCESS, &ignore)) | 	if (!VirtualProtect(mem, getpagesize(), PAGE_NOACCESS, &ignore)) | ||||||
|  |  | ||||||
|  | @ -13,7 +13,7 @@ struct segment { | ||||||
| 	cell size; | 	cell size; | ||||||
| 	cell end; | 	cell end; | ||||||
| 
 | 
 | ||||||
| 	explicit segment(cell size); | 	explicit segment(cell size, bool executable_p); | ||||||
| 	~segment(); | 	~segment(); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue