vfs: check userland buffers before reading them.
[haiku.git] / src / system / kernel / vm / VMKernelArea.h
blob3ece2371f8d8acb768d9114f1be01d3ed9720b81
1 /*
2 * Copyright 2009-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the NewOS License.
4 */
5 #ifndef VM_KERNEL_AREA_H
6 #define VM_KERNEL_AREA_H
9 #include <util/AVLTree.h>
11 #include <vm/VMArea.h>
14 struct ObjectCache;
15 struct VMKernelAddressSpace;
16 struct VMKernelArea;
19 struct VMKernelAddressRange : AVLTreeNode {
20 public:
21 // range types
22 enum {
23 RANGE_FREE,
24 RANGE_RESERVED,
25 RANGE_AREA
28 public:
29 DoublyLinkedListLink<VMKernelAddressRange> listLink;
30 addr_t base;
31 size_t size;
32 union {
33 VMKernelArea* area;
34 struct {
35 addr_t base;
36 uint32 flags;
37 } reserved;
38 DoublyLinkedListLink<VMKernelAddressRange> freeListLink;
40 int type;
42 public:
43 VMKernelAddressRange(addr_t base, size_t size, int type)
45 base(base),
46 size(size),
47 type(type)
51 VMKernelAddressRange(addr_t base, size_t size,
52 const VMKernelAddressRange* other)
54 base(base),
55 size(size),
56 type(other->type)
58 if (type == RANGE_RESERVED) {
59 reserved.base = other->reserved.base;
60 reserved.flags = other->reserved.flags;
66 struct VMKernelAddressRangeTreeDefinition {
67 typedef addr_t Key;
68 typedef VMKernelAddressRange Value;
70 AVLTreeNode* GetAVLTreeNode(Value* value) const
72 return value;
75 Value* GetValue(AVLTreeNode* node) const
77 return static_cast<Value*>(node);
80 int Compare(addr_t a, const Value* _b) const
82 addr_t b = _b->base;
83 if (a == b)
84 return 0;
85 return a < b ? -1 : 1;
88 int Compare(const Value* a, const Value* b) const
90 return Compare(a->base, b);
94 typedef AVLTree<VMKernelAddressRangeTreeDefinition> VMKernelAddressRangeTree;
97 struct VMKernelAddressRangeGetFreeListLink {
98 typedef DoublyLinkedListLink<VMKernelAddressRange> Link;
100 inline Link* operator()(VMKernelAddressRange* range) const
102 return &range->freeListLink;
105 inline const Link* operator()(const VMKernelAddressRange* range) const
107 return &range->freeListLink;
112 struct VMKernelArea : VMArea, AVLTreeNode {
113 VMKernelArea(VMAddressSpace* addressSpace,
114 uint32 wiring, uint32 protection);
115 ~VMKernelArea();
117 static VMKernelArea* Create(VMAddressSpace* addressSpace,
118 const char* name, uint32 wiring,
119 uint32 protection, ObjectCache* objectCache,
120 uint32 allocationFlags);
122 VMKernelAddressRange* Range() const
123 { return fRange; }
124 void SetRange(VMKernelAddressRange* range)
125 { fRange = range; }
127 private:
128 VMKernelAddressRange* fRange;
132 #endif // VM_KERNEL_AREA_H