int enet_socket_send (ENetSocket socket, const ENetAddress * address, const ENetBuffer * buffers, size_t bufferCount) { ENetAddress address_clone; int address_length = enet_address_get_size (address); DWORD sentLength; if (address != NULL) { memcopy (& address_clone, address, address_length); address_clone.port = ENET_HOST_TO_NET_16 (address -> port); } if (WSASendTo (socket, (LPWSABUF) buffers, (DWORD) bufferCount, & sentLength, 0, address != NULL ? (struct sockaddr *) & address_clone : NULL, address != NULL ? address_length : 0, NULL, NULL) == SOCKET_ERROR) { if (WSAGetLastError () == WSAEWOULDBLOCK) return 0; return -1; } return (int) sentLength; }
void SendData(ArgStruct *p) { int nbytes = p->bufflen, nb, mb; char *src = p->s_ptr, *dest = p->r_ptr; #if defined( USE_PIPE ) /* Push the data thru a pipe */ while( nbytes > 0 ) { /* non-blocking, so write as much as I can (~1 page) */ nb = write(p->prot.fd[1], src, nbytes); mb = read( p->prot.fd[0], dest, nb); if( nb <= 0 || mb != nb ) { fprintf(stderr,"Pipe transfer was unsuccessful (%d/%d %d/%d)\n", mb, nb, nbytes, p->bufflen); } src += nb; dest += nb; nbytes -= nb; } #else memcopy(dest, src, nbytes); #endif }
dirent_t *readdir(inode_t *node, uint32_t offset) { CALLOCP(message, vfsm); message->m.msg_type = VFSM_READDIR; memcopy((uint8_t *)&message->readdir.node, (uint8_t *)node, sizeof(inode_t)); message->readdir.num = offset; send2(VFS_PID, message); vfsm *reply = waitmsg(VFS_PID,0); memcopy((uint8_t *)&dirent, (uint8_t *)&reply->readdir_reply.dirent, sizeof(dirent_t)); free(message); free(reply); return &dirent; }
/* * Cette fonction initialise la GDT apres que le kernel soit charge * en memoire. Une GDT est deja operationnelle, mais c'est celle qui * a ete initialisee par le secteur de boot et qui ne correspond * pas forcement a celle que l'on souhaite pour bosokernel. */ void init_gdt(void) { struct gdtdesc code, data, stack; /* initialisation des descripteurs de segment */ init_code_desc(0x0, 0xFFFFF, &code); init_data_desc(0x0, 0xFFFFF, &data); init_gdt_desc(0, 0x10, 0x97, 0x0D, &stack); add_gdt_desc(code); add_gdt_desc(data); add_gdt_desc(stack); /* initialisation de la structure pour GDTR */ kgdtr.limite = GDTSIZE*8; kgdtr.base = GDTBASE; /* recopie de la GDT a son adresse */ memcopy(kgdt, kgdtr.base, kgdtr.limite); /* chargement du registre GDTR */ asm("lgdtl (kgdtr)"); /* initialisation des segments */ asm(" movw $0x10,%ax \n \ movw %ax, %ds \n \ movw %ax, %es \n \ movw %ax, %fs \n \ movw %ax, %gs \n \ movw $0x18,%ax \n \ movw %ax, %ss \n \ movl $0x1FFFF,%esp \n \ nop \n \ nop \n \ ljmp $0x08,$next \n \ next: \n"); }
int file_buff_write(void * buf,Inode* p_inode,int offset,int count) { // 1、确定操作位置 if(offset < 0 || offset >= FILE_MAX_SIZE) { printk("write pos out of file offset : %x\n",offset); return -1; // 位置超出范围 } // 2、写入。在缓冲区中操作,如果文件不在缓冲区内,则先读入缓冲区 int buff_offset = offset % BUFF_SIZE; // 确定缓冲区中的操作位置 int buf_offset = 0; // 待写数据中的偏移 int cnt = 0; // 已写入字节数 while(count > 0) { // 1、搜索待写文件是否在缓冲区,如果不在就将其读入缓冲区 BUFF_HEAD* p_bh = scan_buff(p_inode,offset); if(p_bh == 0) { p_bh = get_buff(p_inode,offset); // 申请缓冲区 if(p_bh == 0) return -1; // 缓冲区用完 read_buff(p_bh); // 文件读入缓冲区 } // 2、此时待写文件已经在缓冲区,在缓冲区中写入内容 void* buff_base = p_bh->buff_base; // 缓冲区地址 int buff_remin = BUFF_SIZE - buff_offset; // 缓冲区剩余字节数 if(buff_remin >= count) // 当前缓冲区能容纳所有剩余数据 { memcopy(buff_base + buff_offset,buf + buf_offset,count); cnt += count; // 剩余数据全部写入,然后返回 p_bh->dirty = 1; // 文件缓冲“脏”标志 return cnt; } else // 当前缓冲区不能容纳所有剩余数据 { memcopy(buff_base + buff_offset,buf + buf_offset,buff_remin); buff_offset = 0; // 写满当前缓冲区后循环写下一个缓冲区 buf_offset += buff_remin; count -= buff_remin; cnt += buff_remin; offset += buff_remin; p_bh->dirty = 1; // 文件缓冲“脏”标志 } } return 0; // 不可能到达这里 }
int file_buff_read(void * buf,Inode* p_inode,int offset,int count) { // 1、确定操作位置 if(offset < 0 || offset >= FILE_MAX_SIZE) { printk("read pos out of file offset : %x\n",offset); return -1; // 位置超出范围 } // 2、读取。在缓冲区中操作,如果文件不在缓冲区内,则先读入缓冲区 int buff_offset = offset % BUFF_SIZE; // 确定缓冲区中的操作位置 int buf_offset = 0; // 待读数据中的偏移 int cnt = 0; // 已读取字节数 while(count > 0) { // 1、搜索待读文件是否在缓冲区,如果不在就将其读入缓冲区 BUFF_HEAD* p_bh = scan_buff(p_inode,offset); if(p_bh == 0) { p_bh = get_buff(p_inode,offset); // 申请缓冲区 if(p_bh == 0) return -1; // 缓冲区用完 read_buff(p_bh); // 文件读入缓冲区 //printk("111 i_num : %d buff_base:%x offset: %d \n",p_bh->p_inode->i_num,p_bh->buff_base,p_bh->offset); } // 2、此时待读文件已经在缓冲区,在缓冲区中读取内容 void* buff_base = p_bh->buff_base; // 缓冲区地址 int buff_remin = BUFF_SIZE - buff_offset; // 缓冲区剩余字节数 if(buff_remin >= count) // 当前缓冲区能容纳所有剩余数据 { memcopy(buf + buf_offset,buff_base + buff_offset,count); cnt += count; // 剩余数据全部读取,然后返回 return cnt; } else // 当前缓冲区不能容纳所有剩余数据 { memcopy(buf + buf_offset,buff_base + buff_offset,buff_remin); buff_offset = 0; // 读完当前缓冲区后循环读取下一个缓冲区 buf_offset += buff_remin; count -= buff_remin; cnt += buff_remin; offset += buff_remin; } } return 0; // 不可能到达这里 }
void RecvData(ArgStruct *p) { int nbytes = p->bufflen; char *src = p->s_ptr, *dest = p->r_ptr; return; /* Do nothing */ memcopy(src, dest, nbytes); }
void test_memcopy( Test * pTest) { char *data1 = "Joshua"; char *data2 = "Anna"; char buffer[480] = ""; char big_buffer[480] = ""; size_t len = 0; len = memcopy(&buffer[0], &data1[0], 0, sizeof(data1), sizeof(buffer)); ct_test(pTest, len == sizeof(data1)); ct_test(pTest, memcmp(&buffer[0], &data1[0], len) == 0); len = memcopy(&buffer[0], &data2[0], len, sizeof(data2), sizeof(buffer)); ct_test(pTest, len == sizeof(data2)); len = memcopy(&buffer[0], &big_buffer[0], 1, sizeof(big_buffer), sizeof(buffer)); ct_test(pTest, len == 0); }
unsigned int ArchivedFile::read(void* dest, unsigned int bytes) { bytes = (index + bytes) > size ? size - index : bytes; //if (bytes > 0) memcopy(dest, data + index, bytes); //memcpy(dest, data + index, bytes); index += bytes; return bytes; }
void BusyWork(void) { char array[4096]; int addr = (int)(&PrintLoggedOutMenu) & 0xfffff000; int i = 20; while (i--) { memcopy(array, (char *)addr, 4096); sort_n_sum(array, 4096); } }
void chroot(inode_t *node) { CALLOCP(message, vfsm); message->m.msg_type = VFSM_CHRD; memcopy((uint8_t *)&message->chrd.rd, (uint8_t *)node, sizeof(inode_t)); send2(VFS_PID,message); free(waitmsg(VFS_PID,0)); free(message); }
int enet_socket_bind (ENetSocket socket, const ENetAddress * address) { const size_t length = enet_address_get_size (address); ENetAddress * clone; memcopy (& clone, address, length); clone -> port = ENET_HOST_TO_NET_16 (address -> port); return bind (socket, (struct sockaddr *) clone, length); }
int main() { int src[] = {1,2,3,4,5}, i; int n = sizeof(src) / sizeof(src[0]); int *dst = malloc(n*sizeof(src[0])); memcopy((void*)src,(void*)dst,sizeof(src)); printf ("Destination is: "); for (i=0; i<n; i++) { printf ("%d ", dst[i]); } printf ("\n"); free(dst); return 0; }
stat_t *fstat(uint32_t filp) { CALLOCP(message, vfsm); message->m.msg_type = VFSM_FSTAT; message->fstat.filp = filp; send2(VFS_PID, message); vfsm *reply = (vfsm *)waitmsg(VFS_PID,0); memcopy((uint8_t *)&stat, (uint8_t *)&reply->fstat_reply.node, sizeof(stat_t)); free(message); free(reply); return &stat; }
int enet_address_set_host (ENetAddress * address, const char * name) { struct addrinfo * result_box; int error_code; error_code = getaddrinfo(name, NULL, &hints, &result_box); if (error_code != 0) return error_code; if (result_box == NULL) return -1; memcopy(&address, result_box -> ai_addr, result_box -> ai_addrlen); address -> port = ENET_NET_TO_HOST_16 (address -> port); return error_code; }
/* * Cette fonction initialise la IDT apres que le kernel soit charge * en memoire. */ void init_idt(void) { idtdesc desc; int i; /* initialisation des descripteurs systeme */ for(i=0;i<IDTSIZE;i++) { init_idt_desc(default_int, 0x08, INTGATE, &desc); add_idt_desc(desc); } init_idt_desc(k_int0, 0x08, INTGATE, &kidt[0]); init_idt_desc(k_int1, 0x08, INTGATE, &kidt[1]); init_idt_desc(k_int2, 0x08, INTGATE, &kidt[2]); init_idt_desc(k_int3, 0x08, INTGATE, &kidt[3]); init_idt_desc(k_int4, 0x08, INTGATE, &kidt[4]); init_idt_desc(k_int5, 0x08, INTGATE, &kidt[5]); init_idt_desc(k_int6, 0x08, INTGATE, &kidt[6]); init_idt_desc(k_int7, 0x08, INTGATE, &kidt[7]); init_idt_desc(k_int8, 0x08, INTGATE, &kidt[8]); init_idt_desc(k_int9, 0x08, INTGATE, &kidt[9]); init_idt_desc(k_int10, 0x08, INTGATE, &kidt[10]); init_idt_desc(k_int11, 0x08, INTGATE, &kidt[11]); init_idt_desc(k_int12, 0x08, INTGATE, &kidt[12]); init_idt_desc(k_int13, 0x08, INTGATE, &kidt[13]); init_idt_desc(k_int14, 0x08, INTGATE, &kidt[14]); init_idt_desc(k_int15, 0x08, INTGATE, &kidt[15]); init_idt_desc(k_int16, 0x08, INTGATE, &kidt[16]); init_idt_desc(k_int17, 0x08, INTGATE, &kidt[17]); init_idt_desc(k_int18, 0x08, INTGATE, &kidt[18]); init_idt_desc(k_irq0, 0x08, INTGATE, &kidt[32]); init_idt_desc(k_irq1, 0x08, INTGATE, &kidt[33]); init_idt_desc(k_irq2, 0x08, INTGATE, &kidt[34]); init_idt_desc(k_irq3, 0x08, INTGATE, &kidt[35]); init_idt_desc(k_irq4, 0x08, INTGATE, &kidt[36]); init_idt_desc(k_irq5, 0x08, INTGATE, &kidt[37]); init_idt_desc(k_irq6, 0x08, INTGATE, &kidt[38]); init_idt_desc(k_irq7, 0x08, INTGATE, &kidt[39]); init_idt_desc(k_irq8, 0x08, INTGATE, &kidt[40]); /* initialisation de la structure pour IDTR */ kidtr.limite = IDTSIZE*8; kidtr.base = IDTBASE; /* recopie de la IDT a son adresse */ memcopy(kidt, kidtr.base, kidtr.limite); /* chargement du registre IDTR */ asm("lidtl (kidtr)"); }
static Py_ssize_t _encodedir(char *dest, size_t destsize, const char *src, Py_ssize_t len) { enum dir_state state = DDEFAULT; Py_ssize_t i = 0, destlen = 0; while (i < len) { switch (state) { case DDOT: switch (src[i]) { case 'd': case 'i': state = DHGDI; charcopy(dest, &destlen, destsize, src[i++]); break; case 'h': state = DH; charcopy(dest, &destlen, destsize, src[i++]); break; default: state = DDEFAULT; break; } break; case DH: if (src[i] == 'g') { state = DHGDI; charcopy(dest, &destlen, destsize, src[i++]); } else state = DDEFAULT; break; case DHGDI: if (src[i] == '/') { memcopy(dest, &destlen, destsize, ".hg", 3); charcopy(dest, &destlen, destsize, src[i++]); } state = DDEFAULT; break; case DDEFAULT: if (src[i] == '.') state = DDOT; charcopy(dest, &destlen, destsize, src[i++]); break; } } return destlen; }
void cMatrixStack::copyfrom(cMatrixStack *c) { if (c->levels!=levels) msg("MatrixStack Error",buildstr("Cannot copy a %i level Matrix Stack over a %i level Matrix Stack")); for (uintf i=0; i<levels; i++) { level[i].parent = c->level[i].parent; level[i].pivot = c->level[i].pivot; level[i].rotx = c->level[i].rotx; level[i].roty = c->level[i].roty; level[i].rotz = c->level[i].rotz; float *dm = level[i].mtx; float *sm = c->level[i].mtx; memcopy(dm, sm, sizeof(Matrix)); level[i].current = c->level[i].current; } }
int enet_socket_connect (ENetSocket socket, const ENetAddress * address) { int result; size_t length = enet_address_get_size (address); ENetAddress * clone; memcopy (& clone, address, length); clone -> port = ENET_HOST_TO_NET_16 (address -> port); result = connect (socket, (struct sockaddr *) & clone, length); if (result == -1 && errno == EINPROGRESS) return 0; return result; }
int enet_socket_connect (ENetSocket socket, const ENetAddress * address) { int result; size_t length = enet_address_get_size (address); ENetAddress * clone; memcopy (& clone, address, length); clone -> port = ENET_HOST_TO_NET_16 (address -> port); result = connect (socket, (struct sockaddr *) & clone, length); if (result == SOCKET_ERROR && WSAGetLastError () != WSAEWOULDBLOCK) return -1; return 0; }
int handle_scrolling(int offset) { if (offset < MAX_ROWS * MAX_COLS*2){ return offset; } int i; for (i = 1; i < MAX_ROWS; i++){ memcopy((char*)(get_screen_offset(0, i) + VID_ADDR), (char*)(get_screen_offset(0,i-1) + VID_ADDR), (MAX_COLS * 2)); } char* last_line = (char*) get_screen_offset(0, MAX_ROWS - 1) + VID_ADDR; for (i=0; i < MAX_COLS; i++){ last_line[i] = 0; } offset -= 2*MAX_COLS; return offset; }
void start_task(void *pdata) { INT8U err;//错误码 INT8U *pname; INT8U len;//名字的长度 char buffer[16]; OS_CPU_SR cpu_sr = 0; pdata = pdata; delay_init(168); OS_ENTER_CRITICLE(); //进入临界区 无法被中断打断 OSTaskCreate( led0Task, (void *)0, (OS_STK *)LED0_TASK_STK[LED0_STK_SIZE-1], LED0_TASK_PRIO);//创建LED任务 // OSTaskCreate( beepTask, (void *)0, // (OS_STK *)BEEP_TASK_STK[BEEP_STK_SIZE-1], // BEEP_TASK_PRIO);//创建BEEP任务 //用OSTaskCreateExt改写 OSTaskCreateExt( beepTask, (void *)0, (OS_STK *)BEEP_TASK_STK[BEEP_STK_SIZE-1], BEEP_TASK_PRIO, BEEP_TASK_PRIO,//ID设置为跟优先级一样 (OS_STK *)BEEP_TASK_STK[0],//栈底指针 BEEP_STK_SIZE,//堆栈大小 (void *) 0,//额外参数为空 OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR//使用任务堆栈检查和清零功能 ) OSTaskNameSet(BEEP_TASK_PRIO,(INT8U *)BEEP_NAME,&err);//BEEP_NAME必须为全局变量 len = OSTaskNameGet(BEEP_TASK_PRIO,&pname,&err)//pname本身为一个指针变量, //对pname取地址变成二维指针 memcopy(buffer,pname,len);//把pname的内容拷贝到buffer中 OSTaskSuspend(START_TASK_PRIO);//挂起起始任务 OS_EXIT_CRITICLE(); //退出临界区 可以被中断打断 }
void cMatrixStack::GenerateMatrix(uintf _level) { if (_level == 0) return; sMatrixStackLevel *l = &level[_level]; sMatrixStackLevel *p = &level[l->parent]; if (!p->current) GenerateMatrix(l->parent); memcopy(l->mtx, level[l->parent].mtx, sizeof(Matrix)); movealongx(l->mtx, l->pivot.x); movealongy(l->mtx, l->pivot.y); movealongz(l->mtx, l->pivot.z); if (l->rotx) rotatearoundx(l->mtx, l->rotx); if (l->roty) rotatearoundy(l->mtx, l->roty); if (l->rotz) rotatearoundz(l->mtx, l->rotz); fixrotations(l->mtx); l->current = true; }
size_t scatter(void const * memory, size_t extent, struct field const * field, unsigned fields) { byte const * source = (byte const *) (memory); while ((fields--) && (field->size < extent)) { if (! field->type) { memcopy (field->base, source, field->size); } else { memfold (field->base, source, field->size); } source += field->size; extent -= field->size; field++; } return (source - (byte *) (memory)); }
//----------------------------------------------------------------------------- // Name: dx_getvideoinfo // Desc: //----------------------------------------------------------------------------- void xw_getvideoinfo(void *vidinfo) { videoinfostruct vi; txtcpy(vi.DriverName,sizeof(vi.DriverName),DriverNameUser); txtcpy(vi.AuthorName,sizeof(vi.AuthorName),DriverAuthor); txtcpy(vi.DriverNameShort,sizeof(vi.DriverNameShort),DriverNameshort); txtcpy(vi.LoadingMethod,sizeof(vi.LoadingMethod),"Static"); txtcpy(vi.DeviceDescription,sizeof(vi.DeviceDescription),"XWindows"); vi.MaxTextureWidth = 0; vi.MaxTextureHeight = 0; vi.NumTextureUnits = 0; vi.TextureMemory = 0; vi.MaxAnisotropy = 0; vi.Features = 0; videoinfostruct *dest = (videoinfostruct *)vidinfo; dword size = dest->structsize; if (size>sizeof(videoinfostruct)) size = sizeof(videoinfostruct); memcopy(dest,&vi,size); dest->structsize = size; }
size_t gather (void * memory, size_t extent, struct field const * field, unsigned fields) { byte * target = (byte *)(memory); while ((fields--) && (field->size < extent)) { if (!field->type) { memcopy (target, field->base, field->size); } else { memfold (target, field->base, field->size); } target += field->size; extent -= field->size; field++; } return (target - (byte *)(memory)); }
vnode_t *get_vnode(uint32_t driver_num, uint32_t inode_num) { vnode_t *vnode = find_vnode(driver_num, inode_num); if(!vnode) { vnode = get_free_vnode(); vfs_msg_getnode *getnode_msg = (vfs_msg_getnode *)calloc(sizeof(vfs_msg_getnode)); getnode_msg->msg_type = VFSM_GETNODE; getnode_msg->node.driver_num = driver_num; getnode_msg->node.inode_num = inode_num; send2(driver_num, getnode_msg); free(getnode_msg); getnode_msg = waitmsg(driver_num,0); if(getnode_msg->node.driver_num) { memcopy((uint8_t *)vnode, (uint8_t *)&getnode_msg->node, sizeof(vnode_t)); } else { _syscall_printf("\nGetnode failed!",0); } free(getnode_msg); } return vnode; }
/* Address of the source must already have been loaded in PRI * "size" is the size in bytes (not cells). */ SC_FUNC void copyarray(symbol *sym,cell size) { assert(sym!=NULL); /* the symbol can be a local array, a global array, or an array * that is passed by reference. */ if (sym->ident==iREFARRAY) { /* reference to an array; currently this is always a local variable */ assert(sym->vclass==sLOCAL); /* symbol must be stack relative */ stgwrite("\tload.s.alt "); } else { /* a local or global array */ if (sym->vclass==sLOCAL) stgwrite("\taddr.alt "); else stgwrite("\tconst.alt "); } /* if */ outval(sym->addr,TRUE); markusage(sym,uWRITTEN); code_idx+=opcodes(1)+opargs(1); memcopy(size); }
int enet_socket_send (ENetSocket socket, const ENetAddress * address, const ENetBuffer * buffers, size_t bufferCount) { struct msghdr msgHdr; ENetAddress address_clone; int sentLength; memset (& msgHdr, 0, sizeof (struct msghdr)); if (address != NULL) { msgHdr.msg_name = & address_clone; msgHdr.msg_namelen = enet_address_get_size (address); memcopy (& address_clone, address, msgHdr.msg_namelen); address_clone.port = ENET_HOST_TO_NET_16 (address -> port); } msgHdr.msg_iov = (struct iovec *) buffers; msgHdr.msg_iovlen = bufferCount; sentLength = sendmsg (socket, & msgHdr, MSG_NOSIGNAL); if (sentLength == -1) { if (errno == EWOULDBLOCK) return 0; return -1; } return sentLength; }
size_t ATTR_FUNC( attr_get )( const uint8_t attr_num, void *const to ) { void * from = NULL; size_t size = 0; uint8_t i; // сначала обработка общих атрибутов size = common_attr_get(&common_attrs_32773, attr_num, to); if (size != 0) return size; // иначе обработка атрибутов данного профиля for( i=0; i<TOTAL_ATTRIBUTES; i++ ) if( attributes[i].num == attr_num ) { from = attributes[i].ptr; size = attributes[i].size; break; } if( TOTAL_ATTRIBUTES <= i ) return 0; memcopy(to, from, size); return size; }