moved xsemaphore to xthread.d
add typed guest pointer template add X_KSPINLOCK, rework spinlock functions. rework irql related code, use irql on pcr instead of on XThread add guest linked list helper functions renamed ProcessInfoBlock to X_KPROCESS assigned names to many kernel structure fields
This commit is contained in:
committed by
Radosław Gliński
parent
32f7241526
commit
b5ddd30572
@@ -9,7 +9,7 @@ class XModule;
|
||||
class XNotifyListener;
|
||||
class XThread;
|
||||
class UserModule;
|
||||
struct ProcessInfoBlock;
|
||||
struct X_KPROCESS;
|
||||
struct TerminateNotification;
|
||||
struct X_TIME_STAMP_BUNDLE;
|
||||
class KernelState;
|
||||
|
||||
@@ -50,7 +50,134 @@ class NativeList {
|
||||
Memory* memory_ = nullptr;
|
||||
uint32_t head_;
|
||||
};
|
||||
template <typename VirtualTranslator>
|
||||
static X_LIST_ENTRY* XeHostList(uint32_t ptr, VirtualTranslator context) {
|
||||
return context->TranslateVirtual<X_LIST_ENTRY*>(ptr);
|
||||
}
|
||||
template <typename VirtualTranslator>
|
||||
static uint32_t XeGuestList(X_LIST_ENTRY* ptr, VirtualTranslator context) {
|
||||
return context->HostToGuestVirtual(ptr);
|
||||
}
|
||||
|
||||
// can either pass an object that adheres to the
|
||||
// HostToGuestVirtual/TranslateVirtual interface, or the original guest ptr for
|
||||
// arg 2
|
||||
template <typename VirtualTranslator>
|
||||
static void XeInitializeListHead(X_LIST_ENTRY* entry,
|
||||
VirtualTranslator context) {
|
||||
// is just a guest ptr?
|
||||
if constexpr (std::is_unsigned_v<VirtualTranslator>) {
|
||||
entry->blink_ptr = context;
|
||||
entry->flink_ptr = context;
|
||||
} else {
|
||||
uint32_t orig_ptr = XeGuestList(entry, context);
|
||||
entry->blink_ptr = orig_ptr;
|
||||
entry->flink_ptr = orig_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VirtualTranslator>
|
||||
static bool XeIsListEmpty(X_LIST_ENTRY* entry, VirtualTranslator context) {
|
||||
return XeHostList(entry->flink_ptr, context) == entry;
|
||||
}
|
||||
template <typename VirtualTranslator>
|
||||
static void XeRemoveEntryList(X_LIST_ENTRY* entry, VirtualTranslator context) {
|
||||
uint32_t front = entry->flink_ptr;
|
||||
uint32_t back = entry->blink_ptr;
|
||||
XeHostList(back, context)->flink_ptr = front;
|
||||
XeHostList(front, context)->blink_ptr = back;
|
||||
}
|
||||
template <typename VirtualTranslator>
|
||||
static void XeRemoveEntryList(uint32_t entry, VirtualTranslator context) {
|
||||
XeRemoveEntryList(XeHostList(entry, context), context);
|
||||
}
|
||||
template <typename VirtualTranslator>
|
||||
static uint32_t XeRemoveHeadList(X_LIST_ENTRY* entry,
|
||||
VirtualTranslator context) {
|
||||
uint32_t result = entry->flink_ptr;
|
||||
XeRemoveEntryList(result, context);
|
||||
return result;
|
||||
}
|
||||
template <typename VirtualTranslator>
|
||||
static uint32_t XeRemoveTailList(X_LIST_ENTRY* entry,
|
||||
VirtualTranslator context) {
|
||||
uint32_t result = entry->blink_ptr;
|
||||
XeRemoveEntryList(result, context);
|
||||
return result;
|
||||
}
|
||||
template <typename VirtualTranslator>
|
||||
static void XeInsertTailList(X_LIST_ENTRY* list_head, uint32_t list_head_guest,
|
||||
X_LIST_ENTRY* host_entry, uint32_t entry,
|
||||
VirtualTranslator context) {
|
||||
uint32_t old_tail = list_head->blink_ptr;
|
||||
host_entry->flink_ptr = list_head_guest;
|
||||
host_entry->blink_ptr = old_tail;
|
||||
XeHostList(old_tail, context)->flink_ptr = entry;
|
||||
list_head->blink_ptr = entry;
|
||||
}
|
||||
template <typename VirtualTranslator>
|
||||
static void XeInsertTailList(uint32_t list_head, uint32_t entry,
|
||||
VirtualTranslator context) {
|
||||
XeInsertTailList(XeHostList(list_head, context), list_head,
|
||||
XeHostList(entry, context), entry, context);
|
||||
}
|
||||
template <typename VirtualTranslator>
|
||||
static void XeInsertTailList(X_LIST_ENTRY* list_head, uint32_t entry,
|
||||
VirtualTranslator context) {
|
||||
XeInsertTailList(list_head, XeGuestList(list_head, context),
|
||||
XeHostList(entry, context), entry, context);
|
||||
}
|
||||
|
||||
template <typename VirtualTranslator>
|
||||
static void XeInsertTailList(X_LIST_ENTRY* list_head, X_LIST_ENTRY* entry,
|
||||
VirtualTranslator context) {
|
||||
XeInsertTailList(list_head, XeGuestList(list_head, context), entry,
|
||||
XeGuestList(entry, context), context);
|
||||
}
|
||||
|
||||
template <typename VirtualTranslator>
|
||||
static void XeInsertHeadList(X_LIST_ENTRY* list_head, uint32_t list_head_guest,
|
||||
X_LIST_ENTRY* host_entry, uint32_t entry,
|
||||
VirtualTranslator context) {
|
||||
uint32_t old_list_head_flink = list_head->flink_ptr;
|
||||
host_entry->flink_ptr = old_list_head_flink;
|
||||
host_entry->blink_ptr = list_head_guest;
|
||||
XeHostList(old_list_head_flink, context)->blink_ptr = entry;
|
||||
list_head->flink_ptr = entry;
|
||||
}
|
||||
|
||||
template <typename VirtualTranslator>
|
||||
static void XeInsertHeadList(uint32_t list_head, uint32_t entry,
|
||||
VirtualTranslator context) {
|
||||
XeInsertHeadList(XeHostList(list_head, context), list_head,
|
||||
XeHostList(entry, context), entry, context);
|
||||
}
|
||||
template <typename VirtualTranslator>
|
||||
static void XeInsertHeadList(X_LIST_ENTRY* list_head, uint32_t entry,
|
||||
VirtualTranslator context) {
|
||||
XeInsertHeadList(list_head, XeGuestList(list_head, context),
|
||||
XeHostList(entry, context), entry, context);
|
||||
}
|
||||
template <typename TObject, size_t EntryListOffset>
|
||||
struct X_TYPED_LIST : public X_LIST_ENTRY {
|
||||
public:
|
||||
X_LIST_ENTRY* ObjectListEntry(TObject* obj) {
|
||||
return reinterpret_cast<X_LIST_ENTRY*>(
|
||||
&reinterpret_cast<char*>(obj)[static_cast<ptrdiff_t>(EntryListOffset)]);
|
||||
}
|
||||
TObject* ListEntryObject(X_LIST_ENTRY* entry) {
|
||||
return reinterpret_cast<TObject*>(&reinterpret_cast<char*>(
|
||||
entry)[-static_cast<ptrdiff_t>(EntryListOffset)]);
|
||||
}
|
||||
template <typename VirtualTranslator>
|
||||
void Initialize(VirtualTranslator* translator) {
|
||||
XeInitializeListHead(this, translator);
|
||||
}
|
||||
template <typename VirtualTranslator>
|
||||
void InsertHead(TObject* entry, VirtualTranslator* translator) {
|
||||
XeInsertHeadList(this, ObjectListEntry(entry), translator);
|
||||
}
|
||||
};
|
||||
} // namespace util
|
||||
} // namespace kernel
|
||||
} // namespace xe
|
||||
|
||||
Reference in New Issue
Block a user