void free_call_d(int line, const char *file_name, const char *function,
		 void *addr)
{

	struct mlist_t *list = find_list(file_name);
	if (!rm_malloc(list, addr)) {
		list = files_list;
		while (list != NULL) {
			if (rm_malloc(list, addr)) {
				free(addr);
				return;
			}
			list = list->next;
		}

	} else {
		logi("free addr 0x%08lX (%d:%s '%s')\n",
		     addr, line, function, file_name);
		free(addr);
		return;
	}
	LOGW("cannot free element!!! 0x%08lX (%d:%s '%s')\n",
	     addr, line, function, file_name);

}
Exemple #2
0
void* mymalloc(size_t s) {
  void* res;
  static char* ptr = NULL;
  static char* limit = NULL;
  if (ptr == NULL) {
    ptr = (char*)rm_malloc(MAX);
    if (ptr == NULL) exit(printf("[mymalloc] rm_malloc error\n"));
    limit = ptr + MAX;
  }
  if (ptr == limit) exit(printf("[mymalloc] Out of memory error\n"));
  res = (void*)ptr;
  ptr += s;
  return res;
}
Exemple #3
0
int main() {
	size_t shadow_rec_size = 32;
	size_t shadow_wordsize = 4;
	
	int* prot_array;
	int* unprot_array;
	
	double prot_write_times;
	double prot_read_times;
	double unprot_write_times;
	double unprot_read_times;
	
	struct timeval tvBeginProtWrite, tvEndProtWrite;
	struct timeval tvBeginProtRead, tvEndProtRead;
	struct timeval tvBeginUnprotWrite, tvEndUnprotWrite;
	struct timeval tvBeginUnprotRead, tvEndUnprotRead;
	
	int i, value;
	
	printf("MAIN - start\n");
	
	/*initializes rm*/
	if (rm_init(read_handler, write_handler, NULL, NULL, shadow_rec_size, shadow_wordsize) == -1) {
		printf("main: rm_init error!!\n");
		return -1;
	}
	
	printf("N is %d\n", N);
	
	/*allocates protected mem*/
	prot_array = (int*)rm_malloc(N * sizeof(int));
	if(prot_array == NULL)
		printf("[main] ERROR: Could not allocate protected mem!\n");
	
	/*allocates unprotected mem*/
	unprot_array = (int*)malloc(N * sizeof(int));
	if(unprot_array == NULL)
		printf("[main] ERROR: Could not allocate unprotected mem!\n");
	
	
	/* PROTECTED WRITE LOOP */
	printf("Protected write loop\n");
	/*fetches initial time*/
	gettimeofday(&tvBeginProtWrite, NULL);
	/*performs N writes to prot mem*/
	for(i=0; i<N; i++) {
		/*performs access*/
		*(prot_array + i) = i;
	}
	/*fetches final time*/
	gettimeofday(&tvEndProtWrite, NULL);
	prot_write_times = tvEndProtWrite.tv_sec + (tvEndProtWrite.tv_usec*0.000001)
			-tvBeginProtWrite.tv_sec - (tvBeginProtWrite.tv_usec*0.000001);
	
	/* UNPROTECTED WRITE LOOP */
	printf("Unprotected write loop\n");
	/*fetches initial time*/
	gettimeofday(&tvBeginUnprotWrite, NULL);
	/*performs N writes to unprot mem*/
	for(i=0; i<N; i++) {
		/*performs access*/
		*(unprot_array + i) = i;
	}
	/*fetches final time*/
	gettimeofday(&tvEndUnprotWrite, NULL);
	unprot_write_times = tvEndUnprotWrite.tv_sec + (tvEndUnprotWrite.tv_usec*0.000001)
			-tvBeginUnprotWrite.tv_sec - (tvBeginUnprotWrite.tv_usec*0.000001);
	
	/* PROTECTED READ LOOP */
	printf("Protected read loop\n");
	/*fetches initial time*/
	gettimeofday(&tvBeginProtRead, NULL);
	/*performs N reads from prot mem*/
	for(i=0; i<N; i++) {
		/*performs access*/
		value = *(prot_array + i);
	}
	/*fetches final time*/
	gettimeofday(&tvEndProtRead, NULL);
	prot_read_times = tvEndProtRead.tv_sec + (tvEndProtRead.tv_usec*0.000001)
			-tvBeginProtRead.tv_sec - (tvBeginProtRead.tv_usec*0.000001);
	
	/* UNPROTECTED READ LOOP */
	printf("Unprotected read loop\n");
	/*fetches initial time*/
	gettimeofday(&tvBeginUnprotRead, NULL);
	/*performs N reads from unprot mem*/
	for(i=0; i<N; i++) {
		/*performs access*/
		value = *(unprot_array + i);
	}
	/*fetches final time*/
	gettimeofday(&tvEndUnprotRead, NULL);
	unprot_read_times = tvEndUnprotRead.tv_sec + (tvEndUnprotRead.tv_usec*0.000001)
			-tvBeginUnprotRead.tv_sec - (tvBeginUnprotRead.tv_usec*0.000001);
	
	
	/*prints debug controls*/
	printf("\n*** DEBUG ***\n");
	printf("write_num = %d\n", write_num);
	printf("read_num = %d\n", read_num);
	printf("*(prot_array) = %d\n", *(prot_array));
	printf("*(prot_array + 5) = %d\n", *(prot_array + 5));
	printf("*(prot_array + N - 1) = %d\n", *(prot_array + N - 1));
	
	/*prints results*/
	printf("\n*** RESULTS ***\n");
	printf("Seconds taken for %d protected writes: %f\n", N, prot_write_times);
	printf("Seconds taken for %d unprotected writes: %f\n", N, unprot_write_times);
	printf("Seconds taken for %d protected reads: %f\n", N, prot_read_times);
	printf("Seconds taken for %d unprotected reads: %f\n", N, unprot_read_times);
	printf("Ratio between prot and unprot writes: %f\n", prot_write_times/unprot_write_times);
	printf("Ratio between prot and unprot reads: %f\n", prot_read_times/unprot_read_times);
	
	/*clean up*/
	rm_free(prot_array);
	free(unprot_array);
	
	printf("MAIN - end\n");
	
	return 0;
}
Exemple #4
0
int main() {
	size_t shadow_rec_size = 32;
	size_t shadow_wordsize = 4;
	
	printf("MAIN - start\n");
	
	if (rm_init(read_handler, write_handler, NULL, NULL, shadow_rec_size, shadow_wordsize) == -1) {
		printf("main: rm_init error!!\n");
		return -1;
	}
	
#if rm_DEBUG == 1
	if (rm_make_dump_file("dump1.txt") == -1) {
		printf("main: rm_make_dump_file error!!\n");
		return -1;
	}
#endif
	
#if rm_STAT == 1
	printf("\n\n\n*** STATS - start ***\n");
	printf("g_stats.patch_instr_number = %u\n", g_stats.patch_instr_number);
	printf("g_stats.cache_instr_number = %u\n", g_stats.cache_instr_number);
	printf("g_stats.BB_number = %u\n", g_stats.BB_number);
	printf("g_stats.BB_min_size = %u\n", g_stats.BB_min_size);
	printf("g_stats.BB_med_size = %u\n", g_stats.BB_med_size);
	printf("g_stats.BB_max_size = %u\n", g_stats.BB_max_size);
	printf("g_stats.BB_min_instr_number = %u\n", g_stats.BB_min_instr_number);
	printf("g_stats.BB_med_instr_number = %u\n", g_stats.BB_med_instr_number);
	printf("g_stats.BB_max_instr_number = %u\n", g_stats.BB_max_instr_number);
	printf("*** STATS - end ***\n");
#endif
	
	int* a;
	int b;
	a = (int*)rm_malloc(sizeof(int));
	printf("\n\n\n");
	printf("Puntatore a = %p\n", a);
	printf("Puntatore rm_get_inactive_ptr(a) = %p\n", rm_get_inactive_ptr(a));
	printf("rm_is_reactive(a) = %d\n", rm_is_reactive(a));
	printf("rm_is_reactive(rm_get_inactive_ptr(a)) = %d\n", rm_is_reactive(rm_get_inactive_ptr(a)));
	printf("rm_get_shadow_rec(a) = %p\n", rm_get_shadow_rec(a));
	
	printf("*** Scrittura ***\n");
	*a = 5;
	printf("*** Lettura ***\n");
	b = *a;
	printf("b = %d\n", b);
	
#if rm_DEBUG == 1
	if (rm_make_dump_file("dump2.txt") == -1) {
		printf("main: rm_make_dump_file error!!\n");
		return -1;
	}
#endif
	
	
	
	printf("MAIN - end\n");
	
	return 0;
}