From: Philip Homburg Date: Mon, 26 Jun 2006 14:20:11 +0000 (+0000) Subject: Vectored safe copies for inet. X-Git-Tag: v3.1.3~287 X-Git-Url: http://zhaoyanbai.com/repos/%22/xml/v3/zones/static/Bv9ARM.ch07.html?a=commitdiff_plain;h=de07a562d1279ab4f3d758450a5409c31dfc0149;p=minix.git Vectored safe copies for inet. --- diff --git a/servers/inet/sr.c b/servers/inet/sr.c index 2ece45778..954fe3a06 100644 --- a/servers/inet/sr.c +++ b/servers/inet/sr.c @@ -78,6 +78,7 @@ PRIVATE mq_t *repl_queue, *repl_queue_tail; PRIVATE cpvec_t cpvec[CPVEC_NR]; #else /* Minix 3 */ PRIVATE struct vir_cp_req vir_cp_req[CPVEC_NR]; +PRIVATE struct vscp_vec s_cp_req[CPVEC_NR]; #endif FORWARD _PROTOTYPE ( int sr_open, (message *m) ); @@ -1269,16 +1270,15 @@ char *dest; return OK; } -#if 0 -PRIVATE int cp_u2b_s (proc, src, var_acc_ptr, size) +PRIVATE int cp_u2b_s(proc, gid, offset, var_acc_ptr, size) int proc; -char *src; +int gid; +vir_bytes offset; acc_t **var_acc_ptr; int size; { - static message mess; acc_t *acc; - int i; + int i, r; acc= bf_memreq(size); @@ -1289,99 +1289,58 @@ int size; { size= (vir_bytes)acc->acc_length; -#ifdef __minix_vmd - cpvec[i].cpv_src= (vir_bytes)src; - cpvec[i].cpv_dst= (vir_bytes)ptr2acc_data(acc); - cpvec[i].cpv_size= size; -#else /* Minix 3 */ - vir_cp_req[i].count= size; - vir_cp_req[i].src.proc_nr_e = proc; - vir_cp_req[i].src.segment = D; - vir_cp_req[i].src.offset = (vir_bytes) src; - vir_cp_req[i].dst.proc_nr_e = this_proc; - vir_cp_req[i].dst.segment = D; - vir_cp_req[i].dst.offset = (vir_bytes) ptr2acc_data(acc); -#endif + s_cp_req[i].v_from= proc; + s_cp_req[i].v_to= SELF; + s_cp_req[i].v_gid= gid; + s_cp_req[i].v_offset= offset; + s_cp_req[i].v_addr= (vir_bytes) ptr2acc_data(acc); + s_cp_req[i].v_bytes= size; - src += size; + offset += size; acc= acc->acc_next; i++; - if (i == CPVEC_NR || acc == NULL) + if (acc == NULL && i == 1) { -#ifdef __minix_vmd - mess.m_type= SYS_VCOPY; - mess.m1_i1= proc; - mess.m1_i2= this_proc; - mess.m1_i3= i; - mess.m1_p1= (char *)cpvec; -#else /* Minix 3 */ - mess.m_type= SYS_VIRVCOPY; - mess.VCP_VEC_SIZE= i; - mess.VCP_VEC_ADDR= (char *)vir_cp_req; -#endif - if (sendrec(SYSTASK, &mess) <0) - ip_panic(("unable to sendrec")); - if (mess.m_type <0) + r= sys_safecopyfrom(s_cp_req[0].v_from, + s_cp_req[0].v_gid, s_cp_req[0].v_offset, + s_cp_req[0].v_addr, s_cp_req[0].v_bytes, D); + if (r <0) { + printf("sys_safecopyfrom failed: %d\n", r); bf_afree(*var_acc_ptr); *var_acc_ptr= 0; - return mess.m_type; + return r; } i= 0; + continue; } - } - return OK; -} -#else -PRIVATE int cp_u2b_s (proc, gid, offset, var_acc_ptr, size) -int proc; -int gid; -vir_bytes offset; -acc_t **var_acc_ptr; -int size; -{ - static message mess; - acc_t *acc; - int r; - - acc= bf_memreq(size); - - *var_acc_ptr= acc; - - while (acc) - { - size= (vir_bytes)acc->acc_length; - - r= sys_safecopyfrom(proc, gid, - offset, (vir_bytes)ptr2acc_data(acc), - size, D); - if (r != OK) + if (i == CPVEC_NR || acc == NULL) { - printf("cp_u2b_s: sys_safecopyfrom failed: %d\n", - r); - bf_afree(*var_acc_ptr); - *var_acc_ptr= 0; - return r; - } - offset += size; + r= sys_vsafecopy(s_cp_req, i); - acc= acc->acc_next; + if (r <0) + { + printf("cp_u2b_s: sys_vsafecopy failed: %d\n", + r); + bf_afree(*var_acc_ptr); + *var_acc_ptr= 0; + return r; + } + i= 0; + } } return OK; } -#endif -#if 0 -PRIVATE int cp_b2u_s(acc_ptr, proc, dest, offset) +PRIVATE int cp_b2u_s(acc_ptr, proc, gid, offset) acc_t *acc_ptr; int proc; -char *dest; +int gid; vir_bytes offset; { - static message mess; acc_t *acc; - int i, size; + int i, r, size; acc= acc_ptr; i=0; @@ -1392,89 +1351,50 @@ vir_bytes offset; if (size) { -#ifdef __minix_vmd - cpvec[i].cpv_src= (vir_bytes)ptr2acc_data(acc); - cpvec[i].cpv_dst= (vir_bytes)dest; - cpvec[i].cpv_size= size; -#else /* Minix 3 */ - vir_cp_req[i].src.proc_nr_e = this_proc; - vir_cp_req[i].src.segment = D; - vir_cp_req[i].src.offset= (vir_bytes)ptr2acc_data(acc); - vir_cp_req[i].dst.proc_nr_e = proc; - vir_cp_req[i].dst.segment = D; - vir_cp_req[i].dst.offset= (vir_bytes)dest; - vir_cp_req[i].count= size; -#endif + s_cp_req[i].v_from= SELF; + s_cp_req[i].v_to= proc; + s_cp_req[i].v_gid= gid; + s_cp_req[i].v_offset= offset; + s_cp_req[i].v_addr= (vir_bytes) ptr2acc_data(acc); + s_cp_req[i].v_bytes= size; + i++; } - dest += size; + offset += size; acc= acc->acc_next; - if (i == CPVEC_NR || acc == NULL) + if (acc == NULL && i == 1) { -#ifdef __minix_vmd - mess.m_type= SYS_VCOPY; - mess.m1_i1= this_proc; - mess.m1_i2= proc; - mess.m1_i3= i; - mess.m1_p1= (char *)cpvec; -#else /* Minix 3 */ - mess.m_type= SYS_VIRVCOPY; - mess.VCP_VEC_SIZE= i; - mess.VCP_VEC_ADDR= (char *) vir_cp_req; -#endif - if (sendrec(SYSTASK, &mess) <0) - ip_panic(("unable to sendrec")); - if (mess.m_type <0) + r= sys_safecopyto(s_cp_req[0].v_to, + s_cp_req[0].v_gid, s_cp_req[0].v_offset, + s_cp_req[0].v_addr, s_cp_req[0].v_bytes, D); + if (r <0) { + printf("sys_safecopyto failed: %d\n", r); bf_afree(acc_ptr); - return mess.m_type; + return r; } i= 0; + continue; } - } - bf_afree(acc_ptr); - return OK; -} -#else -PRIVATE int cp_b2u_s(acc_ptr, proc, gid, offset) -acc_t *acc_ptr; -int proc; -int gid; -vir_bytes offset; -{ - static message mess; - acc_t *acc; - int r, size; - - acc= acc_ptr; - - while (acc) - { - size= (vir_bytes)acc->acc_length; - - if (size) + if (i == CPVEC_NR || acc == NULL) { - r= sys_safecopyto(proc, gid, - offset, (vir_bytes)ptr2acc_data(acc), - size, D); - if (r != OK) + r= sys_vsafecopy(s_cp_req, i); + + if (r <0) { - printf("cp_b2u_s: sys_safecopyto failed: %d\n", + printf("cp_b2u_s: sys_vsafecopy failed: %d\n", r); bf_afree(acc_ptr); return r; } - offset += size; + i= 0; } - - acc= acc->acc_next; } bf_afree(acc_ptr); return OK; } -#endif PRIVATE int sr_repl_queue(proc, ref, operation) int proc;