Exemplo n.º 1
0
int allocate_module(struct LKM_Module *lkm_mod, int e_shnum)
{
        int i=0, j=0, ret=0, flag=0;
        size_t size,size_p;
        int perm = PTE_P | PTE_W ;
        struct Secthdr *secthdr = lkm_mod->sect_hdr;
        void *start, *va = lkm_mod->load_addr;
        lkm_mod->num_pages = 0;


        while(i < e_shnum){
                if((secthdr->sh_type == ELF_SHT_RELA) && (ret = strcmp(secthdr->sh_name + lkm_mod->shname_st_table, ".rela.eh_frame" ) != 0)){
                        ret = apply_relocation(lkm_mod, i);
                        if(ret < 0){
                                cprintf("Failed to Apply Relocation. Aborting..\n");
                                return -1;
                        }
                }else if(secthdr->sh_type == ELF_SHT_REL){
                        cprintf("REL Section. Not Handling it here \n");
                }
                i++;
                secthdr++;
        }
        return 0;

}
Exemplo n.º 2
0
/* Copy all literals referenced from a code block to newspace */
void collect_literals_step(F_COMPILED *compiled, CELL code_start, CELL literals_start)
{
	if(collecting_gen >= compiled->last_scan)
	{
		CELL scan;
		CELL literal_end = literals_start + compiled->literals_length;

		if(collecting_accumulation_gen_p())
			compiled->last_scan = collecting_gen;
		else
			compiled->last_scan = collecting_gen + 1;

		for(scan = literals_start; scan < literal_end; scan += CELLS)
			copy_handle((CELL*)scan);

		if(compiled->relocation != F)
		{
			copy_handle(&compiled->relocation);

			F_BYTE_ARRAY *relocation = untag_object(compiled->relocation);

			F_REL *rel = (F_REL *)(relocation + 1);
			F_REL *rel_end = (F_REL *)((char *)rel + byte_array_capacity(relocation));

			while(rel < rel_end)
			{
				if(REL_TYPE(rel) == RT_IMMEDIATE)
				{
					CELL offset = rel->offset + code_start;
					F_FIXNUM absolute_value = get(CREF(literals_start,REL_ARGUMENT(rel)));
					apply_relocation(REL_CLASS(rel),offset,absolute_value);
				}

				rel++;
			}
		}

		flush_icache(code_start,literals_start - code_start);
	}
}