Deleted Added
full compact
subr_ntoskrnl.c (123474) subr_ntoskrnl.c (123504)
1/*
2 * Copyright (c) 2003
3 * Bill Paul <wpaul@windriver.com>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/cdefs.h>
1/*
2 * Copyright (c) 2003
3 * Bill Paul <wpaul@windriver.com>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/sys/compat/ndis/subr_ntoskrnl.c 123474 2003-12-11 22:34:37Z wpaul $");
34__FBSDID("$FreeBSD: head/sys/compat/ndis/subr_ntoskrnl.c 123504 2003-12-12 22:35:13Z wpaul $");
35
36#include <sys/param.h>
37#include <sys/types.h>
38#include <sys/errno.h>
39#include <sys/systm.h>
40#include <sys/malloc.h>
41#include <sys/lock.h>
42#include <sys/mutex.h>

--- 49 unchanged lines hidden (view full) ---

92 uint32_t, size_t, uint32_t, uint16_t);
93__stdcall static void ntoskrnl_delete_lookaside(paged_lookaside_list *);
94__stdcall static void ntoskrnl_init_nplookaside(npaged_lookaside_list *,
95 lookaside_alloc_func *, lookaside_free_func *,
96 uint32_t, size_t, uint32_t, uint16_t);
97__stdcall static void ntoskrnl_delete_nplookaside(npaged_lookaside_list *);
98static slist_entry *ntoskrnl_push_slist(slist_entry *, slist_entry *);
99static slist_entry *ntoskrnl_pop_slist(slist_entry *);
35
36#include <sys/param.h>
37#include <sys/types.h>
38#include <sys/errno.h>
39#include <sys/systm.h>
40#include <sys/malloc.h>
41#include <sys/lock.h>
42#include <sys/mutex.h>

--- 49 unchanged lines hidden (view full) ---

92 uint32_t, size_t, uint32_t, uint16_t);
93__stdcall static void ntoskrnl_delete_lookaside(paged_lookaside_list *);
94__stdcall static void ntoskrnl_init_nplookaside(npaged_lookaside_list *,
95 lookaside_alloc_func *, lookaside_free_func *,
96 uint32_t, size_t, uint32_t, uint16_t);
97__stdcall static void ntoskrnl_delete_nplookaside(npaged_lookaside_list *);
98static slist_entry *ntoskrnl_push_slist(slist_entry *, slist_entry *);
99static slist_entry *ntoskrnl_pop_slist(slist_entry *);
100static slist_entry *ntoskrnl_push_slist_ex(slist_entry *,
101 slist_entry *, kspin_lock *);
102static slist_entry *ntoskrnl_pop_slist_ex(slist_entry *, kspin_lock *);
100__stdcall static void dummy(void);
101
102static struct mtx ntoskrnl_interlock;
103static int ntoskrnl_inits = 0;
104
105int
106ntoskrnl_libinit()
107{

--- 239 unchanged lines hidden (view full) ---

347 paged_lookaside_list *lookaside;
348 lookaside_alloc_func *allocfunc;
349 lookaside_free_func *freefunc;
350 uint32_t flags;
351 size_t size;
352 uint32_t tag;
353 uint16_t depth;
354{
103__stdcall static void dummy(void);
104
105static struct mtx ntoskrnl_interlock;
106static int ntoskrnl_inits = 0;
107
108int
109ntoskrnl_libinit()
110{

--- 239 unchanged lines hidden (view full) ---

350 paged_lookaside_list *lookaside;
351 lookaside_alloc_func *allocfunc;
352 lookaside_free_func *freefunc;
353 uint32_t flags;
354 size_t size;
355 uint32_t tag;
356 uint16_t depth;
357{
358 struct mtx *mtx;
359
355 lookaside->nll_l.gl_size = size;
356 lookaside->nll_l.gl_tag = tag;
357 if (allocfunc == NULL)
358 lookaside->nll_l.gl_allocfunc = ntoskrnl_allocfunc;
359 else
360 lookaside->nll_l.gl_allocfunc = allocfunc;
361
362 if (freefunc == NULL)
363 lookaside->nll_l.gl_freefunc = ntoskrnl_freefunc;
364 else
365 lookaside->nll_l.gl_freefunc = freefunc;
366
360 lookaside->nll_l.gl_size = size;
361 lookaside->nll_l.gl_tag = tag;
362 if (allocfunc == NULL)
363 lookaside->nll_l.gl_allocfunc = ntoskrnl_allocfunc;
364 else
365 lookaside->nll_l.gl_allocfunc = allocfunc;
366
367 if (freefunc == NULL)
368 lookaside->nll_l.gl_freefunc = ntoskrnl_freefunc;
369 else
370 lookaside->nll_l.gl_freefunc = freefunc;
371
372 mtx = malloc(sizeof(struct mtx), M_DEVBUF, M_NOWAIT|M_ZERO);
373 if (mtx == NULL)
374 return;
375 mtx_init(mtx, "ndisnplook", "ndis lookaside lock",
376 MTX_DEF | MTX_RECURSE | MTX_DUPOK);
377 lookaside->nll_obsoletelock = (kspin_lock)mtx;
378
367 return;
368}
369
370__stdcall static void
371ntoskrnl_delete_lookaside(lookaside)
372 paged_lookaside_list *lookaside;
373{
379 return;
380}
381
382__stdcall static void
383ntoskrnl_delete_lookaside(lookaside)
384 paged_lookaside_list *lookaside;
385{
386 mtx_destroy((struct mtx *)lookaside->nll_obsoletelock);
387 free((struct mtx *)lookaside->nll_obsoletelock, M_DEVBUF);
374 return;
375}
376
377__stdcall static void
378ntoskrnl_init_nplookaside(lookaside, allocfunc, freefunc,
379 flags, size, tag, depth)
380 npaged_lookaside_list *lookaside;
381 lookaside_alloc_func *allocfunc;
382 lookaside_free_func *freefunc;
383 uint32_t flags;
384 size_t size;
385 uint32_t tag;
386 uint16_t depth;
387{
388 return;
389}
390
391__stdcall static void
392ntoskrnl_init_nplookaside(lookaside, allocfunc, freefunc,
393 flags, size, tag, depth)
394 npaged_lookaside_list *lookaside;
395 lookaside_alloc_func *allocfunc;
396 lookaside_free_func *freefunc;
397 uint32_t flags;
398 size_t size;
399 uint32_t tag;
400 uint16_t depth;
401{
402 struct mtx *mtx;
403
388 lookaside->nll_l.gl_size = size;
389 lookaside->nll_l.gl_tag = tag;
390 if (allocfunc == NULL)
391 lookaside->nll_l.gl_allocfunc = ntoskrnl_allocfunc;
392 else
393 lookaside->nll_l.gl_allocfunc = allocfunc;
394
395 if (freefunc == NULL)
396 lookaside->nll_l.gl_freefunc = ntoskrnl_freefunc;
397 else
398 lookaside->nll_l.gl_freefunc = freefunc;
399
404 lookaside->nll_l.gl_size = size;
405 lookaside->nll_l.gl_tag = tag;
406 if (allocfunc == NULL)
407 lookaside->nll_l.gl_allocfunc = ntoskrnl_allocfunc;
408 else
409 lookaside->nll_l.gl_allocfunc = allocfunc;
410
411 if (freefunc == NULL)
412 lookaside->nll_l.gl_freefunc = ntoskrnl_freefunc;
413 else
414 lookaside->nll_l.gl_freefunc = freefunc;
415
416 mtx = malloc(sizeof(struct mtx), M_DEVBUF, M_NOWAIT|M_ZERO);
417 if (mtx == NULL)
418 return;
419 mtx_init(mtx, "ndisnplook", "ndis lookaside lock",
420 MTX_DEF | MTX_RECURSE | MTX_DUPOK);
421 lookaside->nll_obsoletelock = (kspin_lock)mtx;
422
400 return;
401}
402
403__stdcall static void
404ntoskrnl_delete_nplookaside(lookaside)
405 npaged_lookaside_list *lookaside;
406{
423 return;
424}
425
426__stdcall static void
427ntoskrnl_delete_nplookaside(lookaside)
428 npaged_lookaside_list *lookaside;
429{
430 mtx_destroy((struct mtx *)lookaside->nll_obsoletelock);
431 free((struct mtx *)lookaside->nll_obsoletelock, M_DEVBUF);
407 return;
408}
409
410/*
411 * Note: the interlocked slist push and pop routines are
412 * declared to be _fastcall in Windows, which means they
413 * use the _cdecl calling convention here.
414 */

