1/** 2 * \file 3 * \brief User space memory access functions. 4 */ 5 6/* 7 * Copyright (c) 2012, ETH Zurich. 8 * All rights reserved. 9 * 10 * This file is distributed under the terms in the attached LICENSE file. 11 * If you do not find this file, copies can be found by writing to: 12 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#include <kernel.h> 16#include <useraccess.h> 17#include <barrelfish_kpi/paging_arch.h> 18 19/** 20 * Check the validity of the user space buffer. 21 * 22 * \param type Type of access to check: ACCESS_WRITE or ACCESS_READ. 23 * \param buffer Pointer to beginning of buffer. 24 * \param size Size of buffer in bytes. 25 */ 26bool access_ok(uint8_t type, lvaddr_t buffer, size_t size) 27{ 28 debug(SUBSYS_SYSCALL, "%s: buffer=%#"PRIxLVADDR", size=%zu\n", __FUNCTION__, buffer, size); 29 // Check that the provided buffer is fully in user space, i.e. below MEMORY_OFFSET 30 if (buffer + size >= MEMORY_OFFSET) { 31 return false; 32 } 33 34 // check if we have valid ptentries for base .. base + npages 35 return paging_is_region_valid(buffer, size, type); 36} 37