From 8a16a1a0c90b480a9cc97ed86ebad6c18ec35adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 14 Dec 2004 02:39:37 +0000 Subject: [PATCH] lock_memory() now at least makes sure that the memory range is mapped in. It's a bit hackish due to the iospace area, and it also might not work perfectly in all situations, but it does fulfill the current needs. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10445 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/vm/vm.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/kernel/core/vm/vm.c b/src/kernel/core/vm/vm.c index f660a54b00..a5dcc636ed 100755 --- a/src/kernel/core/vm/vm.c +++ b/src/kernel/core/vm/vm.c @@ -2575,11 +2575,34 @@ user_memset(void *s, char c, size_t count) long -lock_memory(void *buffer, ulong numBytes, ulong flags) +lock_memory(void *address, ulong numBytes, ulong flags) { - // The NewOS VM currently doesn't support locking - dunno if we'll - // ever change this, but if, we should definitely implement these - // functions :-) + addr_t base = (addr_t)address; + addr_t end = base + numBytes; + bool isUser = IS_USER_ADDRESS(address); + + // ToDo: Our VM currently doesn't support locking, this function + // will now at least make sure that the memory is paged in, but + // that's about it. + // Nevertheless, it must be implemented as soon as we're able to + // swap pages out of memory. + + // ToDo: this is a hack, too; the iospace area is a null region and + // officially cannot be written to or read; ie. vm_soft_fault() will + // fail there. Furthermore, this is x86 specific as well. + #define IOSPACE_SIZE (256 * 1024 * 1024) + if (base >= KERNEL_BASE + IOSPACE_SIZE && base + numBytes < KERNEL_BASE + 2 * IOSPACE_SIZE) + return B_OK; + + for (; base < end; base += B_PAGE_SIZE) { + status_t status = vm_soft_fault(base, (flags & B_READ_DEVICE) != 0, isUser); + if (status != B_OK) { + dprintf("lock_memory(address = %p, numBytes = %lu, flags = %lu) failed: %s\n", + address, numBytes, flags, strerror(status)); + return status; + } + } + return B_OK; }