1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Add function for clearing user-space memory from the kernel.

This commit is contained in:
Jonas 'Sortie' Termansen 2014-01-11 23:07:45 +01:00
parent 5559377532
commit 0ac60d68ea
6 changed files with 26 additions and 30 deletions

View file

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2013.
Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
This file is part of Sortix.
@ -69,18 +69,8 @@ off_t Zero::lseek(ioctx_t* /*ctx*/, off_t offset, int /*whence*/)
ssize_t Zero::read(ioctx_t* ctx, uint8_t* buf, size_t count)
{
const size_t ZERO_MEM_SIZE = 128;
uint8_t zero_mem[ZERO_MEM_SIZE];
memset(zero_mem, 0, ZERO_MEM_SIZE);
size_t sofar = 0;
while ( sofar < count )
{
size_t left = count - sofar;
size_t amount = left < ZERO_MEM_SIZE ? left : ZERO_MEM_SIZE;
ctx->copy_to_dest(buf + sofar, zero_mem, amount);
sofar += amount;
}
return (ssize_t) sofar;
ctx->zero_dest(buf, count);
return (ssize_t) count;
}
ssize_t Zero::pread(ioctx_t* ctx, uint8_t* buf, size_t count, off_t /*off*/)