Example #1
0
void CopyVmaInfo(struct mm_struct *memStr)
{
	memStr->fileStartPointer = currentTask->memMap->fileStartPointer;

	struct vm_area_struct* current = currentTask->memMap->head;
	
	struct vm_area_struct* prev = NULL;

	while(current!= NULL)
	{
		struct vm_area_struct* newVma  = (struct vm_area_struct *)AllocateVirtualMemory();
		if(prev != NULL)
			{
				prev->vm_next = newVma;
			}
			else
			{
				memStr->head = newVma;
			}	
		newVma->vm_start = current->vm_start ;
		newVma->sectionOffset= current->sectionOffset;
		newVma->vm_end = current->vm_end;
		newVma->vm_next = NULL;
		prev = newVma ;
		newVma->permFlags =  current->permFlags;
		
		current = current->vm_next;
	}
}
Example #2
0
uint64_t ReadElf(struct mm_struct *memStr,char *fileName)
{

	char *start = ReadFile(fileName);
	uint64_t rip= -1;

	struct Exe_Format exeFormat;
	memStr->fileStartPointer = (uint64_t)start;
	rip= Parse_ELF_Executable( start , &exeFormat);
    	if (rip!= -1) 
	{
		int i =0;

		struct vm_area_struct* prev = NULL;
		for(i=0;i<exeFormat.numSegments;i++)
		{
			if(exeFormat.segmentList[i].sizeInMemory > 0)
			{
			 struct vm_area_struct* newVma  = (struct vm_area_struct *)AllocateVirtualMemory();
			 if(prev != NULL)
				{
					prev->vm_next = newVma;
				}
				else
				{
					memStr->head = newVma;
				}	
			 newVma->vm_start = exeFormat.segmentList[i].startAddress;
			 newVma->sectionOffset= exeFormat.segmentList[i].offsetInFile;
                      newVma->copySize =  exeFormat.segmentList[i].lengthInFile;
			 newVma->vm_end = newVma->vm_start +  exeFormat.segmentList[i].sizeInMemory;
			 newVma->permFlags = exeFormat.segmentList[i].protFlags;
			 newVma->vm_next = NULL;
			 prev = newVma ;
			}

		}
	}
		
	return rip;
}
Example #3
0
void * mmap(void *addr,uint64_t noPages)
{

struct vm_area_struct * temp = currentTask->memMap->head;
while(temp->vm_next != NULL)
temp = temp->vm_next;

struct vm_area_struct * newVMA=(struct vm_area_struct*)AllocateVirtualMemory();

newVMA->vm_start = sbrk;
newVMA->vm_end = sbrk + noPages*PAGE_SIZE;                                                                                                                                   
newVMA->vm_next = NULL;
newVMA->sectionOffset = -1; 
newVMA->permFlags = 3;
temp->vm_next = newVMA;

sbrk  = newVMA->vm_end;

return (void*)newVMA->vm_start;

 }
struct File* getFile(const char *fileName)
{
    struct posix_header_ustar * entry = (struct posix_header_ustar*)(&_binary_tarfs_start);
	int padding =0;
	errno = 0;
	struct File* file = (struct File *)AllocateVirtualMemory();
	int exitflag = 0;
    while((uint64_t)entry < (uint64_t)&_binary_tarfs_end)
        {
			int size = getSize(entry->size);
			//printf("entry->name - %s",entry->name);
			if(strcmp(entry->typeflag,"5")  == 0 && strncmp(fileName,entry->name,lastIndexOf (fileName, "/")+1) == 0){
				strncpy(file->parent.d_name,entry->name,NAMEMAX);
				file->parent.offset = (char*)entry - (char*)&_binary_tarfs_start;
				if(++exitflag >= 2)
					break;
			}
            if(strcmp(fileName,entry->name) == 0 && strcmp(entry->typeflag,"0")  == 0){
				strncpy(file->path, fileName, NAMEMAX);
				file->offset = (char*)entry - (char*)&_binary_tarfs_start;
				if(++exitflag >= 2)
					break;
			}
			entry = (struct posix_header_ustar *)((char*)entry + sizeof(struct posix_header_ustar) + size );
			if(size > 0){
				padding = BLOCKSIZE - size%BLOCKSIZE;
				if((char*)&_binary_tarfs_end - (char*)entry >=BLOCKSIZE)
				{
					entry = (struct posix_header_ustar *)((char*)entry + padding);
				}
			}	
		}
		if(strcmp(fileName,entry->name)!=0){
			printf("freeing page");
			unFreePage((uint64_t)file);
			return NULL;
		}
		return file;
}