* Moved memset_physical() to vm.cpp and made it available in the kernel.
* Added memcpy_to_physical(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28219 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -99,6 +99,10 @@ uint32 vm_num_page_faults(void);
|
|||||||
off_t vm_available_memory(void);
|
off_t vm_available_memory(void);
|
||||||
off_t vm_available_not_needed_memory(void);
|
off_t vm_available_not_needed_memory(void);
|
||||||
|
|
||||||
|
status_t memset_physical(addr_t address, int value, size_t length);
|
||||||
|
status_t memcpy_to_physical(addr_t to, const void* from, size_t length,
|
||||||
|
bool user);
|
||||||
|
|
||||||
// user syscalls
|
// user syscalls
|
||||||
area_id _user_create_area(const char *name, void **address, uint32 addressSpec,
|
area_id _user_create_area(const char *name, void **address, uint32 addressSpec,
|
||||||
size_t size, uint32 lock, uint32 protection);
|
size_t size, uint32 lock, uint32 protection);
|
||||||
|
|||||||
-24
@@ -16,30 +16,6 @@
|
|||||||
#include "io_requests.h"
|
#include "io_requests.h"
|
||||||
|
|
||||||
|
|
||||||
static inline status_t
|
|
||||||
memset_physical(addr_t address, int value, size_t length)
|
|
||||||
{
|
|
||||||
while (length > 0) {
|
|
||||||
addr_t pageOffset = address % B_PAGE_SIZE;
|
|
||||||
addr_t virtualAddress;
|
|
||||||
status_t error = vm_get_physical_page(address - pageOffset,
|
|
||||||
&virtualAddress, 0);
|
|
||||||
if (error != B_OK)
|
|
||||||
return error;
|
|
||||||
|
|
||||||
size_t toSet = min_c(length, B_PAGE_SIZE - pageOffset);
|
|
||||||
memset((void*)(virtualAddress + pageOffset), value, toSet);
|
|
||||||
|
|
||||||
vm_put_physical_page(virtualAddress);
|
|
||||||
|
|
||||||
length -= toSet;
|
|
||||||
address += toSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
VMVnodeCache::Init(struct vnode *vnode)
|
VMVnodeCache::Init(struct vnode *vnode)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5162,6 +5162,70 @@ vm_resize_area(area_id areaID, size_t newSize, bool kernel)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
memset_physical(addr_t address, int value, size_t length)
|
||||||
|
{
|
||||||
|
ThreadCPUPinner _(thread_get_current_thread());
|
||||||
|
|
||||||
|
while (length > 0) {
|
||||||
|
addr_t pageOffset = address % B_PAGE_SIZE;
|
||||||
|
addr_t virtualAddress;
|
||||||
|
status_t error = vm_get_physical_page(address - pageOffset,
|
||||||
|
&virtualAddress, 0);
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
size_t toSet = min_c(length, B_PAGE_SIZE - pageOffset);
|
||||||
|
memset((void*)(virtualAddress + pageOffset), value, toSet);
|
||||||
|
|
||||||
|
vm_put_physical_page(virtualAddress);
|
||||||
|
|
||||||
|
length -= toSet;
|
||||||
|
address += toSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
memcpy_to_physical(addr_t to, const void* _from, size_t length, bool user)
|
||||||
|
{
|
||||||
|
const uint8* from = (const uint8*)_from;
|
||||||
|
addr_t pageOffset = to % B_PAGE_SIZE;
|
||||||
|
|
||||||
|
ThreadCPUPinner _(thread_get_current_thread());
|
||||||
|
|
||||||
|
while (length > 0) {
|
||||||
|
size_t toCopy = min_c(length, B_PAGE_SIZE - pageOffset);
|
||||||
|
|
||||||
|
addr_t virtualAddress;
|
||||||
|
status_t error = vm_get_physical_page(to - pageOffset, &virtualAddress,
|
||||||
|
0);
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
error = user_memcpy((void*)(virtualAddress + pageOffset), from,
|
||||||
|
toCopy);
|
||||||
|
} else
|
||||||
|
memcpy((void*)(virtualAddress + pageOffset), from, toCopy);
|
||||||
|
|
||||||
|
vm_put_physical_page(virtualAddress);
|
||||||
|
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
to += toCopy;
|
||||||
|
from += toCopy;
|
||||||
|
length -= toCopy;
|
||||||
|
pageOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - kernel public API
|
// #pragma mark - kernel public API
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user