2009-12-02 22:55:59 +03:00
|
|
|
/*
|
2010-05-02 00:41:57 +04:00
|
|
|
* Copyright 2009-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
|
2009-12-02 22:55:59 +03:00
|
|
|
* Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
|
|
|
* Distributed under the terms of the NewOS License.
|
|
|
|
*/
|
|
|
|
#ifndef _KERNEL_VM_VM_AREA_H
|
|
|
|
#define _KERNEL_VM_VM_AREA_H
|
|
|
|
|
|
|
|
|
2010-05-02 00:41:57 +04:00
|
|
|
#include <vm_defs.h>
|
|
|
|
|
2009-12-02 22:55:59 +03:00
|
|
|
#include <lock.h>
|
2009-12-03 15:41:11 +03:00
|
|
|
#include <util/DoublyLinkedList.h>
|
2010-04-03 22:01:29 +04:00
|
|
|
#include <util/SinglyLinkedList.h>
|
2009-12-02 22:55:59 +03:00
|
|
|
#include <util/OpenHashTable.h>
|
|
|
|
#include <vm/vm_types.h>
|
|
|
|
|
|
|
|
|
|
|
|
struct VMAddressSpace;
|
|
|
|
struct VMCache;
|
2009-12-04 17:45:08 +03:00
|
|
|
struct VMKernelAddressSpace;
|
|
|
|
struct VMUserAddressSpace;
|
2009-12-02 22:55:59 +03:00
|
|
|
|
|
|
|
|
2010-04-03 22:01:29 +04:00
|
|
|
struct VMAreaUnwiredWaiter
|
|
|
|
: public DoublyLinkedListLinkImpl<VMAreaUnwiredWaiter> {
|
|
|
|
VMArea* area;
|
|
|
|
addr_t base;
|
|
|
|
size_t size;
|
|
|
|
ConditionVariable condition;
|
|
|
|
ConditionVariableEntry waitEntry;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef DoublyLinkedList<VMAreaUnwiredWaiter> VMAreaUnwiredWaiterList;
|
|
|
|
|
|
|
|
|
|
|
|
struct VMAreaWiredRange : SinglyLinkedListLinkImpl<VMAreaWiredRange> {
|
|
|
|
VMArea* area;
|
|
|
|
addr_t base;
|
|
|
|
size_t size;
|
|
|
|
bool writable;
|
|
|
|
bool implicit; // range created automatically
|
|
|
|
VMAreaUnwiredWaiterList waiters;
|
|
|
|
|
2010-04-11 19:07:06 +04:00
|
|
|
VMAreaWiredRange()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-04-03 22:01:29 +04:00
|
|
|
VMAreaWiredRange(addr_t base, size_t size, bool writable, bool implicit)
|
|
|
|
:
|
|
|
|
area(NULL),
|
|
|
|
base(base),
|
|
|
|
size(size),
|
|
|
|
writable(writable),
|
|
|
|
implicit(implicit)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-04-11 19:07:06 +04:00
|
|
|
void SetTo(addr_t base, size_t size, bool writable, bool implicit)
|
|
|
|
{
|
|
|
|
this->area = NULL;
|
|
|
|
this->base = base;
|
|
|
|
this->size = size;
|
|
|
|
this->writable = writable;
|
|
|
|
this->implicit = implicit;
|
|
|
|
}
|
|
|
|
|
2010-04-03 22:01:29 +04:00
|
|
|
bool IntersectsWith(addr_t base, size_t size) const
|
|
|
|
{
|
|
|
|
return this->base + this->size - 1 >= base
|
|
|
|
&& base + size - 1 >= this->base;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef SinglyLinkedList<VMAreaWiredRange> VMAreaWiredRangeList;
|
|
|
|
|
|
|
|
|
2010-04-11 19:07:06 +04:00
|
|
|
struct VMPageWiringInfo {
|
|
|
|
VMAreaWiredRange range;
|
2010-05-26 01:34:08 +04:00
|
|
|
phys_addr_t physicalAddress;
|
2010-04-11 19:07:06 +04:00
|
|
|
// the actual physical address corresponding to
|
|
|
|
// the virtual address passed to vm_wire_page()
|
|
|
|
// (i.e. with in-page offset)
|
|
|
|
vm_page* page;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-12-02 22:55:59 +03:00
|
|
|
struct VMArea {
|
2014-10-29 14:32:37 +03:00
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
// AddWaiterIfWired() flags
|
|
|
|
IGNORE_WRITE_WIRED_RANGES = 0x01, // ignore existing ranges that
|
|
|
|
// wire for writing
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2009-12-02 22:55:59 +03:00
|
|
|
area_id id;
|
2019-07-13 05:41:21 +03:00
|
|
|
char name[B_OS_NAME_LENGTH];
|
2009-12-02 22:55:59 +03:00
|
|
|
uint32 protection;
|
2021-03-17 17:37:44 +03:00
|
|
|
uint32 protection_max;
|
2009-12-02 22:55:59 +03:00
|
|
|
uint16 wiring;
|
|
|
|
|
2010-05-02 00:41:57 +04:00
|
|
|
private:
|
|
|
|
uint16 memory_type; // >> shifted by MEMORY_TYPE_SHIFT
|
|
|
|
|
|
|
|
public:
|
2009-12-02 22:55:59 +03:00
|
|
|
VMCache* cache;
|
|
|
|
vint32 no_cache_change;
|
|
|
|
off_t cache_offset;
|
|
|
|
uint32 cache_type;
|
|
|
|
VMAreaMappings mappings;
|
|
|
|
uint8* page_protections;
|
|
|
|
|
|
|
|
struct VMAddressSpace* address_space;
|
|
|
|
struct VMArea* cache_next;
|
|
|
|
struct VMArea* cache_prev;
|
|
|
|
struct VMArea* hash_next;
|
|
|
|
|
2009-12-03 17:18:24 +03:00
|
|
|
addr_t Base() const { return fBase; }
|
|
|
|
size_t Size() const { return fSize; }
|
|
|
|
|
2010-05-02 00:41:57 +04:00
|
|
|
inline uint32 MemoryType() const;
|
|
|
|
inline void SetMemoryType(uint32 memoryType);
|
|
|
|
|
2009-12-03 15:41:11 +03:00
|
|
|
bool ContainsAddress(addr_t address) const
|
2009-12-03 17:18:24 +03:00
|
|
|
{ return address >= fBase
|
|
|
|
&& address <= fBase + (fSize - 1); }
|
2009-12-03 15:41:11 +03:00
|
|
|
|
2010-04-03 22:01:29 +04:00
|
|
|
bool IsWired() const
|
|
|
|
{ return !fWiredRanges.IsEmpty(); }
|
|
|
|
bool IsWired(addr_t base, size_t size) const;
|
|
|
|
|
|
|
|
void Wire(VMAreaWiredRange* range);
|
|
|
|
void Unwire(VMAreaWiredRange* range);
|
2010-04-05 16:12:36 +04:00
|
|
|
VMAreaWiredRange* Unwire(addr_t base, size_t size, bool writable);
|
2010-04-03 22:01:29 +04:00
|
|
|
|
|
|
|
bool AddWaiterIfWired(VMAreaUnwiredWaiter* waiter);
|
|
|
|
bool AddWaiterIfWired(VMAreaUnwiredWaiter* waiter,
|
2014-10-29 14:32:37 +03:00
|
|
|
addr_t base, size_t size, uint32 flags = 0);
|
2010-04-03 22:01:29 +04:00
|
|
|
|
2009-12-04 20:07:16 +03:00
|
|
|
protected:
|
|
|
|
VMArea(VMAddressSpace* addressSpace,
|
|
|
|
uint32 wiring, uint32 protection);
|
|
|
|
~VMArea();
|
|
|
|
|
2010-01-27 15:45:53 +03:00
|
|
|
status_t Init(const char* name, uint32 allocationFlags);
|
2009-12-04 20:07:16 +03:00
|
|
|
|
|
|
|
protected:
|
2017-12-02 04:27:15 +03:00
|
|
|
friend struct VMAddressSpace;
|
|
|
|
friend struct VMKernelAddressSpace;
|
|
|
|
friend struct VMUserAddressSpace;
|
2009-12-03 18:21:18 +03:00
|
|
|
|
2009-12-04 20:07:16 +03:00
|
|
|
protected:
|
2009-12-03 18:21:18 +03:00
|
|
|
void SetBase(addr_t base) { fBase = base; }
|
|
|
|
void SetSize(size_t size) { fSize = size; }
|
|
|
|
|
2009-12-04 20:07:16 +03:00
|
|
|
protected:
|
2009-12-03 17:18:24 +03:00
|
|
|
addr_t fBase;
|
|
|
|
size_t fSize;
|
2010-04-03 22:01:29 +04:00
|
|
|
VMAreaWiredRangeList fWiredRanges;
|
2009-12-03 15:41:11 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-12-02 22:55:59 +03:00
|
|
|
struct VMAreaHashDefinition {
|
|
|
|
typedef area_id KeyType;
|
|
|
|
typedef VMArea ValueType;
|
|
|
|
|
|
|
|
size_t HashKey(area_id key) const
|
|
|
|
{
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Hash(const VMArea* value) const
|
|
|
|
{
|
|
|
|
return HashKey(value->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Compare(area_id key, const VMArea* value) const
|
|
|
|
{
|
|
|
|
return value->id == key;
|
|
|
|
}
|
|
|
|
|
|
|
|
VMArea*& GetLink(VMArea* value) const
|
|
|
|
{
|
|
|
|
return value->hash_next;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef BOpenHashTable<VMAreaHashDefinition> VMAreaHashTable;
|
|
|
|
|
|
|
|
|
|
|
|
struct VMAreaHash {
|
|
|
|
static status_t Init();
|
|
|
|
|
|
|
|
static status_t ReadLock()
|
|
|
|
{ return rw_lock_read_lock(&sLock); }
|
|
|
|
static void ReadUnlock()
|
|
|
|
{ rw_lock_read_unlock(&sLock); }
|
|
|
|
static status_t WriteLock()
|
|
|
|
{ return rw_lock_write_lock(&sLock); }
|
|
|
|
static void WriteUnlock()
|
|
|
|
{ rw_lock_write_unlock(&sLock); }
|
|
|
|
|
|
|
|
static VMArea* LookupLocked(area_id id)
|
|
|
|
{ return sTable.Lookup(id); }
|
|
|
|
static VMArea* Lookup(area_id id);
|
|
|
|
static area_id Find(const char* name);
|
|
|
|
static void Insert(VMArea* area);
|
|
|
|
static void Remove(VMArea* area);
|
|
|
|
|
|
|
|
static VMAreaHashTable::Iterator GetIterator()
|
|
|
|
{ return sTable.GetIterator(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
static rw_lock sLock;
|
|
|
|
static VMAreaHashTable sTable;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-05-02 00:41:57 +04:00
|
|
|
uint32
|
|
|
|
VMArea::MemoryType() const
|
|
|
|
{
|
|
|
|
return (uint32)memory_type << MEMORY_TYPE_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
VMArea::SetMemoryType(uint32 memoryType)
|
|
|
|
{
|
|
|
|
memory_type = memoryType >> MEMORY_TYPE_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 22:55:59 +03:00
|
|
|
#endif // _KERNEL_VM_VM_AREA_H
|