Skip to content

Commit

Permalink
tdifw
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Nov 17, 2011
1 parent 89810b7 commit 34bb999
Show file tree
Hide file tree
Showing 98 changed files with 16,679 additions and 0 deletions.
Binary file added Project/tdifw/addon/ndis_hk/bin/ndis_hk.sys
Binary file not shown.
3 changes: 3 additions & 0 deletions Project/tdifw/addon/ndis_hk/install_2k.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
copy bin\ndis_hk.sys %SystemRoot%\system32\drivers > nul
regedit /s install_2k.reg
Binary file added Project/tdifw/addon/ndis_hk/install_2k.reg
Binary file not shown.
3 changes: 3 additions & 0 deletions Project/tdifw/addon/ndis_hk/install_nt4.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
copy bin\ndis_hk.sys %SystemRoot%\system32\drivers > nul
regedit /s install_nt4.reg
11 changes: 11 additions & 0 deletions Project/tdifw/addon/ndis_hk/install_nt4.reg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
REGEDIT4

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ndis_hk]
"Type"=dword:00000001
"Start"=dword:00000002
"ErrorControl"=dword:00000001
"ImagePath"=hex(2):5c,53,79,73,74,65,6d,52,6f,6f,\
74,5c,53,79,73,74,65,6d,33,32,5c,64,72,\
69,76,65,72,73,5c,6e,64,69,73,5f,68,\
6b,2e,73,79,73,00
"Group"="Streams Drivers"
190 changes: 190 additions & 0 deletions Project/tdifw/addon/ndis_hk/src/av.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil -*- (for GNU Emacs)
//
// $Id: av.c,v 1.2 2003/05/13 12:47:39 dev Exp $
/** @addtogroup common
*@{
*/

/**
* @file av.c
* Implementation of functions to work with list of argument-value (av) pairs
*/

#include <ntddk.h>

#include "av.h"
#include "except.h"
#include "memtrack.h"

/** entry contains key-value pair and its type */
struct av_entry {
struct av_entry *next; /**< next entry */
const void *key; /**< key of value to search */
int type; /**< type of pair for search */
void *value; /**< some transparent value */
};

/** number of hash buckets */
#define HASH_SIZE 0x1000
/** get hash by some key */
#define CALC_HASH(key) (((ULONG)(key) >> 5) % HASH_SIZE)

/** hash for av-pairs */
static struct av_entry **g_av_hash;
/** guard spinlock for hash */
KSPIN_LOCK g_av_hash_guard;

NTSTATUS
init_av(void)
{
g_av_hash = (struct av_entry **)malloc_np(sizeof(struct av_entry *) * HASH_SIZE);
if (g_av_hash == NULL) {
KdPrint(("[ndis_hk] init_av: malloc_np!\n"));
return STATUS_INSUFFICIENT_RESOURCES;
}

memset(g_av_hash, 0, sizeof(struct av_entry *) * HASH_SIZE);

KeInitializeSpinLock(&g_av_hash_guard);

return STATUS_SUCCESS;
}

void
free_av(void)
{
ULONG hash;
struct av_entry *av, *av_next;
KIRQL irql;
NTSTATUS status = STATUS_OBJECT_NAME_NOT_FOUND;

KeAcquireSpinLock(&g_av_hash_guard, &irql);

for (hash = 0; hash < HASH_SIZE; hash++) {
for (av = g_av_hash[hash]; av != NULL;) {
av_next = av->next;

if (av->value != NULL && av->type > 0)
free(av->value);
free(av);

av = av_next;
}
}

free(g_av_hash);
g_av_hash = NULL;

KeReleaseSpinLock(&g_av_hash_guard, irql);
}

NTSTATUS
add_av(const void *key, void *value, int type, BOOLEAN no_guard)
{
ULONG hash = CALC_HASH(key);
KIRQL irql;
struct av_entry *av;
NTSTATUS status;

if (!no_guard)
KeAcquireSpinLock(&g_av_hash_guard, &irql);

__try {

for (av = g_av_hash[hash]; av != NULL; av = av->next)
if (av->key == key && av->type == type)
break;

if (av == NULL) {

av = (struct av_entry *)malloc_np(sizeof(*av));
if (av == NULL) {
KdPrint(("[ndis_hk] add_av: malloc_np!\n"));
status = STATUS_INSUFFICIENT_RESOURCES;
__leave;
}

av->next = g_av_hash[hash];
av->key = key;
av->value = value;
av->type = type;

g_av_hash[hash] = av;

} else {
KdPrint(("[ndis_hk] add_av: reuse of key 0x%x type %d\n", key, type));

// change value for av
if (av->value != NULL && av->type > 0)
free(av->value);
av->value = value;
}

status = STATUS_SUCCESS;

} __except((status = GetExceptionCode(), EXCEPTION_EXECUTE_HANDLER)) {
KdPrint(("[ndis_hk] add_av: exception 0x%x!\n", status));
}

if (!no_guard)
KeReleaseSpinLock(&g_av_hash_guard, irql);

return status;
}

