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:
parent
5559377532
commit
0ac60d68ea
6 changed files with 26 additions and 30 deletions
|
@ -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*/)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue