Ejemplo n.º 1
0
DCstruct* dcNewStruct(DCsize fieldCount, DCint alignment)
{
	DCstruct* s = (DCstruct*)dcAllocMem(sizeof(DCstruct));
	s->pCurrentStruct = s;
	s->pLastStruct = NULL;
	s->nextField = 0;
	s->fieldCount = fieldCount;
	s->alignment = alignment;
	s->size = 0;
	s->pFields = (DCfield*)dcAllocMem(fieldCount * sizeof(DCfield));
	return s;
}
Ejemplo n.º 2
0
static DCCallVM* dc_callvm_new_arm32_thumb(DCCallVM_vt* vt, DCsize size)
{
  /* Store at least 16 bytes (4 words) for internal spill area. Assembly code depends on it. */
  DCCallVM_arm32_thumb* self = (DCCallVM_arm32_thumb*)dcAllocMem(sizeof(DCCallVM_arm32_thumb)+size+16);
  dc_callvm_base_init(&self->mInterface, vt);
  dcVecInit(&self->mVecHead, size);
  return (DCCallVM*)self;
}
Ejemplo n.º 3
0
static DCCallVM* dc_callvm_new_mips_o32(DCCallVM_vt* vt, DCsize size)
{
  DCCallVM_mips_o32* self = (DCCallVM_mips_o32*)dcAllocMem(sizeof(DCCallVM_mips_o32)+size);
  dc_callvm_base_init(&self->mInterface, vt);
  dcVecInit(&self->mVecHead, size);
  dc_callvm_reset_mips_o32( (DCCallVM*) self );
  return (DCCallVM*)self;
}
Ejemplo n.º 4
0
/* the six output registers %o0-%o5 are always loaded, thus we need to ensure the argument buffer has space for at least 24 bytes. */
static DCCallVM* dc_callvm_new_sparc(DCCallVM_vt* vt, DCsize size)
{
  size=DC_MAX(size,sizeof(void*)*(6+1));
  DCCallVM_sparc* self = (DCCallVM_sparc*) dcAllocMem(sizeof(DCCallVM_sparc)+size);
  dc_callvm_base_init(&self->mInterface, vt);
  dcVecInit(&self->mVecHead,size);
  return (DCCallVM*)self;
}
/* the six output registers %o0-%o5 are always loaded, thus we need to ensure the argument buffer has space for at least 24 bytes. */
static DCCallVM* dc_callvm_new_sparc64(DCCallVM_vt* vt, DCsize size)
{
  DCCallVM_sparc64* self = (DCCallVM_sparc64*) dcAllocMem(sizeof(DCCallVM_sparc64)+DHEAD+size);
  dc_callvm_base_init(&self->mInterface, vt);
  dcVecInit(&self->mVecHead,DHEAD+size);
  dc_callvm_reset_sparc64(&self->mInterface);
  return (DCCallVM*)self;
}
Ejemplo n.º 6
0
DCCallVM* dcNewCallVM(DCsize size)
{
  DCCallVM_ppc64* self = (DCCallVM_ppc64*)dcAllocMem(sizeof(DCCallVM_ppc64)+size);
  dcVecInit(&self->mVecHead, size);
  self->mIntRegs              = 0;
  self->mFloatRegs            = 0;
  dc_callvm_mode_ppc64( (DCCallVM*) self, DC_CALL_C_DEFAULT );
  return (DCCallVM*)self;
}
Ejemplo n.º 7
0
static DCCallVM* dc_callvm_new_x86(DCCallVM_vt* vt, DCsize size)
{
  DCCallVM_x86* self = (DCCallVM_x86*) dcAllocMem( sizeof(DCCallVM_x86)+size );

  dc_callvm_base_init(&self->mInterface, vt);

  self->mIntRegs              = 0;
  dcVecInit(&self->mVecHead, size);
  return (DCCallVM*) self;
}
static DCCallVM* dc_callvm_new_arm32_armhf(DCCallVM_vt* vt, DCsize size)
{
  /* Store at least 16 bytes (4 words) for internal spill area. Assembly code depends on it. */
  DCCallVM_arm32_armhf* p = (DCCallVM_arm32_armhf*)dcAllocMem(sizeof(DCCallVM_arm32_armhf)+size+16);
  dc_callvm_base_init(&p->mInterface, vt);
  dcVecInit(&p->mVecHead, size);
  p->i = 0;
  p->s = 0;
  p->d = 0;
  return (DCCallVM*)p;
}
Ejemplo n.º 9
0
/* Public API. */
DCCallVM* dcNewCallVM(DCsize size)
{
  DCCallVM_x86* p = (DCCallVM_x86*)dcAllocMem(sizeof(DCCallVM_x86)+size);

  dc_callvm_mode_x86((DCCallVM*)p, DC_CALL_C_DEFAULT);

  dcVecInit(&p->mVecHead, size);
  dc_callvm_reset_x86((DCCallVM*)p);

  return (DCCallVM*)p;
}
Ejemplo n.º 10
0
/* Public API. */
DCCallVM* dcNewCallVM(DCsize size)
{
  /* Store at least 16 bytes (4 words) for internal spill area. Assembly code depends on it. */
  DCCallVM_mips_eabi* p = (DCCallVM_mips_eabi*)dcAllocMem(sizeof(DCCallVM_mips_eabi)+size+16);

  dc_callvm_mode_mips_eabi((DCCallVM*)p, DC_CALL_C_DEFAULT);

  dcVecInit(&p->mVecHead, size);
  dc_callvm_reset_mips_eabi((DCCallVM*)p);

  return (DCCallVM*)p;
}
Ejemplo n.º 11
0
/* Public API. */
DCCallVM* dcNewCallVM(DCsize size)
{
  /* Store at least 16 bytes (4 words for first 4 int args) for internal spill area. Assembly code depends on it. */
  DCCallVM_arm32_armhf* p = (DCCallVM_arm32_armhf*)dcAllocMem(sizeof(DCCallVM_arm32_armhf)+size+16);

  mode((DCCallVM*)p, DC_CALL_C_DEFAULT);

  dcVecInit(&p->mVecHead, size);
  reset((DCCallVM*)p);

  return (DCCallVM*)p;
}
Ejemplo n.º 12
0
DLSyms* dlSymsInit(const char* libPath)
{
  unsigned char* pMem;
  void* pSectionContent;
  int i;
  struct stat st;
  DLSyms* pSyms = (DLSyms*)dcAllocMem(sizeof(DLSyms));
  memset(pSyms, 0, sizeof(DLSyms));
  pSyms->file = open(libPath, O_RDONLY);
  stat(libPath, &st);
  pSyms->fileSize = st.st_size;
  pSyms->pElf_Ehdr = (Elf_Ehdr*) mmap((void*) NULL, pSyms->fileSize, PROT_READ, MAP_SHARED, pSyms->file, 0);

#ifdef DL__BinaryFormat_elf32
  assert(pSyms->pElf_Ehdr->e_ident[EI_CLASS] == ELFCLASS32);
#else
  assert(pSyms->pElf_Ehdr->e_ident[EI_CLASS] == ELFCLASS64);
#endif

  assert(pSyms->pElf_Ehdr->e_phoff > 0);
  assert(pSyms->pElf_Ehdr->e_shoff > 0);


  pMem = (unsigned char*)pSyms->pElf_Ehdr;
  
  /* traverse section headers */
  Elf_Shdr* pS = (Elf_Shdr*) ( pMem + pSyms->pElf_Ehdr->e_shoff );
  /* skip section 0 which is always zero due to the Elf standard. */
  for (i = 1; i < pSyms->pElf_Ehdr->e_shnum; i++) 
  {
    Elf_Shdr* pSection = &pS[i];
    pSectionContent = ((char*)pMem) + pSection->sh_offset;
    switch (pSection->sh_type)
    {
      case SHT_DYNSYM:
        if (!pSyms->pSymTab) {
          pSyms->pSymTab  = (Elf_Sym*)pSectionContent;
          pSyms->nSymbols = pSection->sh_size / pSection->sh_entsize;
        }
        break;
      case SHT_STRTAB:
        // Do not trust pSyms->pElf_Ehdr->e_shstrndx!
        if (!pSyms->pStrTab) {
          pSyms->pStrTab  = (const char*)pSectionContent;
          pSyms->strTabSize = pSection->sh_size;
        }
        break;
    }
    if (pSyms->pSymTab && pSyms->pStrTab)
      break;
  }
  return pSyms;
}
Ejemplo n.º 13
0
static DCCallVM* dc_callvm_new_arm64(DCCallVM_vt* vt, DCsize size)
{
  DCCallVM_arm64* p = (DCCallVM_arm64*) dcAllocMem(size);

  dc_callvm_base_init(&p->mInterface, vt);

  dcVecInit(&p->mVecHead, size);

  p->i = 0;
  p->f = 0;

  return (DCCallVM*)p;
}
Ejemplo n.º 14
0
static DCCallVM* dc_callvm_new_x64(DCCallVM_vt* vt, DCsize size)
{
  DCCallVM_x64* self = (DCCallVM_x64*)dcAllocMem(sizeof(DCCallVM_x64)+size);
  
  dc_callvm_base_init(&self->mInterface, vt);

  /* Since we store register parameters in DCCallVM_x64 directly, adjust the stack size. */
  size -= sizeof(DCRegData_x64);
  size = (((signed long)size) < 0) ? 0 : size;


  self->mRegCount.i = self->mRegCount.f =  0;

  dcVecInit(&self->mVecHead, size);
  return (DCCallVM*)self;
}
Ejemplo n.º 15
0
DLSyms* dlSymsInit(const char* libPath) 
{
	DLSyms* pSyms = NULL;
	uint32_t iImage, nImages;
	for (iImage = 0, nImages = _dyld_image_count(); iImage < nImages; iImage++)
	{
		const char* name = _dyld_get_image_name(iImage);
		if (name && !strcmp(name, libPath))
		{
			const struct MACH_HEADER_TYPE* pHeader = _dyld_get_image_header(iImage);
			const char* pBase = ((const char*)pHeader);
			if (pHeader->filetype != MH_DYLIB)
				return NULL;
			if (pHeader->flags & MH_SPLIT_SEGS)
				return NULL;

			if (pHeader)
			{
				uint32_t iCmd, nCmds = pHeader->ncmds;
				const struct load_command* cmd = (const struct load_command*)(pBase + sizeof(struct MACH_HEADER_TYPE));
				
				for (iCmd = 0; iCmd < nCmds; iCmd++) 
				{
					if (cmd->cmd == LC_SYMTAB) 
					{
						const struct symtab_command* scmd = (const struct symtab_command*)cmd;
					
						pSyms = (DLSyms*)( dcAllocMem(sizeof(DLSyms)) );
						pSyms->symbolCount = scmd->nsyms;
						pSyms->pStringTable = pBase + scmd->stroff;
						pSyms->pSymbolTable = (struct NLIST_TYPE*)(pBase + scmd->symoff);
						
						return pSyms;
					}
					cmd = (const struct load_command*)(((char*)cmd) + cmd->cmdsize);
				}
			}
			break;
		}
	}
	return NULL;
}