From ac740aebcfb8025ac20180c2ba4a07ea775f2ea4 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Mon, 3 Dec 2007 23:43:58 +0000 Subject: [PATCH] Implement functions required by some ndis drivers. NdisIMCopySendPerPacketInfo [1] KeQuerySystemTime [1] KeTickCount [1] strncat [1] KeBugCheckEx Submitted by: Marcin Simonides [1] --- sys/compat/ndis/subr_ndis.c | 10 ++++++ sys/compat/ndis/subr_ntoskrnl.c | 58 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/sys/compat/ndis/subr_ndis.c b/sys/compat/ndis/subr_ndis.c index 8d3dfd9c3ec3..e4269b509f79 100644 --- a/sys/compat/ndis/subr_ndis.c +++ b/sys/compat/ndis/subr_ndis.c @@ -282,6 +282,7 @@ static void NdisCopyFromPacketToPacket(ndis_packet *, uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *); static void NdisCopyFromPacketToPacketSafe(ndis_packet *, uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *, uint32_t); +static void NdisIMCopySendPerPacketInfo(ndis_packet *, ndis_packet *); static ndis_status NdisMRegisterDevice(ndis_handle, unicode_string *, unicode_string *, driver_dispatch **, void **, ndis_handle *); @@ -3279,6 +3280,14 @@ NdisCopyFromPacketToPacketSafe(dpkt, doff, reqlen, spkt, soff, cpylen, prio) return; } +static void +NdisIMCopySendPerPacketInfo(dpkt, spkt) + ndis_packet *dpkt; + ndis_packet *spkt; +{ + memcpy(&dpkt->np_ext, &spkt->np_ext, sizeof(ndis_packet_extension)); +} + static ndis_status NdisMRegisterDevice(handle, devname, symname, majorfuncs, devobj, devhandle) ndis_handle handle; @@ -3356,6 +3365,7 @@ dummy() image_patch_table ndis_functbl[] = { IMPORT_SFUNC(NdisCopyFromPacketToPacket, 6), IMPORT_SFUNC(NdisCopyFromPacketToPacketSafe, 7), + IMPORT_SFUNC(NdisIMCopySendPerPacketInfo, 2), IMPORT_SFUNC(NdisScheduleWorkItem, 1), IMPORT_SFUNC(NdisMIndicateStatusComplete, 1), IMPORT_SFUNC(NdisMIndicateStatus, 4), diff --git a/sys/compat/ndis/subr_ntoskrnl.c b/sys/compat/ndis/subr_ntoskrnl.c index 0be598d4f984..367d9f6593c8 100644 --- a/sys/compat/ndis/subr_ntoskrnl.c +++ b/sys/compat/ndis/subr_ntoskrnl.c @@ -218,6 +218,8 @@ static int atoi (const char *); static long atol (const char *); static int rand(void); static void srand(unsigned int); +static void KeQuerySystemTime(uint64_t *); +static uint32_t KeTickCount(void); static uint8_t IoIsWdmVersionAvailable(uint8_t, uint8_t); static void ntoskrnl_thrfunc(void *); static ndis_status PsCreateSystemThread(ndis_handle *, @@ -240,11 +242,13 @@ static void *ntoskrnl_memset(void *, int, size_t); static void *ntoskrnl_memmove(void *, void *, size_t); static void *ntoskrnl_memchr(void *, unsigned char, size_t); static char *ntoskrnl_strstr(char *, char *); +static char *ntoskrnl_strncat(char *, char *, size_t); static int ntoskrnl_toupper(int); static int ntoskrnl_tolower(int); static funcptr ntoskrnl_findwrap(funcptr); static uint32_t DbgPrint(char *, ...); static void DbgBreakPoint(void); +static void KeBugCheckEx(uint32_t, u_long, u_long, u_long, u_long); static void dummy(void); static struct mtx ntoskrnl_dispatchlock; @@ -475,6 +479,29 @@ ntoskrnl_strstr(s, find) return ((char *)s); } +/* Taken from libc */ +static char * +ntoskrnl_strncat(dst, src, n) + char *dst; + char *src; + size_t n; +{ + if (n != 0) { + char *d = dst; + const char *s = src; + + while (*d != 0) + d++; + do { + if ((*d = *s++) == 0) + break; + d++; + } while (--n != 0); + *d = 0; + } + return (dst); +} + static int ntoskrnl_toupper(c) int c; @@ -1590,6 +1617,22 @@ ntoskrnl_time(tval) return; } +static void +KeQuerySystemTime(current_time) + uint64_t *current_time; +{ + ntoskrnl_time(current_time); +} + +static uint32_t +KeTickCount(void) +{ + struct timeval tv; + getmicrouptime(&tv); + return tvtohz(&tv); +} + + /* * KeWaitForSingleObject() is a tricky beast, because it can be used * with several different object types: semaphores, timers, events, @@ -3593,6 +3636,17 @@ DbgBreakPoint(void) #endif } +static void +KeBugCheckEx(code, param1, param2, param3, param4) + uint32_t code; + u_long param1; + u_long param2; + u_long param3; + u_long param4; +{ + panic("KeBugCheckEx: STOP 0x%X", code); +} + static void ntoskrnl_timercall(arg) void *arg; @@ -4218,6 +4272,7 @@ image_patch_table ntoskrnl_functbl[] = { IMPORT_CFUNC_MAP(_vsnprintf, vsnprintf, 0), IMPORT_CFUNC(DbgPrint, 0), IMPORT_SFUNC(DbgBreakPoint, 0), + IMPORT_SFUNC(KeBugCheckEx, 5), IMPORT_CFUNC(strncmp, 0), IMPORT_CFUNC(strcmp, 0), IMPORT_CFUNC_MAP(stricmp, strcasecmp, 0), @@ -4227,6 +4282,7 @@ image_patch_table ntoskrnl_functbl[] = { IMPORT_CFUNC_MAP(toupper, ntoskrnl_toupper, 0), IMPORT_CFUNC_MAP(tolower, ntoskrnl_tolower, 0), IMPORT_CFUNC_MAP(strstr, ntoskrnl_strstr, 0), + IMPORT_CFUNC_MAP(strncat, ntoskrnl_strncat, 0), IMPORT_CFUNC_MAP(strchr, index, 0), IMPORT_CFUNC_MAP(strrchr, rindex, 0), IMPORT_CFUNC(memcpy, 0), @@ -4368,6 +4424,8 @@ image_patch_table ntoskrnl_functbl[] = { IMPORT_SFUNC(IoWMIRegistrationControl, 2), IMPORT_SFUNC(WmiQueryTraceInformation, 5), IMPORT_CFUNC(WmiTraceMessage, 0), + IMPORT_SFUNC(KeQuerySystemTime, 1), + IMPORT_CFUNC(KeTickCount, 0), /* * This last entry is a catch-all for any function we haven't