summaryrefslogtreecommitdiffstats
path: root/sys/compat/ndis/subr_ntoskrnl.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/compat/ndis/subr_ntoskrnl.c')
-rw-r--r--sys/compat/ndis/subr_ntoskrnl.c131
1 files changed, 125 insertions, 6 deletions
diff --git a/sys/compat/ndis/subr_ntoskrnl.c b/sys/compat/ndis/subr_ntoskrnl.c
index 80b1d98..c575eb9 100644
--- a/sys/compat/ndis/subr_ntoskrnl.c
+++ b/sys/compat/ndis/subr_ntoskrnl.c
@@ -128,6 +128,7 @@ static kspin_lock ntoskrnl_intlock;
static uint8_t RtlEqualUnicodeString(unicode_string *,
unicode_string *, uint8_t);
+static void RtlCopyString(ansi_string *, const ansi_string *);
static void RtlCopyUnicodeString(unicode_string *,
unicode_string *);
static irp *IoBuildSynchronousFsdRequest(uint32_t, device_object *,
@@ -180,7 +181,9 @@ static uint64_t _aullrem(uint64_t, uint64_t);
static uint64_t _aullshr(uint64_t, uint8_t);
static uint64_t _aullshl(uint64_t, uint8_t);
static slist_entry *ntoskrnl_pushsl(slist_header *, slist_entry *);
+static void InitializeSListHead(slist_header *);
static slist_entry *ntoskrnl_popsl(slist_header *);
+static void ExFreePoolWithTag(void *, uint32_t);
static void ExInitializePagedLookasideList(paged_lookaside_list *,
lookaside_alloc_func *, lookaside_free_func *,
uint32_t, size_t, uint32_t, uint16_t);
@@ -210,6 +213,10 @@ static void *MmMapLockedPagesSpecifyCache(mdl *,
static void MmUnmapLockedPages(void *, mdl *);
static device_t ntoskrnl_finddev(device_t, uint64_t, struct resource **);
static void RtlZeroMemory(void *, size_t);
+static void RtlSecureZeroMemory(void *, size_t);
+static void RtlFillMemory(void *, size_t, uint8_t);
+static void RtlMoveMemory(void *, const void *, size_t);
+static ndis_status RtlCharToInteger(const char *, uint32_t, uint32_t *);
static void RtlCopyMemory(void *, const void *, size_t);
static size_t RtlCompareMemory(const void *, const void *, size_t);
static ndis_status RtlUnicodeStringToInteger(unicode_string *,
@@ -538,6 +545,20 @@ RtlEqualUnicodeString(unicode_string *str1, unicode_string *str2,
}
static void
+RtlCopyString(dst, src)
+ ansi_string *dst;
+ const ansi_string *src;
+{
+ if (src != NULL && src->as_buf != NULL && dst->as_buf != NULL) {
+ dst->as_len = min(src->as_len, dst->as_maxlen);
+ memcpy(dst->as_buf, src->as_buf, dst->as_len);
+ if (dst->as_len < dst->as_maxlen)
+ dst->as_buf[dst->as_len] = 0;
+ } else
+ dst->as_len = 0;
+}
+
+static void
RtlCopyUnicodeString(dest, src)
unicode_string *dest;
unicode_string *src;
@@ -650,6 +671,14 @@ ExAllocatePoolWithTag(pooltype, len, tag)
return (buf);
}
+static void
+ExFreePoolWithTag(buf, tag)
+ void *buf;
+ uint32_t tag;
+{
+ ExFreePool(buf);
+}
+
void
ExFreePool(buf)
void *buf;
@@ -2056,6 +2085,13 @@ ntoskrnl_pushsl(head, entry)
return (oldhead);
}
+static void
+InitializeSListHead(head)
+ slist_header *head;
+{
+ memset(head, 0, sizeof(*head));
+}
+
static slist_entry *
ntoskrnl_popsl(head)
slist_header *head;
@@ -2725,6 +2761,59 @@ ntoskrnl_workitem_thread(arg)
return; /* notreached */
}
+static ndis_status
+RtlCharToInteger(src, base, val)
+ const char *src;
+ uint32_t base;
+ uint32_t *val;
+{
+ int negative = 0;
+ uint32_t res;
+
+ if (!src || !val)
+ return (STATUS_ACCESS_VIOLATION);
+ while (*src != '\0' && *src <= ' ')
+ src++;
+ if (*src == '+')
+ src++;
+ else if (*src == '-') {
+ src++;
+ negative = 1;
+ }
+ if (base == 0) {
+ base = 10;
+ if (*src == '0') {
+ src++;
+ if (*src == 'b') {
+ base = 2;
+ src++;
+ } else if (*src == 'o') {
+ base = 8;
+ src++;
+ } else if (*src == 'x') {
+ base = 16;
+ src++;
+ }
+ }
+ } else if (!(base == 2 || base == 8 || base == 10 || base == 16))
+ return (STATUS_INVALID_PARAMETER);
+
+ for (res = 0; *src; src++) {
+ int v;
+ if (isdigit(*src))
+ v = *src - '0';
+ else if (isxdigit(*src))
+ v = tolower(*src) - 'a' + 10;
+ else
+ v = base;
+ if (v >= base)
+ return (STATUS_INVALID_PARAMETER);
+ res = res * base + v;
+ }
+ *val = negative ? -res : res;
+ return (STATUS_SUCCESS);
+}
+
static void
ntoskrnl_destroy_workitem_threads(void)
{
@@ -2905,6 +2994,32 @@ RtlZeroMemory(dst, len)
}
static void
+RtlSecureZeroMemory(dst, len)
+ void *dst;
+ size_t len;
+{
+ memset(dst, 0, len);
+}
+
+static void
+RtlFillMemory(dst, len, c)
+ void *dst;
+ size_t len;
+ uint8_t c;
+{
+ memset(dst, c, len);
+}
+
+static void
+RtlMoveMemory(dst, src, len)
+ void *dst;
+ const void *src;
+ size_t len;
+{
+ memmove(dst, src, len);
+}
+
+static void
RtlCopyMemory(dst, src, len)
void *dst;
const void *src;
@@ -2919,17 +3034,14 @@ RtlCompareMemory(s1, s2, len)
const void *s2;
size_t len;
{
- size_t i, total = 0;
+ size_t i;
uint8_t *m1, *m2;
m1 = __DECONST(char *, s1);
m2 = __DECONST(char *, s2);
- for (i = 0; i < len; i++) {
- if (m1[i] == m2[i])
- total++;
- }
- return (total);
+ for (i = 0; i < len && m1[i] == m2[i]; i++);
+ return (i);
}
void
@@ -4124,7 +4236,12 @@ dummy()
image_patch_table ntoskrnl_functbl[] = {
IMPORT_SFUNC(RtlZeroMemory, 2),
+ IMPORT_SFUNC(RtlSecureZeroMemory, 2),
+ IMPORT_SFUNC(RtlFillMemory, 3),
+ IMPORT_SFUNC(RtlMoveMemory, 3),
+ IMPORT_SFUNC(RtlCharToInteger, 3),
IMPORT_SFUNC(RtlCopyMemory, 3),
+ IMPORT_SFUNC(RtlCopyString, 2),
IMPORT_SFUNC(RtlCompareMemory, 3),
IMPORT_SFUNC(RtlEqualUnicodeString, 3),
IMPORT_SFUNC(RtlCopyUnicodeString, 2),
@@ -4211,6 +4328,7 @@ image_patch_table ntoskrnl_functbl[] = {
IMPORT_SFUNC(ExInitializeNPagedLookasideList, 7),
IMPORT_SFUNC(ExDeleteNPagedLookasideList, 1),
IMPORT_FFUNC(InterlockedPopEntrySList, 1),
+ IMPORT_FFUNC(InitializeSListHead, 1),
IMPORT_FFUNC(InterlockedPushEntrySList, 2),
IMPORT_SFUNC(ExQueryDepthSList, 1),
IMPORT_FFUNC_MAP(ExpInterlockedPopEntrySList,
@@ -4220,6 +4338,7 @@ image_patch_table ntoskrnl_functbl[] = {
IMPORT_FFUNC(ExInterlockedPopEntrySList, 2),
IMPORT_FFUNC(ExInterlockedPushEntrySList, 3),
IMPORT_SFUNC(ExAllocatePoolWithTag, 3),
+ IMPORT_SFUNC(ExFreePoolWithTag, 2),
IMPORT_SFUNC(ExFreePool, 1),
#ifdef __i386__
IMPORT_FFUNC(KefAcquireSpinLockAtDpcLevel, 1),
OpenPOWER on IntegriCloud