Example #1
0
void FMC_ReadPage(uint32_t u32startAddr, uint32_t * u32buff)
{
    uint32_t i;
       
    for (i = 0; i < FLASH_PAGE_SIZE/4; i++)
    {
        u32buff[i] = 0;
    }                

    if (u32startAddr == 0x00000000)
    {
        my_memcpy((uint8_t *)u32buff, u8FormatData, 62);
        
        u32buff[FLASH_PAGE_SIZE/4-1] = 0xAA550000;            
    }
    else
    {
        if ( (u32startAddr == (FAT_SECTORS * 512)) || (u32startAddr == ((FAT_SECTORS+1) * 512)) )
        {
            u32buff[0] = 0x00FFFFF8;
        }
        else if (u32startAddr == (8 * 512)) /* root dir */
        {
            my_memcpy((uint8_t *)u32buff, u8RootDirData, 96);
        }
    }
}
Example #2
0
char *my_strcatnew(char* pre, char* post)
{
  char *res;
  int  l_pre;
  int  l_post;
  
  l_pre = my_strlen(pre);
  l_post = my_strlen(post);
  if ((res = malloc(l_pre + l_post + 1)) == NULL)
    return (NULL);
  my_memcpy(res, pre, l_pre);
  my_memcpy(res + l_pre, post, l_post);
  res[l_pre + l_post] = '\0';
  return (res);
}
Example #3
0
int toto()
{
  char	toto[] = "Coucou Ca Va ?";
  char	test[20];
  char	dest[7];

  printf("sa marche ? toto fait %d char\n", my_strlen("toto"));
  my_memcpy(dest, toto, 14);
  dest[14] = 0;
  printf("dest = [%s]\n", dest);
  printf("strchr = [%s]\n", my_strchr(toto, 'a'));
  printf("strcmp toto, dest = %d\n", my_strcmp(toto + 1, dest));
  dest[3] = 'a';
  printf("strncmp toto, dest = %d\n", my_strncmp(toto, dest, 3));
  my_bzero(toto, 5);
  printf("bzero = [%s]\n", toto + 5);
  printf("strcasecmp = %d\n", strcasecmp("SALUT", "123456"));
  my_write(1, "test\n", 5);
  printf("rindex my toto with the char 'a' : [%s]\n",
  	 my_rindex("caca coco coucou", 'i'));
  test[14] = 0;
  printf("apres le memset = [%s]\n", my_memset(test, 'A', 14));
  strcpy(dest, "Coucou");
  printf("memmove result = [%s]\n", memmove(dest, dest + 1, 20));
  printf("dest = [%s]\n", dest);
}
Example #4
0
static int		add_data_to_buffer(char **buffer, int buffer_size,
					   char *data, int data_size)
{
  char			*new_buffer;

  if (!buffer)
    return (-1);
  new_buffer = x_malloc(buffer_size + data_size);
  if (*buffer && buffer_size)
    my_memcpy(new_buffer, *buffer, buffer_size);
  my_memcpy(new_buffer + buffer_size, data, data_size);
  if (*buffer)
    x_free(*buffer);
  *buffer = new_buffer;
  return (buffer_size + data_size);
}
Example #5
0
int			import_format_fox(int 		fd,
					  t_tekpain 	*paint)
{
  t_format_fox_header	header;
  t_layer		*cur;
  char			name[1024];
  unsigned int		*pixels;

  if (read(fd, &header, sizeof(t_format_fox_header)) == -1)
    return (my_printf(2, "Erreur read import_format_fox\n"));
  paint->workzone = header.workzone;
  if ((pixels = bunny_malloc(sizeof(unsigned int) * header.workzone.x
		   * header.workzone.y)) == NULL)
    return (-1);
  while (header.count--)
    {
      read(fd, &name, sizeof(char) * 1024);
      layer_add(paint, layer_new(name,
				 bunny_new_pixelarray(header.workzone.x,
						      header.workzone.y), 0));
      cur = paint->current_layer->data;
      read(fd, pixels, sizeof(unsigned int) * header.workzone.x
	   * header.workzone.y);
      my_memcpy(cur->pix->pixels, pixels,
		sizeof(unsigned int) * header.workzone.x * header.workzone.y);
    }
  bunny_free(pixels);
  return (0);
}
Example #6
0
int32_t HID_CmdReadPages(CMD_T *pCmd)
{
    uint32_t u32StartPage;
    uint32_t u32Pages;
    int32_t i;

    u32StartPage = pCmd->u32Arg1;
    u32Pages     = pCmd->u32Arg2;

	printf("Read command - Start page: %d    Pages Numbers: %d\n", u32StartPage, u32Pages);

    if(u32Pages)
    {
        /* Update data to page buffer to upload */
		/* TODO: We need to update the page data if got a page read command. (0xFF is used in this sample code) */
        for(i=0;i<PAGE_SIZE;i++)
            g_u8PageBuff[i] = 0xFF;
        g_u32BytesInPageBuf = PAGE_SIZE;

        /* The signature word is used as page counter */
        pCmd->u32Signature = 1;

	    /* Trigger HID IN */
		my_memcpy((uint8_t *)((uint32_t)USBD_SRAM_BASE + (uint32_t)USBD->BUFSEG2), (void *)g_u8PageBuff, HID_MAX_PACKET_SIZE_INT_IN);
		USBD->MXPLD2 = HID_MAX_PACKET_SIZE_INT_IN;
		g_u32BytesInPageBuf-= HID_MAX_PACKET_SIZE_INT_IN;
    }

	return 0;
}
Example #7
0
TEST(speed_test, case1){
  int to1[100000];
  int to2[100000];
  int to3[100000];
  int from[100000];

  initialize(from, 100000, 1);

  clock_t n_start = clock();
  my_memcpy(to1, from, 100000);
  clock_t n_end = clock();

  clock_t start = clock();
  memcpy(to2, from, 100000);
  clock_t end = clock();

  clock_t f_start = clock();
  fast_my_memcpy(to2, from, 100000);
  clock_t f_end = clock();

  double default_speed_gap = (n_end - n_start) - (end - start);
  double fastver_speed_gap = (f_end - f_start) - (end - start);
  printf("speed gap between my_memcpy is %f\n", default_speed_gap);
  printf("speed gap between fast ver is %f\n", fastver_speed_gap);
  EXPECT_TRUE(default_speed_gap - fastver_speed_gap > 0);
}
Example #8
0
int WriteDir(int dirhandle, struct DirEntry *dent)
{
    if (dirhandle<0||dirhandle>=10)
        return -1;

    struct INode inode;
    int  dev=0;
    ReadInode(dev,dir_table[dirhandle]->d_entry.d_ino, &inode);

    int dentries_in_one_block = BLKSIZE / (sizeof (struct OnDiskDirEntry));


    int blk_count= dir_table[dirhandle]->d_offset / dentries_in_one_block;

    char buf [BLKSIZE];

    ReadBlock(dev,DATA_BLK_STARTS_AT+inode.i_blks[blk_count],buf);

    struct OnDiskDirEntry* dp= (struct OnDiskDirEntry*) buf;

    dp += dir_table[dirhandle]->d_offset % dentries_in_one_block;

    my_memcpy(  dp, &dent->d_entry, sizeof (struct OnDiskDirEntry) );

    WriteBlock(dev,DATA_BLK_STARTS_AT+inode.i_blks[blk_count],buf);

    dir_table[dirhandle]->d_offset++;

    return 0 ;// success

}
Example #9
0
int32_t ProcessCommand(uint8_t *pu8Buffer, uint32_t u32BufferLen)
{
	uint32_t u32sum;
	printf("ProcessCommand\n");  //shanchun20121116
	
    my_memcpy((uint8_t *)&gCmd, pu8Buffer, u32BufferLen);

    /* Check size */
    if((gCmd.u8Size > sizeof(gCmd)) || (gCmd.u8Size > u32BufferLen))
        return -1;

    /* Check signature */
    if(gCmd.u32Signature != HID_CMD_SIGNATURE)
        return -1;

    /* Calculate checksum & check it*/
    u32sum = CalCheckSum((uint8_t *)&gCmd, gCmd.u8Size);
    if(u32sum != gCmd.u32Checksum)
        return -1;

	switch(gCmd.u8Cmd)
	{
		case HID_CMD_ERASE:
		{
			HID_CmdEraseSectors(&gCmd);
			break;
		}		
		case HID_CMD_READ:
		{
			HID_CmdReadPages(&gCmd);
			break;
		}		
		case HID_CMD_WRITE:
		{
			HID_CmdWritePages(&gCmd);
			break;		
		}
		case HID_CMD_TEST:
		{
		    HID_CmdTest(&gCmd);
		    break;
		}

		case HID_CMD_TKWRITE:
		{
			HID_CmdTKWrite(&gCmd);
			break;
		}

		case HID_CMD_TKREAD:
		{
			HID_CmdTKRead(&gCmd);
			break;
		}
		default:
			return -1;
	}	
	
	return 0;
}
Example #10
0
int send_uptime(void)
{
  struct sockaddr_in sai;
  struct stat st;
  PackUp *mem;
  int len, servidx;
  char servhost[UHOSTLEN] = "none";
  module_entry *me;

  if (uptimeip == -1) {
    uptimeip = get_ip();
    if (uptimeip == -1)
      return -2;
  }

  uptimecount++;
  upPack.packets_sent = htonl(uptimecount); /* Tell the server how many
					       uptime packets we've sent. */
  upPack.now2 = htonl(time(NULL));
  upPack.ontime = 0;

  if ((me = module_find("server", 1, 0))) {
    Function *server_funcs = me->funcs;

    if (server_online) {
      servidx = findanyidx(serv);
      strncpyz(servhost, dcc[servidx].host, sizeof servhost);
      upPack.ontime = htonl(server_online);
    }
  }

  if (!upPack.pid)
    upPack.pid = htonl(getpid());

  if (!upPack.uptime)
    upPack.uptime = htonl(online_since);

  if (stat("/proc", &st) < 0)
    upPack.sysup = 0;
  else
    upPack.sysup = htonl(st.st_ctime);

  len = sizeof(upPack) + strlen(botnetnick) + strlen(servhost) +
        strlen(uptime_version);
  mem = (PackUp *) nmalloc(len);
  egg_bzero(mem, len); /* mem *should* be completely filled before it's
                             * sent to the server.  But belt-and-suspenders
                             * is always good.
                             */
  my_memcpy(mem, &upPack, sizeof(upPack));
  sprintf(mem->string, "%s %s %s", botnetnick, servhost, uptime_version);
  egg_bzero(&sai, sizeof(sai));
  sai.sin_family = AF_INET;
  sai.sin_addr.s_addr = uptimeip;
  sai.sin_port = htons(uptime_port);
  len = sendto(uptimesock, (void *) mem, len, 0, (struct sockaddr *) &sai,
               sizeof(sai));
  nfree(mem);
  return len;
}
Example #11
0
char *filesys_start(Function *global_funcs)
{
  global = global_funcs;

  module_register(MODULE_NAME, filesys_table, 2, 0);
  if (!module_depend(MODULE_NAME, "eggdrop", 106, 0)) {
    module_undepend(MODULE_NAME);
    return "This module requires Eggdrop 1.6.0 or later.";
  }
  if (!(transfer_funcs = module_depend(MODULE_NAME, "transfer", 2, 0))) {
    module_undepend(MODULE_NAME);
    return "This module requires transfer module 2.0 or later.";
  }
  add_tcl_commands(mytcls);
  add_tcl_strings(mystrings);
  add_tcl_ints(myints);
  H_fil = add_bind_table("fil", 0, builtin_fil);
  add_builtins(H_dcc, mydcc);
  add_builtins(H_fil, myfiles);
  add_builtins(H_load, myload);
  add_help_reference("filesys.help");
  init_server_ctcps(0);
  my_memcpy(&USERENTRY_DCCDIR, &USERENTRY_INFO,
            sizeof(struct user_entry_type) - sizeof(char *));

  USERENTRY_DCCDIR.got_share = 0;       /* We dont want it shared tho */
  add_entry_type(&USERENTRY_DCCDIR);
  DCC_FILES_PASS.timeout_val = &password_timeout;
  add_lang_section("filesys");
  return NULL;
}
Example #12
0
char *filesys_start(Function * global_funcs)
{
  global = global_funcs;

  Context;
  dccdir[0] = 0;
  dccin[0] = 0;
  filedb_path[0] = 0;
  module_register(MODULE_NAME, filesys_table, 2, 0);
  if (!(transfer_funcs = module_depend(MODULE_NAME, "transfer", 2, 0)))
    return "You need the transfer module to user the file system.";
  if (!module_depend(MODULE_NAME, "eggdrop", 104, 0))
    return "You need at least eggdrop1.4.0 to run this module.";
  add_tcl_commands(mytcls);
  add_tcl_strings(mystrings);
  add_tcl_ints(myints);
  H_fil = add_bind_table("fil", 0, builtin_fil);
  add_builtins(H_dcc, mydcc);
  add_builtins(H_fil, myfiles);
  add_builtins(H_load, myload);
  add_help_reference("filesys.help");
  init_server_ctcps(0);
  my_memcpy(&USERENTRY_DCCDIR, &USERENTRY_INFO,
	    sizeof(struct user_entry_type) - sizeof(char *));

  USERENTRY_DCCDIR.got_share = 0;	/* we dont want it shared tho */
  add_entry_type(&USERENTRY_DCCDIR);
  DCC_FILES_PASS.timeout_val = &password_timeout;
  add_lang_section("filesys");
  return NULL;
}
Example #13
0
char *notes_start(Function *global_funcs)
{

  global = global_funcs;

  notefile[0] = 0;
  module_register(MODULE_NAME, notes_table, 2, 2);
  if (!module_depend(MODULE_NAME, "eggdrop", 108, 0)) {
    module_undepend(MODULE_NAME);
    return "This module requires Eggdrop 1.8.0 or later.";
  }
  add_hook(HOOK_HOURLY, (Function) notes_hourly);
  add_hook(HOOK_MATCH_NOTEREJ, (Function) match_note_ignore);
  add_tcl_ints(notes_ints);
  add_tcl_strings(notes_strings);
  add_tcl_commands(notes_tcls);
  add_builtins(H_dcc, notes_cmds);
  add_builtins(H_chon, notes_chon);
  add_builtins(H_away, notes_away);
  add_builtins(H_nkch, notes_nkch);
  add_builtins(H_load, notes_load);
  add_help_reference("notes.help");
  add_lang_section("notes");
  notes_server_setup(0);
  notes_irc_setup(0);
  my_memcpy(&USERENTRY_FWD, &USERENTRY_INFO, sizeof(void *) * 12);
  add_entry_type(&USERENTRY_FWD);
  return NULL;
}
Example #14
0
/**   
  * @brief  USB_EpAck2, Ack Transfer Pipe.
  * @param  None.
  * @retval None.
  */
