diff options
Diffstat (limited to 'libstore')
-rw-r--r-- | libstore/ChangeLog | 10 | ||||
-rw-r--r-- | libstore/bunzip2.c | 10 | ||||
-rw-r--r-- | libstore/copy.c | 21 | ||||
-rw-r--r-- | libstore/encode.c | 47 | ||||
-rw-r--r-- | libstore/gunzip.c | 10 | ||||
-rw-r--r-- | libstore/rdwr.c | 7 | ||||
-rw-r--r-- | libstore/zero.c | 19 |
7 files changed, 75 insertions, 49 deletions
diff --git a/libstore/ChangeLog b/libstore/ChangeLog index 25153114..4528a079 100644 --- a/libstore/ChangeLog +++ b/libstore/ChangeLog @@ -5,6 +5,16 @@ * copy.c: Likewise. * gunzip.c: Likewise. * bunzip2.c: Likewise. + +1999-07-09 Thomas Bushnell, BSG <tb@mit.edu> + + * bunzip2.c (bunzip2): Use mmap instead of vm_allocate. + * copy.c (copy_read): Likewise. + (copy_clone): Likewise. + * encode.c (store_encode): Likewise. + * gunzip.c (gunzip): Likewise. + * rdwr.c (store_read): Likewise. + * zero.c (zero_read): Likewise. 1999-07-08 Roland McGrath <roland@baalperazim.frob.com> diff --git a/libstore/bunzip2.c b/libstore/bunzip2.c index 3b7ecb0e..e1ec5808 100644 --- a/libstore/bunzip2.c +++ b/libstore/bunzip2.c @@ -135,10 +135,9 @@ bunzip2 (struct store *from, void **buf, size_t *buf_len) if (zerr) /* Can't do that, try to make a bigger buffer elsewhere. */ { - new_buf = old_buf; - zerr = - vm_allocate (mach_task_self (), - (vm_address_t *)&new_buf, new_buf_len, 1); + new_buf = mmap (0, new_buf_len, PROT_READ|PROT_WRITE, + MAP_ANON, 0, 0); + zerr = (new_buf == (void *) -1) ? errno : 0; if (zerr) longjmp (zerr_jmp_buf, 1); @@ -171,7 +170,8 @@ bunzip2 (struct store *from, void **buf, size_t *buf_len) /* Try to guess a reasonable output buffer size. */ *buf_len = round_page (from->size * 2); - zerr = vm_allocate (mach_task_self (), (vm_address_t *)buf, *buf_len, 1); + *buf = mmap (0, *buf_len, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + zerr = (*buf == (void *) -1) ? errno : 0; if (zerr) return zerr; diff --git a/libstore/copy.c b/libstore/copy.c index ded612fe..0c1834fa 100644 --- a/libstore/copy.c +++ b/libstore/copy.c @@ -34,10 +34,9 @@ copy_read (struct store *store, if (*len < amount) /* Have to allocate memory for the return value. */ { - error_t err = - vm_allocate (mach_task_self (), (vm_address_t *)buf, amount, 1); - if (err) - return err; + *buf = mmap (0, amount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + if (*buf == (void *)-1)) + return errno; } bcopy (store->hook + (addr * store->block_size), *buf, amount); @@ -124,11 +123,15 @@ copy_cleanup (struct store *store) error_t copy_clone (const struct store *from, struct store *to) { - error_t err = - vm_allocate (mach_task_self (), (vm_address_t *)&to->hook, to->size, 1); - if (! err) - bcopy (from->hook, to->hook, from->size); - return err; + void *buf; + buf = mmap (0, to->size, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + if (buf != (void *) -1) + { + to->hook = buf; + bcopy (from->hook, to->hook, from->size); + return 0; + } + return errno; } struct store_class diff --git a/libstore/encode.c b/libstore/encode.c index f9896a9d..834a0d16 100644 --- a/libstore/encode.c +++ b/libstore/encode.c @@ -1,6 +1,6 @@ /* Store wire encoding - Copyright (C) 1996, 1997 Free Software Foundation, Inc. + Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc. Written by Miles Bader <miles@gnu.ai.mit.edu> This file is part of the GNU Hurd. @@ -80,6 +80,7 @@ store_std_leaf_encode (const struct store *store, struct store_enc *enc) error_t store_encode (const struct store *store, struct store_enc *enc) { + void *buf; error_t err; const struct store_class *class = store->class; /* We zero each vector length for the allocate_encoding method to work, so @@ -100,22 +101,36 @@ store_encode (const struct store *store, struct store_enc *enc) if (err) return err; + errno = 0; if (enc->num_ports > init_num_ports) - err = vm_allocate (mach_task_self (), - (vm_address_t *)&enc->ports, - enc->num_ports * sizeof *enc->ports, 1); - if (!err && enc->num_ints > init_num_ints) - err = vm_allocate (mach_task_self (), - (vm_address_t *)&enc->ints, - enc->num_ints * sizeof *enc->ints, 1); - if (!err && enc->num_offsets > init_num_offsets) - err = vm_allocate (mach_task_self (), - (vm_address_t *)&enc->offsets, - enc->num_offsets * sizeof *enc->offsets, 1); - if (!err && enc->data_len > init_data_len) - err = vm_allocate (mach_task_self (), - (vm_address_t *)&enc->data, enc->data_len, 1); - + { + buf = mmap (0, enc->num_ports * sizeof *enc->ports, + PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + if (buf != (void *) -1) + enc->ports = buf; + } + if (!errno && enc->num_ints > init_num_ints) + { + buf = mmap (0, enc->num_ints * sizeof *enc->ints, + PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + if (buf != (void *) -1) + enc->ints = buf; + } + if (!errno && enc->num_offsets > init_num_offsets) + { + buf = mmap (0, enc->num_offsets * sizeof *enc->offsets, + PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + if (buf != (void *) -1) + enc->offsets = buf; + + } + if (!errno && enc->data_len > init_data_len) + { + buf = mmap (0, enc->data_len, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + if (buf != (void *) -1) + enc->data = buf; + } + err = errno if (! err) err = (*class->encode) (store, enc); diff --git a/libstore/gunzip.c b/libstore/gunzip.c index eb2355e8..2e868219 100644 --- a/libstore/gunzip.c +++ b/libstore/gunzip.c @@ -142,10 +142,9 @@ gunzip (struct store *from, void **buf, size_t *buf_len) if (zerr) /* Can't do that, try to make a bigger buffer elsewhere. */ { - new_buf = old_buf; - zerr = - vm_allocate (mach_task_self (), - (vm_address_t *)&new_buf, new_buf_len, 1); + new_buf = mmap (0, new_buf_len, PROT_READ|PROT_WRITE, + MAP_ANON, 0, 0); + zerr = (new_buf == (void *) -1) ? errno : 0; if (zerr) longjmp (zerr_jmp_buf, 1); @@ -178,7 +177,8 @@ gunzip (struct store *from, void **buf, size_t *buf_len) /* Try to guess a reasonable output buffer size. */ *buf_len = round_page (from->size * 2); - zerr = vm_allocate (mach_task_self (), (vm_address_t *)buf, *buf_len, 1); + *buf = mmap (0, *buf_len, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + zerr = (*buf == (void *) -1) ? errno : 0; if (zerr) return zerr; diff --git a/libstore/rdwr.c b/libstore/rdwr.c index 42006ad5..c5059536 100644 --- a/libstore/rdwr.c +++ b/libstore/rdwr.c @@ -226,10 +226,9 @@ store_read (struct store *store, make room. */ { whole_buf_len = amount; - err = vm_allocate (mach_task_self (), - (vm_address_t *)&whole_buf, amount, 1); - if (err) - return err; /* Punt early, there's nothing to clean up. */ + whole_buf = mmap (0, amount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + if (whole_buf == (void *) -1) + return errno; /* Punt early, there's nothing to clean up. */ } buf_end = whole_buf; diff --git a/libstore/zero.c b/libstore/zero.c index d94cbdcf..33e34142 100644 --- a/libstore/zero.c +++ b/libstore/zero.c @@ -1,6 +1,6 @@ /* Zero store backend - Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 1997, 1999 Free Software Foundation, Inc. Written by Miles Bader <miles@gnu.ai.mit.edu> This file is part of the GNU Hurd. @@ -32,18 +32,17 @@ zero_read (struct store *store, { if (*len < amount) { - error_t err = - vm_allocate (mach_task_self (), (vm_address_t *)buf, amount, 1); - if (! err) - *len = amount; - return err; - } - else - { - bzero (*buf, amount); + *buf = mmap (0, amount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); + if (*buf == (void *) -1) + return errno; *len = amount; return 0; } + else + bzero (*buf, amount); + + *len = amount; + return 0; } static error_t |