Пример #1
0
int main()
{
    char buffer2[20];
    char buffer3[20];
    void * al;
    void *toout,*fromout;
    int page_size = getpagesize();
    page_mask = ~((intptr_t)page_size-1);
    // Get some page aligned memory
    void * x = malloc(page_size * 2);
    target_space = ((intptr_t)x + page_size - 1) & page_mask;
    void * mm = (void*)target_space;

    al = MyAlloc(mm); // cause the swizzle
    swizzle_space = (intptr_t)al & page_mask;
    
    if (swizzle_space == target_space)
    {
        fprintf (stderr,"Error al not swizzled\n");
    }

    ((char*)al)[0] = 1;
    
    buffer2[0] = 2;
    buffer3[0] = 3;

    mmemcpy(buffer2, al, n, &toout, &fromout);
    
    fprintf(stderr, "al[0] %d buffer2[0] %d  toout - to %x fromout - from %x\n", 
           ((char*)al)[0], buffer2[0], 
           (char*)toout - (char*)buffer2, (char*)fromout- (char*)al);
    if (!Swizzled (al)) {
        fprintf (stderr,"Error1 al not swizzled\n");
    }
    if (!Swizzled (fromout)) {
        fprintf (stderr,"Error2 fromout not swizzled\n");
    }

    mmemcpy(al, buffer3, n, &toout, &fromout);
    if (!Swizzled (al)) {
        fprintf (stderr,"Error3 al not swizzled\n");
        fflush (stderr);
    }
    if (!Swizzled (toout)) {
        fprintf (stderr,"Error4 toout not swizzled\n");
        fflush (stderr);
    }
    fprintf(stderr, "al[0] %d  buffer3[0] %d  toout - to %x fromout - from %x\n",((char*)al)[0], 
            buffer3[0], (char*)toout-(char *)al, (char*)fromout - (char*)buffer3);
    fflush (stderr);
    
    memindex(al);
    
    MyFree(al);
    
    return 0;
}
Пример #2
0
/* swap two elements in a heap/tree */
void heap_swap(HEAP * const h, uint32 A, uint32 B) {
	void * C;
	C = mmalloc(sizeof(h->elem_size));

	/* copy memory as we dont know how big are elements */
	mmemcpy(C, h->root + (h->elem_size * A), h->elem_size);
	mmemcpy(h->root + (h->elem_size * A), h->root + (h->elem_size * B), h->elem_size);
	mmemcpy(h->root + (h->elem_size * B), C, h->elem_size);

	mfree(C);
}
Пример #3
0
unsigned char *uncompress_data( unsigned char *inbuf,int *buflen )
{
  unsigned char *outbuf;
  unsigned char packcode;
  int a,b,c,len,offset;
  int inlen,outlen,inpos,outpos;
  
  /* length of data */
  inlen=*buflen;
  outlen=(inbuf[2]<<16)+(inbuf[3]<<8)+inbuf[4];
  outbuf=(unsigned char*)malloc(outlen);
  if (outbuf==NULL) 
  { 
    //AfxMessageBox("Insufficient memory."); 
	free(outbuf);
    return NULL; 
  }
  
  /* position in file */
  if (inbuf[0]&0x01) inpos=8; else inpos=5;
  outpos=0;
  
  /* main decoding loop */
  while ((inpos<inlen)&&(inbuf[inpos]<0xFC))
  {
	

    packcode=inbuf[inpos];
    a=inbuf[inpos+1];
    b=inbuf[inpos+2];
    
    if (!(packcode&0x80)) {
      len=packcode&3;
      mmemcpy(outbuf+outpos,inbuf+inpos+2,len);
      inpos+=len+2;
      outpos+=len;
      len=((packcode&0x1c)>>2)+3;
      offset=((packcode>>5)<<8)+a+1;
      mmemcpy(outbuf+outpos,outbuf+outpos-offset,len);
      outpos+=len;
    }
    else if (!(packcode&0x40)) {
Пример #4
0
/**
 * inserts element at the top of heap
 */
void heap_insert_head(HEAP * const h, void * const he) {
	mmemcpy((HEAP *)h->root + h->count, he, h->elem_size);
	h->count++;
}