Пример #1
0
int touch_all(void)
{
	FILE *maps;
	unsigned long start,end,flags,size;
	char perms[STR_SIZE],dev[STR_SIZE];
	char buf[TOUCH_BUFSIZE];

	maps=fopen("/proc/self/maps","r");
	if(!maps)
	{
		perror("touch_all");
		return -1;
	}
	while(fgets(buf,TOUCH_BUFSIZE-1,maps))
	{
		if(sscanf(buf,"%8lx-%8lx %15s %lx %15s %lu",&start,&end,perms,&flags,dev,&size)<2)
			continue;
		if(perms[1] == 'w')
			touch_area((void*)start,end-start,1);
		else
			touch_area((void*)start,end-start,0);
	}
	fclose(maps);
	return 0;
}
Пример #2
0
const char *test_mapping1(void)
{
	int rc;
	
	size_t buffer1_len = BUFFER1_PAGES * PAGE_SIZE;
	size_t buffer2_len = BUFFER2_PAGES * PAGE_SIZE;
	void *buffer1 = create_as_area(buffer1_len);
	void *buffer2 = create_as_area(buffer2_len);
	if (!buffer1 || !buffer2) {
		return "Cannot allocate memory";
	}
	
	touch_area(buffer1, buffer1_len);
	touch_area(buffer2, buffer2_len);
	
	/* Now verify that mapping to physical frames exist. */
	if (!VERIFY_MAPPING(buffer1, BUFFER1_PAGES, EOK)) {
		return "Failed to find mapping (buffer1)";
	}
	if (!VERIFY_MAPPING(buffer2, BUFFER2_PAGES, EOK)) {
		return "Failed to find mapping (buffer2)";
	}
	
	/* Let's destroy the buffer1 area and access it again. */
	rc = as_area_destroy(buffer1);
	if (rc != EOK) {
		return "Failed to destroy AS area";
	}
	if (!VERIFY_MAPPING(buffer1, BUFFER1_PAGES, ENOENT)) {
		return "Mapping of destroyed area still exists";
	}
	
	/* clean-up */
	rc = as_area_destroy(buffer2);
	if (rc != EOK) {
		return "Failed to destroy AS area";
	}
	
	return NULL;
}