void *
get_av(const void *key, int type, KIRQL *irql)
{
ULONG hash = CALC_HASH(key);
struct av_entry *av;

if (irql != NULL)
KeAcquireSpinLock(&g_av_hash_guard, irql);

for (av = g_av_hash[hash]; av != NULL; av = av->next)
if (av->key == key && av->type == type)
return av->value;

if (irql != NULL)
KeReleaseSpinLock(&g_av_hash_guard, *irql);

return NULL;
}

NTSTATUS
del_av(const void *key, int type, BOOLEAN no_guard)
{
ULONG hash = CALC_HASH(key);
struct av_entry *av, *av_next;
KIRQL irql;
NTSTATUS status = STATUS_OBJECT_NAME_NOT_FOUND;

if (!no_guard)
KeAcquireSpinLock(&g_av_hash_guard, &irql);

av_next = NULL;
for (av = g_av_hash[hash]; av != NULL; av = av->next) {
if (av->key == key && av->type == type) {

if (av_next != NULL)
av_next->next = av->next;
else
g_av_hash[hash] = av->next;

if (av->value != NULL && av->type > 0)
free(av->value);
free(av);

status = STATUS_SUCCESS;
break;
}

av_next = av;
}

if (!no_guard)
KeReleaseSpinLock(&g_av_hash_guard, irql);

return status;
}
/*@}*/
74 changes: 74 additions & 0 deletions Project/tdifw/addon/ndis_hk/src/av.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil -*- (for GNU Emacs)
//
// $Id: av.h,v 1.3 2003/05/13 12:47:39 dev Exp $

/**
* @file av.h
* Set of functions to work with list of argument-value (av) pairs
*/

#ifndef _av_h_
#define _av_h_

/**
* Initialize av
*
* @retval STATUS_SUCCESS no error
*/
NTSTATUS init_av(void);

/**
* Deinitialize av
*/
void free_av(void);

/**
* Add av-pair into list
*
* @param key key of value (you can work with value using this key)
* @param value value to be stored
* @param type type of pair (key and type must be unique in av-list)
* @param no_guard if (no_guard) we're already inside g_av_hash_guard spinlock
*/
NTSTATUS add_av(const void *key, void *value, int type, BOOLEAN no_guard);

/**
* Get value by key and type and get ownership over av-list.
* You can give ownership back as soon as possible using:
* KeReleaseSpinLock(&g_av_hash_guard, irql);
*
* @param key key of value
* @param type type of value
* @param irql saved irql for KeReleaseSpinLock (can be NULL means
* we're already inside g_av_hash_guard spinlock)
* @return saved value
* @retval NULL value is not found
*/
void *get_av(const void *key, int type, KIRQL *irql);

/**
* Delete value by key and type
*
* @param key key of value
* @param type type of pair
* @param no_guard if (no_guard) we're already inside g_av_hash_guard spinlock
*
* @retval STATUS_SUCCESS value has been deleted
*/
NTSTATUS del_av(const void *key, int type, BOOLEAN no_guard);

/** guard spinlock for av-list */
extern KSPIN_LOCK g_av_hash_guard;

/* type of values */

enum {
/* NOTE: if (type > 0) value can be automatically freed by free() from memtrack.c */

PROTOCOL_TO_PCHARS = 1, /**< map NDIS_HANDLE NdisProtocolHandle -> struct PROTOCOL_CHARS */
BINDING_TO_ADAPTER, /**< map NDIS_HANDLE NdisBindingHandle -> struct ADAPTER_PROTOCOL */

/* NOTE: if (type < 0) don't free value on delete */
};

#endif
2 changes: 2 additions & 0 deletions Project/tdifw/addon/ndis_hk/src/dirs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DIRS= \
ndis_hk
19 changes: 19 additions & 0 deletions Project/tdifw/addon/ndis_hk/src/except.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef _except_h_
#define _except_h_

#ifndef W2K_ONLY
#pragma warning( disable : 4102 ) /* suppress "unreferenced label" message */

/** The MSDN says nothing about __leave in try-except, but the compiler accepts it.
* This is how it is done in GCC (http://reactos.wox.org/index.php?page=gccseh):
* __leave // Jump to closing brace of try block.
* And so do we, jump to beginning of __except() and __finally.
*/
#define __except(filter) ___finally: if(0) //not supported: never execute this block
#define __try //always execute, nothing needed
#define __finally ___finally: //label for the "finally" block
#define __leave {goto ___finally;} //Jump to that label

#endif

#endif // _except_h_
Loading

0 comments on commit 34bb999

Please sign in to comment.