diff options
author | Robert Morris <[email protected]> | 2019-06-04 05:57:47 -0400 |
---|---|---|
committer | Robert Morris <[email protected]> | 2019-06-04 05:57:47 -0400 |
commit | 8baac760500980d4b83e8de2e90265bfaa19df13 (patch) | |
tree | ceb59412ec44ff98c1281627fb648deaeedb0d04 /pipe.c | |
parent | cefe223bf5e4b68e5c1202f2f089a164ad656621 (diff) | |
download | xv6-labs-8baac760500980d4b83e8de2e90265bfaa19df13.tar.gz xv6-labs-8baac760500980d4b83e8de2e90265bfaa19df13.tar.bz2 xv6-labs-8baac760500980d4b83e8de2e90265bfaa19df13.zip |
support read() and write() bigger than one page
Diffstat (limited to 'pipe.c')
-rw-r--r-- | pipe.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -76,9 +76,11 @@ pipeclose(struct pipe *p, int writable) //PAGEBREAK: 40 int -pipewrite(struct pipe *p, char *addr, int n) +pipewrite(struct pipe *p, uint64 addr, int n) { int i; + char ch; + struct proc *pr = myproc(); acquire(&p->lock); for(i = 0; i < n; i++){ @@ -90,7 +92,9 @@ pipewrite(struct pipe *p, char *addr, int n) wakeup(&p->nread); sleep(&p->nwrite, &p->lock); //DOC: pipewrite-sleep } - p->data[p->nwrite++ % PIPESIZE] = addr[i]; + if(copyin(pr->pagetable, &ch, addr + i, 1) == -1) + break; + p->data[p->nwrite++ % PIPESIZE] = ch; } wakeup(&p->nread); //DOC: pipewrite-wakeup1 release(&p->lock); @@ -98,9 +102,11 @@ pipewrite(struct pipe *p, char *addr, int n) } int -piperead(struct pipe *p, char *addr, int n) +piperead(struct pipe *p, uint64 addr, int n) { int i; + struct proc *pr = myproc(); + char ch; acquire(&p->lock); while(p->nread == p->nwrite && p->writeopen){ //DOC: pipe-empty @@ -113,7 +119,9 @@ piperead(struct pipe *p, char *addr, int n) for(i = 0; i < n; i++){ //DOC: piperead-copy if(p->nread == p->nwrite) break; - addr[i] = p->data[p->nread++ % PIPESIZE]; + ch = p->data[p->nread++ % PIPESIZE]; + if(copyout(pr->pagetable, addr + i, &ch, 1) == -1) + break; } wakeup(&p->nwrite); //DOC: piperead-wakeup release(&p->lock); |