i386_copy.c revision 38712
138712Smsmith/* 238712Smsmith * mjs copyright 338712Smsmith */ 438712Smsmith/* 538712Smsmith * MD primitives supporting placement of module data 638712Smsmith * 738712Smsmith * XXX should check load address/size against memory top. 838712Smsmith */ 938712Smsmith#include <stand.h> 1038712Smsmith 1138712Smsmith#include "libi386.h" 1238712Smsmith 1338712Smsmith#define READIN_BUF 4096 1438712Smsmith 1538712Smsmithint 1638712Smsmithi386_copyin(void *src, vm_offset_t dest, size_t len) 1738712Smsmith{ 1838712Smsmith vpbcopy(src, dest, len); 1938712Smsmith return(len); 2038712Smsmith} 2138712Smsmith 2238712Smsmithint 2338712Smsmithi386_readin(int fd, vm_offset_t dest, size_t len) 2438712Smsmith{ 2538712Smsmith void *buf; 2638712Smsmith size_t resid, chunk, get, got; 2738712Smsmith 2838712Smsmith chunk = min(READIN_BUF, len); 2938712Smsmith buf = malloc(chunk); 3038712Smsmith if (buf == NULL) 3138712Smsmith return(0); 3238712Smsmith 3338712Smsmith for (resid = len; resid > 0; resid -= got, dest += got) { 3438712Smsmith get = min(chunk, resid); 3538712Smsmith got = read(fd, buf, get); 3638712Smsmith if (got <= 0) 3738712Smsmith break; 3838712Smsmith vpbcopy(buf, dest, chunk); 3938712Smsmith } 4038712Smsmith free(buf); 4138712Smsmith if (resid != 0) 4238712Smsmith printf("i386_readin: %d bytes short\n", resid); 4338712Smsmith return(len - resid); 4438712Smsmith} 4538712Smsmith 4638712Smsmith 47