diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2021-08-22 01:32:05 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2021-08-22 01:32:05 +0200 |
commit | cd10e825fe4b5458c0deaa300449e0cd872570ef (patch) | |
tree | c031a76e99b60278d5d042078b6c21239290e2de /rumpdisk | |
parent | 755419de31af8510a8c0eca07348516acd918e6b (diff) | |
download | hurd-cd10e825fe4b5458c0deaa300449e0cd872570ef.tar.gz hurd-cd10e825fe4b5458c0deaa300449e0cd872570ef.tar.bz2 hurd-cd10e825fe4b5458c0deaa300449e0cd872570ef.zip |
rumpdisk: Simplify allocating data for device_read
* rumpdisk/block-rump.c (rumpdisk_device_read): Use
vm_allocate/vm_deallocate instead of mmap/munmap.
Diffstat (limited to 'rumpdisk')
-rw-r--r-- | rumpdisk/block-rump.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/rumpdisk/block-rump.c b/rumpdisk/block-rump.c index 2c083cb2..92d099be 100644 --- a/rumpdisk/block-rump.c +++ b/rumpdisk/block-rump.c @@ -309,10 +309,11 @@ rumpdisk_device_read (void *d, mach_port_t reply_port, unsigned *bytes_read) { struct block_data *bd = d; - char *buf; + vm_address_t buf; int pagesize = sysconf (_SC_PAGE_SIZE); int npages = (count + pagesize - 1) / pagesize; ssize_t err; + kern_return_t ret; if ((bd->mode & D_READ) == 0) return D_INVALID_OPERATION; @@ -321,22 +322,21 @@ rumpdisk_device_read (void *d, mach_port_t reply_port, return D_SUCCESS; *data = 0; - buf = mmap (NULL, npages * pagesize, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); - if (buf == MAP_FAILED) - return errno; + ret = vm_allocate (mach_task_self (), &buf, npages * pagesize, TRUE); + if (ret != KERN_SUCCESS) + return ENOMEM; err = rump_sys_pread (bd->rump_fd, (void *)buf, (size_t)count, (off_t)bn * bd->block_size); if (err < 0) { *bytes_read = 0; - munmap (buf, npages * pagesize); + vm_deallocate (mach_task_self (), buf, npages * pagesize); return EIO; } else { *bytes_read = err; - *data = buf; + *data = (void*) buf; return D_SUCCESS; } } |