uint32_t USB_EpAck2(void)
{
	/* Interrupt IN */
	uint8_t au8Buf[8] = {0};
	my_memcpy((uint8_t *)((uint32_t)USBD_SRAM_BASE + (uint32_t)USBD->BUFSEG4), au8Buf, MAX_PACKET_SIZE_INT);
	USBD->MXPLD4 = MAX_PACKET_SIZE_INT;
	return 0;
}
Example #15
0
mpi_request* mpi_irecv(mpi* m,
    void* data, unsigned size, int from)
{
  (void)m;
  (void)from;
  my_memcpy(data, global_data, size);
  return (mpi_request*)1;
}
Example #16
0
// Write into a file already opened, nbytes from buf
int WriteFile(int fhandle, char buf[], int nbytes)
{

    // implementation of writefile is same as above readfile function, just direction of flow of data is reverse

    if (fhandle<0||ofo_table[fhandle]==NULL) {
        return -1;//error
    }

    struct INode inode;
    ReadInode( dev,ofo_table[fhandle]->ofo_inode->ic_ino,&inode);

    int nblks_to_be_read= (nbytes-1)/BLKSIZE +1;
    int nblk_to_be_skipped= (ofo_table[fhandle]->ofo_curpos -1) / BLKSIZE;

    int first_blkno_tobe_read= inode.i_blks[nblk_to_be_skipped];

    int byte_to_be_skipped= (ofo_table[fhandle]->ofo_curpos-1) % BLKSIZE;

    char tempbuf [BLKSIZE];
    ReadBlock(ofo_table[fhandle]->ofo_inode->ic_dev, first_blkno_tobe_read, tempbuf);

    int bytes_tobe_read= BLKSIZE - byte_to_be_skipped;
    my_memcpy(tempbuf+byte_to_be_skipped, buf, bytes_tobe_read );

    char* buf_ptr=buf+bytes_tobe_read;
    //now read remaining blks
    int i=nblk_to_be_skipped +1;
    for (;i<nblks_to_be_read;i++) {

        ReadBlock(dev,DATA_BLK_STARTS_AT+inode.i_blks[i],tempbuf);

        int bytes_to_transfer;

        if (nbytes>(i+1)*BLKSIZE)
            bytes_to_transfer=BLKSIZE;
        else bytes_to_transfer= nbytes-i*BLKSIZE;

        my_memcpy(tempbuf, buf_ptr, bytes_to_transfer);
        buf_ptr += BLKSIZE;
    }
    // advance the cursor
    ofo_table[fhandle]->ofo_curpos +=  nbytes;

    return nbytes; // return bytes read
}
Example #17
0
int main(void)
{
	char src[]="woshiwjb";
	char dest[8]={0};
	my_memcpy(dest,src,5);
	printf("%s\n",dest);
	return 0;
}
Example #18
0
void   	*my_ptrdup(void *ptr, size_t size)
{
  char 	*dest;

  if (ptr == NULL || !size || (dest = gbgc_malloc(size)) == NULL ||
      (dest = my_memcpy(dest, ptr, size)) == NULL)
    return (NULL);
  return ((void *)dest);
}
Example #19
0
int set_proc_data(SysStruct *ss, const int *buf, int pid)
{
    if(ss == NULL || buf == NULL)
        return -1;
    if(pid < 0 || pid >= NUM_PROCS)
        return -2;
    my_memcpy(ss->proc[pid].reg_data, buf, 0x44);
    return pid;
}
Example #20
0
TEST(my_memcpy_test, case1){
  int array1[10];
  int array2[] = {1,2,3,4,5};
  my_memcpy(array1, array2, 5);
  EXPECT_EQ(array1[0], 1);
  EXPECT_EQ(array1[1], 2);
  EXPECT_EQ(array1[2], 3);
  EXPECT_EQ(array1[3], 4);
  EXPECT_EQ(array1[4], 5);
}
Example #21
0
static void hi_jack_function(mocked_function_t *functionp,void * dstFunc) {
#ifdef __amd64__
	char jumpf[30] = "\x48\xb8XXXXXXXX\x50\xc3";
	char *addr = jumpf+2;
	(*(void**) (addr))=dstFunc;
	my_memcpy(functionp->addr,jumpf,STUB_SIZE);
#elif __i386__
#define HIJACK_ADDR(x) *(void**)((x)+1)
	static const char hijack_stub[] = {
	0x68, 0x00, 0x00, 0x00, 0x00, /* push addr */
	0xc3                          /* ret */
	};
	my_memcpy(functionp->addr, hijack_stub, sizeof(hijack_stub));
	HIJACK_ADDR(functionp->addr) = dstFunc;

#else
	abort();
#endif
}
Example #22
0
File: ebizzy.c Project: 1587/ltp
static unsigned int search_mem(void)
{
	record_t key, *found;
	record_t *src, *copy;
	unsigned int chunk;
	size_t copy_size = chunk_size;
	unsigned int i;
	unsigned int state = 0;

	for (i = 0; threads_go == 1; i++) {
		chunk = rand_num(chunks, &state);
		src = mem[chunk];
		/*
		 * If we're doing random sizes, we need a non-zero
		 * multiple of record size.
		 */
		if (random_size)
			copy_size = (rand_num(chunk_size / record_size, &state)
				     + 1) * record_size;
		copy = alloc_mem(copy_size);

		if (touch_pages) {
			touch_mem((char *)copy, copy_size);
		} else {

			if (no_lib_memcpy)
				my_memcpy(copy, src, copy_size);
			else
				memcpy(copy, src, copy_size);

			key = rand_num(copy_size / record_size, &state);

			if (verbose > 2)
				printf("Search key %zu, copy size %zu\n", key,
				       copy_size);
			if (linear)
				found = linear_search(key, copy, copy_size);
			else
				found =
				    bsearch(&key, copy, copy_size / record_size,
					    record_size, compare);

			/* Below check is mainly for memory corruption or other bug */
			if (found == NULL) {
				fprintf(stderr, "Couldn't find key %zd\n", key);
				exit(1);
			}
		}		/* end if ! touch_pages */

		free_mem(copy, copy_size);
	}

	return (i);
}
Example #23
0
int mpi_recv_any(mpi* m, void** data, unsigned* size, int* from)
{
  (void)m;
  if (global_state == EMPTY)
    return 0;
  *data = my_malloc(global_size);
  my_memcpy(*data, global_data, global_size);
  *size = global_size;
  *from = 0;
  global_state = EMPTY;
  return 1;
}
Example #24
0
void HID_GetInReport(void)
{
    uint32_t u32StartPage;
    uint32_t u32TotalPages;
    uint32_t u32PageCnt;
	uint8_t *ptr;
	int32_t i;
    uint8_t u8Cmd;

    u8Cmd        = gCmd.u8Cmd;
    u32StartPage = gCmd.u32Arg1;
    u32TotalPages= gCmd.u32Arg2;
    u32PageCnt   = gCmd.u32Signature;

    /* Check if it is in data phase of read command */
	if(u8Cmd == HID_CMD_READ)
	{
	    /* Process the data phase of read command */
        if((u32PageCnt >= u32TotalPages) && (g_u32BytesInPageBuf == 0))
        {
    		/* The data transfer is complete. */
            u8Cmd = HID_CMD_NONE;
            printf("Read command complete!\n");
        }
	    else
	    {
	        if(g_u32BytesInPageBuf == 0)
	        {
	            /* The previous page has sent out. Read new page to page buffer */
				/* TODO: We should update new page data here. (0xFF is used in this sample code) */
				printf("Reading page %d\n", u32StartPage + u32PageCnt);
		        for(i=0;i<PAGE_SIZE;i++)
		            g_u8PageBuff[i] = 0xFF;
					
	            g_u32BytesInPageBuf = PAGE_SIZE;
	
	            /* Update the page counter */
	            u32PageCnt++;
	        }
	
            /* Prepare the data for next HID IN transfer */	
			ptr = (uint8_t *)((uint32_t)USBD_SRAM_BASE + (uint32_t)USBD->BUFSEG2);
			my_memcpy(ptr, (void *)&g_u8PageBuff[PAGE_SIZE - g_u32BytesInPageBuf], HID_MAX_PACKET_SIZE_INT_IN);
			USBD->MXPLD2 = HID_MAX_PACKET_SIZE_INT_IN;
    		g_u32BytesInPageBuf -= HID_MAX_PACKET_SIZE_INT_IN;
		}
	}
	
	gCmd.u8Cmd        = u8Cmd;
	gCmd.u32Signature = u32PageCnt;
	
}
int
main ()
{
  printf ("== Launching sanity test ==\n");

  assert (my_memcpy (NULL, NULL, 0) == NULL);
  assert (my_memcmp (NULL, NULL, 0) == 0);
  assert (my_memset (NULL, 0, 0) == NULL);

  printf ("== Sanity test succeded ==\n");

  return 0;
}
Example #26
0
int main()
{
    l3 o{};
    o.report(reinterpret_cast<char const*>(&o));
    
    std::cout << "the complete object occupies ";
    print_range(&o, sizeof(o));
    std::cout << "\n";
    
    l1& so = o;
    l1 t;
    my_memcpy(&t, &so, sizeof(t));
}
Example #27
0
int main()
{
  vecteur v1,v2;
  int taille;

  v1 = lit_vecteur("vecteur1.txt");
  affiche_vecteur(v1);
  taille = taille_vecteur(v1);
  v2 = allouer_vecteur(taille);
  my_memcpy(acces_vecteur(v2,0), acces_vecteur(v1,0),taille*sizeof(double));
  my_memmove(acces_vecteur(v2,0), acces_vecteur(v2,taille/4), (taille/2)*sizeof(double));
  affiche_vecteur(v2);
  my_memcpy(acces_vecteur(v2,0), acces_vecteur(v1,0),taille*sizeof(double));
  my_memmove(acces_vecteur(v2,taille/4), acces_vecteur(v2,0), (taille/2)*sizeof(double));
  affiche_vecteur(v2);
  liberer_vecteur(v1);
  liberer_vecteur(v2);

  printf("Difference malloc/free : %d\n",malloc_counter - free_counter);
  
  return 0;
}
Example #28
0
t_ll* ll_new_data(void* data, int size)
{
    t_ll* node;
    void* ndata;

    if ((node = malloc(sizeof(t_ll))) == NULL)
      return NULL;
    if ((ndata = malloc(size)) == NULL)
      return (NULL);

    node->data = my_memcpy(ndata, data, size);
    node->next = NULL;
    return node;
}
Example #29
0
static void unprotect_address(mocked_function_t * functionp) {
	char *p;
	long psize = sysconf(_SC_PAGESIZE);
	for (p = (char *)functionp->addr; (unsigned long)p % psize; --p)
		;
	if (-1 == mprotect(p,128, PROT_WRITE|PROT_READ|PROT_EXEC)){
		perror("could not set protection");
		exit(-1);
	}
	if (-1 == mprotect(p+psize,128, PROT_WRITE|PROT_READ|PROT_EXEC)){
		perror("could not set protection on next page");
		exit(-1);
	}
	my_memcpy(functionp->backup_function_data,functionp->addr,STUB_SIZE);
}
Example #30
0
int testMemcpy(size_t SIZE)
{
	int i,rv,j;
	char * src=getBuffer(SIZE+1);
	char * dst=calloc(SIZE+1,sizeof(char));

	printf("testSize:%i\n",SIZE);
	my_memcpy(dst,src,SIZE);
	rv=differ(dst,src,SIZE) ;
	if ( rv ) printf("Error 1\n");

	free(src);
	free(dst);
	return 0;
}