ReactOS 0.4.16-dev-319-g6cf4263
misc.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS NDIS library
4 * FILE: ndis/misc.c
5 */
6
7#include "ndissys.h"
8
9extern LONG CancelId;
10
11/*
12 * @implemented
13 */
14#undef NdisInterlockedAddUlong
15VOID
21{
23}
24
25/*
26 * @implemented
27 */
28VOID
34{
35 /* This needs to be verified. The documentation
36 * seems to be missing but it is exported by
37 * NDIS 5.1 so I'm implementing it like the other
38 * interlocked routines
39 */
40
42}
43
44/*
45 * @implemented
46 */
47LONG
50 IN PNDIS_ANSI_STRING String1,
53{
54 /* This one needs to be verified also. See the
55 * comment in NdisInterlockedAddLargeInteger
56 */
57
59}
60
61/*
62 * @implemented
63 */
64LONG
67 IN PNDIS_STRING String1,
70{
71 /* This one needs to be verified also. See the
72 * comment in NdisInterlockedAddLargeInteger
73 */
74
76}
77
78/*
79 * @implemented
80 */
81#undef NdisInterlockedInsertHeadList
85 IN PLIST_ENTRY ListHead,
86 IN PLIST_ENTRY ListEntry,
88{
89 return ExInterlockedInsertHeadList ( ListHead, ListEntry, &SpinLock->SpinLock );
90}
91
92/*
93 * @implemented
94 */
95#undef NdisInterlockedInsertTailList
99 IN PLIST_ENTRY ListHead,
100 IN PLIST_ENTRY ListEntry,
102{
103 return ExInterlockedInsertTailList ( ListHead, ListEntry, &SpinLock->SpinLock );
104}
105
106
107/*
108 * @implemented
109 */
110#undef NdisInterlockedRemoveHeadList
112EXPORT
114 IN PLIST_ENTRY ListHead,
116{
117 return ExInterlockedRemoveHeadList ( ListHead, &SpinLock->SpinLock );
118}
119
121{
127
131{
133}
134
138{
139 return (NDIS_HANDLE)obj;
140}
141
142static const WCHAR NDIS_FILE_FOLDER[] = L"\\SystemRoot\\System32\\Drivers\\";
143
144/*
145 * @implemented
146 */
147VOID
148EXPORT
153{
155
156 NDIS_DbgPrint(MAX_TRACE, ("called: FileHandle 0x%x\n", FileHandle));
157
158 if (HandleObject->Mapped)
159 {
160 /* If a file already mapped we will return an error code */
161 NDIS_DbgPrint(MIN_TRACE, ("File already mapped\n"));
163 return;
164 }
165
166 HandleObject->Mapped = TRUE;
167 *MappedBuffer = HandleObject->MapBuffer;
168
169 /* Set returned status */
171}
172
173/*
174 * @implemented
175 */
176VOID
177EXPORT
180{
182
183 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
184
185 HandleObject->Mapped = FALSE;
186}
187
188/*
189 * @implemented
190 */
191VOID
192EXPORT
195{
196 PNDIS_HANDLE_OBJECT FileHandleObject;
197
199
200 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
201
202 ASSERT ( FileHandle );
203
204 FileHandleObject = NDIS_HANDLE_TO_POBJECT(FileHandle);
205
206 ASSERT ( FileHandleObject->FileHandle );
207
208 if ( FileHandleObject->Mapped )
210
211 ZwClose ( FileHandleObject->FileHandle );
212
213 memset ( FileHandleObject, 0, sizeof(NDIS_HANDLE_OBJECT) );
214
215 ExFreePool ( FileHandleObject );
216}
217
218
219/*
220 * @implemented
221 */
222VOID
223EXPORT
230{
231 NDIS_STRING FullFileName;
233 PNDIS_HANDLE_OBJECT FileHandleObject = NULL;
235
237
238 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
239
240 ASSERT ( Status && FileName );
241
243 FullFileName.Buffer = NULL;
244
245 FullFileName.Length = sizeof(NDIS_FILE_FOLDER) - sizeof(UNICODE_NULL);
246 FullFileName.MaximumLength = FileName->MaximumLength + FullFileName.Length;
247 FullFileName.Buffer = ExAllocatePool ( NonPagedPool, FullFileName.MaximumLength );
248
249 if ( !FullFileName.Buffer )
250 {
251 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
253 goto cleanup;
254 }
255
256 FileHandleObject = ExAllocatePool ( NonPagedPool, sizeof(NDIS_HANDLE_OBJECT) );
257 if ( !FileHandleObject )
258 {
259 NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
261 goto cleanup;
262 }
263 memset ( FileHandleObject, 0, sizeof(NDIS_HANDLE_OBJECT) );
264
265 memmove ( FullFileName.Buffer, NDIS_FILE_FOLDER, FullFileName.Length );
266 *Status = RtlAppendUnicodeStringToString ( &FullFileName, FileName );
267 if ( !NT_SUCCESS(*Status) )
268 {
269 NDIS_DbgPrint(MIN_TRACE, ("RtlAppendUnicodeStringToString failed (%x)\n", *Status));
271 goto cleanup;
272 }
273
275 &FullFileName,
277 NULL,
278 NULL );
279
280 *Status = ZwCreateFile (
281 &FileHandleObject->FileHandle,
285 NULL, // PLARGE_INTEGER AllocationSize
286 0, // ULONG FileAttributes
287 FILE_SHARE_READ, // ULONG ShareAccess
288 FILE_OPEN, // ULONG CreateDisposition
289 FILE_SYNCHRONOUS_IO_NONALERT, // ULONG CreateOptions
290 0, // PVOID EaBuffer
291 0 ); // ULONG EaLength
292
293 if ( !NT_SUCCESS(*Status) )
294 {
295 NDIS_DbgPrint(MIN_TRACE, ("ZwCreateFile failed (%x) Name %wZ\n", *Status, FileName));
297 }
298
299cleanup:
300 if ( FullFileName.Buffer != NULL )
301 {
302 ExFreePool ( FullFileName.Buffer );
303 FullFileName.Buffer = NULL;
304 }
305 if ( !NT_SUCCESS(*Status) )
306 {
307 if( FileHandleObject ) {
308 ExFreePool ( FileHandleObject );
309 FileHandleObject = NULL;
310 }
311 *FileHandle = NULL;
312 }
313 else
314 *FileHandle = NDIS_POBJECT_TO_HANDLE(FileHandleObject);
315
316 return;
317}
318
319/*
320 * @implemented
321 */
322CCHAR
323EXPORT
325 VOID)
326{
327 return KeNumberProcessors;
328}
329
330
331/*
332 * @implemented
333 */
334VOID
335EXPORT
337 OUT PULONG pIdleCount,
340/*
341 * FUNCTION:
342 * ARGUMENTS:
343 * NOTES:
344 * NDIS 5.0
345 */
346{
347 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
348
350}
351
352
353/*
354 * @implemented
355 */
356VOID
357EXPORT
359{
361 LARGE_INTEGER TickCount;
362
363 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
364
365 /* Get the increment and current tick count */
367 KeQueryTickCount(&TickCount);
368
369 /* Convert to milliseconds and return */
370 TickCount.QuadPart *= Increment;
371 TickCount.QuadPart /= (10 * 1000);
372 *pSystemUpTime = TickCount.LowPart;
373}
374
375/*
376 * @implemented
377 */
378#undef NdisInterlockedDecrement
379LONG
380EXPORT
383/*
384 * FUNCTION:
385 * ARGUMENTS:
386 * NOTES:
387 * NDIS 5.0
388 */
389{
390 return InterlockedDecrement ( Addend );
391}
392
393
394/*
395 * @implemented
396 */
397#undef NdisInterlockedIncrement
398LONG
399EXPORT
402/*
403 * FUNCTION:
404 * ARGUMENTS:
405 * NOTES:
406 * NDIS 5.0
407 */
408{
409 return InterlockedIncrement ( Addend );
410}
411
412
413/*
414 * @implemented
415 */
416#undef NdisInterlockedPopEntrySList
418EXPORT
420 IN PSLIST_HEADER ListHead,
422/*
423 * FUNCTION:
424 * ARGUMENTS:
425 * NOTES:
426 * NDIS 5.0
427 */
428{
430}
431
432
433/*
434 * @implemented
435 */
436#undef NdisInterlockedPushEntrySList
438EXPORT
440 IN PSLIST_HEADER ListHead,
441 IN PSINGLE_LIST_ENTRY ListEntry,
443/*
444 * FUNCTION:
445 * ARGUMENTS:
446 * NOTES:
447 * NDIS 5.0
448 */
449{
450 return (PSINGLE_LIST_ENTRY)ExInterlockedPushEntrySList ( ListHead, (PSLIST_ENTRY)ListEntry, Lock );
451}
452
453
454VOID
455NTAPI
457{
458 PNDIS_WORK_ITEM pNdisItem = (PNDIS_WORK_ITEM)pContext;
459
460 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
461
462 pNdisItem->Routine(pNdisItem, pNdisItem->Context);
463}
464
466EXPORT
468 IN PNDIS_WORK_ITEM pWorkItem)
469{
470 PWORK_QUEUE_ITEM pntWorkItem = (PWORK_QUEUE_ITEM)pWorkItem->WrapperReserved;
471
472 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
473
474 ExInitializeWorkItem(pntWorkItem, ndisProcWorkItemHandler, pWorkItem);
475 ExQueueWorkItem(pntWorkItem, DelayedWorkQueue);
476 return NDIS_STATUS_SUCCESS;
477}
478
479/*
480 * @implemented
481 */
482VOID
483EXPORT
485 PULONG pCpuUsage)
486/*
487 * FUNCTION: Returns how busy the current processor is as a percentage
488 * ARGUMENTS:
489 * pCpuUsage = Pointer to a buffer to place CPU usage
490 */
491{
492 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
493
495}
496
497/*
498 * @implemented
499 */
500ULONG
501EXPORT
503{
504 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
505
507}
508
509/*
510 * @implemented
511 */
512UINT
513EXPORT
515{
516 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
517
518 return NDIS_VERSION;
519}
520
521/*
522 * @implemented
523 */
524UCHAR
525EXPORT
527{
528 UCHAR PartialCancelId;
529
530 PartialCancelId = (UCHAR)InterlockedIncrement(&CancelId);
531
532 NDIS_DbgPrint(MAX_TRACE, ("Cancel ID %u\n", PartialCancelId));
533
534 return PartialCancelId;
535}
536
537/* EOF */
unsigned char BOOLEAN
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define MIN_TRACE
Definition: debug.h:14
#define MAX_TRACE
Definition: debug.h:16
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define FILE_SHARE_READ
Definition: compat.h:136
static void cleanup(void)
Definition: main.c:1335
#define ASSERT_IRQL(x)
Definition: debug.h:42
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
VOID EXPORT NdisInterlockedAddLargeInteger(IN PLARGE_INTEGER Addend, IN LARGE_INTEGER Increment, IN PNDIS_SPIN_LOCK SpinLock)
Definition: misc.c:30
VOID EXPORT NdisGetCurrentProcessorCounts(OUT PULONG pIdleCount, OUT PULONG pKernelAndUser, OUT PULONG pIndex)
Definition: misc.c:336
LONG EXPORT NdisCompareAnsiString(IN PNDIS_ANSI_STRING String1, IN PNDIS_ANSI_STRING String2, BOOLEAN CaseInSensitive)
Definition: misc.c:49
FORCEINLINE PNDIS_HANDLE_OBJECT NDIS_HANDLE_TO_POBJECT(NDIS_HANDLE handle)
Definition: misc.c:130
VOID EXPORT NdisOpenFile(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE FileHandle, OUT PUINT FileLength, IN PNDIS_STRING FileName, IN NDIS_PHYSICAL_ADDRESS HighestAcceptableAddress)
Definition: misc.c:224
static const WCHAR NDIS_FILE_FOLDER[]
Definition: misc.c:142
FORCEINLINE NDIS_HANDLE NDIS_POBJECT_TO_HANDLE(PNDIS_HANDLE_OBJECT obj)
Definition: misc.c:137
VOID EXPORT NdisGetCurrentProcessorCpuUsage(PULONG pCpuUsage)
Definition: misc.c:484
UINT EXPORT NdisGetVersion(VOID)
Definition: misc.c:514
NDIS_STATUS EXPORT NdisScheduleWorkItem(IN PNDIS_WORK_ITEM pWorkItem)
Definition: misc.c:467
VOID EXPORT NdisMapFile(OUT PNDIS_STATUS Status, OUT PVOID *MappedBuffer, IN NDIS_HANDLE FileHandle)
Definition: misc.c:149
LONG CancelId
Definition: main.c:23
LONG EXPORT NdisCompareUnicodeString(IN PNDIS_STRING String1, IN PNDIS_STRING String2, IN BOOLEAN CaseInSensitive)
Definition: misc.c:66
struct _NDIS_HANDLE_OBJECT * PNDIS_HANDLE_OBJECT
ULONG EXPORT NdisGetSharedDataAlignment(VOID)
Definition: misc.c:502
VOID EXPORT NdisCloseFile(IN NDIS_HANDLE FileHandle)
Definition: misc.c:193
VOID EXPORT NdisUnmapFile(IN NDIS_HANDLE FileHandle)
Definition: misc.c:178
UCHAR EXPORT NdisGeneratePartialCancelId(VOID)
Definition: misc.c:526
CCHAR EXPORT NdisSystemProcessorCount(VOID)
Definition: misc.c:324
VOID EXPORT NdisGetSystemUpTime(OUT PULONG pSystemUpTime)
Definition: misc.c:358
struct _NDIS_HANDLE_OBJECT NDIS_HANDLE_OBJECT
VOID NTAPI ndisProcWorkItemHandler(PVOID pContext)
Definition: misc.c:456
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
IN OUT PLONG Addend
Definition: CrNtStubs.h:25
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:46
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define FILE_OPEN
Definition: from_kernel.h:54
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
Status
Definition: gdiplustypes.h:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
ULONG NTAPI ExInterlockedAddUlong(IN OUT PULONG Addend, IN ULONG Increment, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:88
PLIST_ENTRY NTAPI ExInterlockedInsertHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:114
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LARGE_INTEGER NTAPI ExInterlockedAddLargeInteger(IN OUT PLARGE_INTEGER Addend, IN LARGE_INTEGER Increment, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:62
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define ASSERT(a)
Definition: mode.c:44
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define NdisInterlockedIncrement(Addend)
Definition: ndis.h:4386
_Out_ PULONG _Out_ PULONG pIndex
Definition: ndis.h:4565
unsigned int * PUINT
Definition: ndis.h:50
unsigned int UINT
Definition: ndis.h:50
#define NdisInterlockedRemoveHeadList(_ListHead, _SpinLock)
Definition: ndis.h:4342
_Out_ PULONG pKernelAndUser
Definition: ndis.h:4564
#define NdisInterlockedInsertTailList(_ListHead, _ListEntry, _SpinLock)
Definition: ndis.h:4333
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465
struct _NDIS_WORK_ITEM * PNDIS_WORK_ITEM
_Out_ PNDIS_HANDLE _Out_ PUINT FileLength
Definition: ndis.h:3228
#define NdisInterlockedAddUlong(_Addend, _Increment, _SpinLock)
Definition: ndis.h:4395
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define NDIS_STATUS_ALREADY_MAPPED
Definition: ndis.h:494
#define NdisInterlockedPushEntrySList(SListHead, SListEntry, Lock)
Definition: ndis.h:5268
#define NdisInterlockedDecrement(Addend)
Definition: ndis.h:4379
_Out_ PVOID * MappedBuffer
Definition: ndis.h:3245
* PNDIS_STATUS
Definition: ndis.h:45
_Out_ PNDIS_HANDLE _Out_ PUINT _In_ PNDIS_STRING _In_ NDIS_PHYSICAL_ADDRESS HighestAcceptableAddress
Definition: ndis.h:3230
#define NdisInterlockedInsertHeadList(_ListHead, _ListEntry, _SpinLock)
Definition: ndis.h:4323
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
#define NdisInterlockedPopEntrySList(SListHead, Lock)
Definition: ndis.h:5256
VOID NTAPI ExGetCurrentProcessorCounts(PULONG IdleTime, PULONG KernelAndUserTime, PULONG ProcessorNumber)
Definition: sysinfo.c:345
#define NDIS_VERSION
Definition: ndissys.h:27
VOID NTAPI ExGetCurrentProcessorCpuUsage(PULONG CpuUsage)
Definition: sysinfo.c:324
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_In_ const STRING * String2
Definition: rtlfuncs.h:2369
_In_ const STRING _In_ BOOLEAN CaseInSensitive
Definition: rtlfuncs.h:2402
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_READ_DATA
Definition: nt_native.h:628
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI LONG NTAPI RtlCompareString(PSTRING String1, PSTRING String2, BOOLEAN CaseInSensitive)
#define UNICODE_NULL
int NDIS_STATUS
Definition: ntddndis.h:475
ULONG NTAPI KeGetRecommendedSharedDataAlignment(VOID)
Definition: cpu.c:710
ULONG NTAPI KeQueryTimeIncrement(VOID)
Definition: clock.c:153
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define KeQueryTickCount(CurrentCount)
Definition: ke.h:43
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: typedefs.h:120
HANDLE FileHandle
Definition: misc.c:122
BOOLEAN Mapped
Definition: misc.c:123
PVOID MapBuffer
Definition: misc.c:125
ULONG FileLength
Definition: misc.c:124
PVOID Context
Definition: ndis.h:2318
NDIS_PROC Routine
Definition: ndis.h:2319
Definition: ntbasedef.h:636
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
int32_t * PLONG
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
char CCHAR
Definition: typedefs.h:51
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:228
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127
#define FORCEINLINE
Definition: wdftypes.h:67
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
#define ExInterlockedPushEntrySList(SListHead, SListEntry, Lock)
Definition: exfuncs.h:163
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
#define ExInterlockedPopEntrySList(SListHead, Lock)
Definition: exfuncs.h:166
@ DelayedWorkQueue
Definition: extypes.h:190
struct _WORK_QUEUE_ITEM * PWORK_QUEUE_ITEM
#define PSLIST_ENTRY
Definition: rtltypes.h:134
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180