--- 19 unchanged lines hidden (view full) ---

434 mtx_lock(&ntoskrnl_interlock);
435 first = head->sl_next;
436 if (first != NULL)
437 head->sl_next = first->sl_next;
438 mtx_unlock(&ntoskrnl_interlock);
439 return(first);
440}
441
432 return;
433}
434
435/*
436 * Note: the interlocked slist push and pop routines are
437 * declared to be _fastcall in Windows, which means they
438 * use the _cdecl calling convention here.
439 */

--- 19 unchanged lines hidden (view full) ---

459 mtx_lock(&ntoskrnl_interlock);
460 first = head->sl_next;
461 if (first != NULL)
462 head->sl_next = first->sl_next;
463 mtx_unlock(&ntoskrnl_interlock);
464 return(first);
465}
466
467__stdcall static slist_entry *
468ntoskrnl_push_slist_ex(head, entry, lock)
469 slist_entry *head;
470 slist_entry *entry;
471 kspin_lock *lock;
472{
473 slist_entry *oldhead;
474 return(NULL);
475 mtx_lock((struct mtx *)*lock);
476 oldhead = head->sl_next;
477 entry->sl_next = head->sl_next;
478 head->sl_next = entry;
479 mtx_unlock((struct mtx *)*lock);
480 return(oldhead);
481}
482
483__stdcall static slist_entry *
484ntoskrnl_pop_slist_ex(head, lock)
485 slist_entry *head;
486 kspin_lock *lock;
487{
488 slist_entry *first;
489
490 return(NULL);
491 mtx_lock((struct mtx *)*lock);
492 first = head->sl_next;
493 if (first != NULL)
494 head->sl_next = first->sl_next;
495 mtx_unlock((struct mtx *)*lock);
496 return(first);
497}
498
442__stdcall static void
443dummy()
444{
445 printf ("ntoskrnl dummy called...\n");
446 return;
447}
448
449
450image_patch_table ntoskrnl_functbl[] = {
451 { "RtlEqualUnicodeString", (FUNC)ntoskrnl_unicode_equal },
452 { "sprintf", (FUNC)sprintf },
453 { "DbgPrint", (FUNC)printf },
454 { "strncmp", (FUNC)strncmp },
455 { "strcmp", (FUNC)strcmp },
456 { "strncpy", (FUNC)strncpy },
457 { "strcpy", (FUNC)strcpy },
499__stdcall static void
500dummy()
501{
502 printf ("ntoskrnl dummy called...\n");
503 return;
504}
505
506
507image_patch_table ntoskrnl_functbl[] = {
508 { "RtlEqualUnicodeString", (FUNC)ntoskrnl_unicode_equal },
509 { "sprintf", (FUNC)sprintf },
510 { "DbgPrint", (FUNC)printf },
511 { "strncmp", (FUNC)strncmp },
512 { "strcmp", (FUNC)strcmp },
513 { "strncpy", (FUNC)strncpy },
514 { "strcpy", (FUNC)strcpy },
515 { "strlen", (FUNC)strlen },
516 { "memcpy", (FUNC)memcpy },
517 { "memset", (FUNC)memset },
458 { "IofCallDriver", (FUNC)ntoskrnl_iofcalldriver },
459 { "IoBuildSynchronousFsdRequest", (FUNC)ntoskrnl_iobuildsynchfsdreq },
460 { "KeWaitForSingleObject", (FUNC)ntoskrnl_waitforobj },
461 { "KeInitializeEvent", (FUNC)ntoskrnl_initevent },
462 { "_allmul", (FUNC)_allmul },
463 { "_alldiv", (FUNC)_alldiv },
464 { "_allrem", (FUNC)_allrem },
465 { "_allshr", (FUNC)_allshr },

--- 10 unchanged lines hidden (view full) ---

476 { "READ_REGISTER_UCHAR", (FUNC)ntoskrnl_readreg_uchar },
477 { "WRITE_REGISTER_UCHAR", (FUNC)ntoskrnl_writereg_uchar },
478 { "ExInitializePagedLookasideList", (FUNC)ntoskrnl_init_lookaside },
479 { "ExDeletePagedLookasideList", (FUNC)ntoskrnl_delete_lookaside },
480 { "ExInitializeNPagedLookasideList", (FUNC)ntoskrnl_init_nplookaside },
481 { "ExDeleteNPagedLookasideList", (FUNC)ntoskrnl_delete_nplookaside },
482 { "InterlockedPopEntrySList", (FUNC)ntoskrnl_pop_slist },
483 { "InterlockedPushEntrySList", (FUNC)ntoskrnl_push_slist },
518 { "IofCallDriver", (FUNC)ntoskrnl_iofcalldriver },
519 { "IoBuildSynchronousFsdRequest", (FUNC)ntoskrnl_iobuildsynchfsdreq },
520 { "KeWaitForSingleObject", (FUNC)ntoskrnl_waitforobj },
521 { "KeInitializeEvent", (FUNC)ntoskrnl_initevent },
522 { "_allmul", (FUNC)_allmul },
523 { "_alldiv", (FUNC)_alldiv },
524 { "_allrem", (FUNC)_allrem },
525 { "_allshr", (FUNC)_allshr },

--- 10 unchanged lines hidden (view full) ---

536 { "READ_REGISTER_UCHAR", (FUNC)ntoskrnl_readreg_uchar },
537 { "WRITE_REGISTER_UCHAR", (FUNC)ntoskrnl_writereg_uchar },
538 { "ExInitializePagedLookasideList", (FUNC)ntoskrnl_init_lookaside },
539 { "ExDeletePagedLookasideList", (FUNC)ntoskrnl_delete_lookaside },
540 { "ExInitializeNPagedLookasideList", (FUNC)ntoskrnl_init_nplookaside },
541 { "ExDeleteNPagedLookasideList", (FUNC)ntoskrnl_delete_nplookaside },
542 { "InterlockedPopEntrySList", (FUNC)ntoskrnl_pop_slist },
543 { "InterlockedPushEntrySList", (FUNC)ntoskrnl_push_slist },
544 { "ExInterlockedPopEntrySList", (FUNC)ntoskrnl_pop_slist_ex },
545 { "ExInterlockedPushEntrySList",(FUNC)ntoskrnl_push_slist_ex },
484
485 /*
486 * This last entry is a catch-all for any function we haven't
487 * implemented yet. The PE import list patching routine will
488 * use it for any function that doesn't have an explicit match
489 * in this table.
490 */
491
492 { NULL, (FUNC)dummy },
493
494 /* End of list. */
495
496 { NULL, NULL },
497};
546
547 /*
548 * This last entry is a catch-all for any function we haven't
549 * implemented yet. The PE import list patching routine will
550 * use it for any function that doesn't have an explicit match
551 * in this table.
552 */
553
554 { NULL, (FUNC)dummy },
555
556 /* End of list. */
557
558 { NULL, NULL },
559};