| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | #include "master.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | namespace factor | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | /* Fill in a PPC function descriptor */ | 
					
						
							|  |  |  | void *fill_function_descriptor(void *ptr, void *code) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	void **descriptor = (void **)ptr; | 
					
						
							|  |  |  | 	descriptor[0] = code; | 
					
						
							|  |  |  | 	descriptor[1] = NULL; | 
					
						
							|  |  |  | 	descriptor[2] = NULL; | 
					
						
							|  |  |  | 	return descriptor; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Get a field from a PPC function descriptor */ | 
					
						
							|  |  |  | void *function_descriptor_field(void *ptr, size_t idx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return ptr ? ((void **) ptr)[idx] : ptr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | /* If memory allocation fails, bail out */ | 
					
						
							| 
									
										
										
										
											2009-08-25 03:20:58 -04:00
										 |  |  | vm_char *safe_strdup(const vm_char *str) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	vm_char *ptr = STRDUP(str); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	if(!ptr) fatal_error("Out of memory in safe_strdup", 0); | 
					
						
							|  |  |  | 	return ptr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-25 03:20:58 -04:00
										 |  |  | cell read_cell_hex() | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell cell; | 
					
						
							| 
									
										
										
										
											2010-08-01 19:14:20 -04:00
										 |  |  | 	std::cin >> std::hex >> cell >> std::dec; | 
					
						
							|  |  |  | 	if(!std::cin.good()) exit(1); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	return cell; | 
					
						
							| 
									
										
										
										
											2009-08-17 16:37:09 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-07 01:31:15 -05:00
										 |  |  | /* On Windows, memcpy() is in a different DLL and the non-optimizing
 | 
					
						
							|  |  |  | compiler can't find it */ | 
					
						
							|  |  |  | VM_C_API void *factor_memcpy(void *dst, void *src, size_t len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return memcpy(dst,src,len); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | } |