1 ////////////////////////////////////////////////////////////////////
2 // Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
3 // All rights reserved
4 // This file was released under the GPLv2 on June 2015.
5 ////////////////////////////////////////////////////////////////////
6 /*************************************************************************
7 *
8 * File: env_spec_w32.h
9 *
10 * Module: User-mode applications (User mode execution only)
11 *
12 * Description:
13 *
14 *
15 * Author: Alter
16 *
17 *************************************************************************/
18
19 #ifndef __ENV_SPEC_W32__H_
20 #define __ENV_SPEC_W32__H_
21
22 #ifdef NT_NATIVE_MODE
23 //#include "ntddk.h" // include this for its native functions and defn's
24 #include "nt_native.h"
25 #else //NT_NATIVE_MODE
26 #include <windows.h>
27 #endif //NT_NATIVE_MODE
28 #include "platform.h"
29 //#ifndef WITHOUT_FORMATTER
30 #include "udferr_usr.h"
31 //#endif WITHOUT_FORMATTER
32
33 #ifndef NT_NATIVE_MODE
34 #ifdef ASSERT
35 #undef ASSERT
36 #define ASSERT(a) if(!(a)) {__asm int 3;}
37 #endif
38 #endif //NT_NATIVE_MODE
39
40 #ifndef MAXIMUM_FILENAME_LENGTH
41 #define MAXIMUM_FILENAME_LENGTH MAX_PATH
42 #endif //MAXIMUM_FILENAME_LENGTH
43
44 #ifndef PAGE_SHIFT
45 #define PAGE_SHIFT 12
46 #endif //PAGE_SHIFT
47
48 #ifndef PAGE_SIZE
49 #define PAGE_SIZE (ULONG)0x1000
50 #endif //PAGE_SIZE
51
52 #ifndef PHYSICAL_ADDRESS
53 #define PHYSICAL_ADDRESS LARGE_INTEGER
54 #endif //PHYSICAL_ADDRESS
55
56 #define OS_SUCCESS(a) NT_SUCCESS(a)
57 #define OSSTATUS NTSTATUS
58
59 #if defined UDF_DBG || defined DEBUG
60 #define DBG
61 #ifndef CDRW_W32
62 #define UDF_DBG
63 #endif //CDRW_W32
64 #endif
65
66 #define ERESEOURCE ULONG
67 #define PERESEOURCE PULONG
68
69 #define KEVENT ULONG
70 #define PKEVENT PULONG
71
72 typedef ULONG KSPIN_LOCK; // winnt ntndis
73 typedef KSPIN_LOCK *PKSPIN_LOCK;
74
75 #ifndef NT_NATIVE_MODE
76 // Status ot
77 #define NTSTATUS LONG
78
79 #define NT_SUCCESS(x) ( (NTSTATUS)(x)>=0 )
80
81 #define PsGetCurrentThread() GetCurrentThreadId()
82
83 #define PsGetVersion(a,b,c,d) { \
84 OSVERSIONINFO OsVer; \
85 OsVer.dwOSVersionInfoSize = sizeof(OsVer); \
86 GetVersionEx(&OsVer); \
87 if(a) (*(a)) = OsVer.dwMajorVersion; \
88 if(b) (*(b)) = OsVer.dwMinorVersion; \
89 if(c) (*(c)) = OsVer.dwBuildNumber; \
90 if(d) (d)->Buffer = L""; \
91 if(d) (d)->Length = 0; \
92 if(d) (d)->MaximumLength = 0; \
93 }
94
95 extern "C"
96 VOID
97 PrintDbgConsole(
98 PCHAR DebugMessage,
99 ...
100 );
101
102 #else //NT_NATIVE_MODE
103 #define HINSTANCE HANDLE
104 #endif //NT_NATIVE_MODE
105
106 typedef
107 int (*PSKIN_INIT) (
108 HINSTANCE hInstance, // handle to current instance
109 HINSTANCE hPrevInstance, // handle to previous instance
110 int nCmdShow // show state
111 );
112
113 typedef
114 int (*PSKIN_PRINTF) (
115 const char* Message,
116 ...
117 );
118
119 typedef
120 PWCHAR (__stdcall *PSKIN_GETCMDLINE) (
121 VOID
122 );
123
124 typedef
125 ULONG (__stdcall *PSKIN_MSG) (
126 ULONG MsgId,
127 ULONG MsgSubId,
128 PVOID DataIn,
129 ULONG DataInLen,
130 PVOID DataOut,
131 ULONG DataInOut
132 );
133
134 typedef struct _SKIN_API {
135 PSKIN_INIT Init;
136 PSKIN_PRINTF Printf;
137 PSKIN_GETCMDLINE GetCommandLine;
138 PSKIN_MSG Msg;
139 } SKIN_API, *PSKIN_API;
140
141 #ifdef USE_SKIN_MODEL
142
143 extern "C" PSKIN_API SkinAPI;
144 extern PSKIN_API SkinLoad(
145 PWCHAR path,
146 HINSTANCE hInstance, // handle to current instance
147 HINSTANCE hPrevInstance, // handle to previous instance
148 int nCmdShow // show state
149 );
150
151 #define SkinPrintf SkinAPI->Printf
152 #define SkinGetCmdLine SkinAPI->GetCommandLine
153 #define SkinNotify(op, state, ctx, sz) SkinAPI->Msg(op, state, ctx, sz, NULL, 0)
154 #define SkinAsk(op, state, ctx, def) SkinAPI->Msg(op, state, ctx, sizeof(ctx), NULL, 0)
155
156 #else
157
158 #define SkinLoad(path) {;}
159
160 #if defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
161 #define SkinPrintf(x) {;}
162 /*VOID
163 inline
164 SkinPrintf(
165 PCHAR Message,
166 ...
167 )
168 {
169 //do nothing
170 return;
171 }*/
172 #else // defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
173 #define SkinPrintf printf
174 #endif
175
176 #define SkinGetCmdLine GetCommandLineW
177 #define SkinNotify(op, state, ctx) {;}
178 #define SkinAsk(op, state, ctx, def) (def)
179
180 #endif // defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
181
182 #if defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
183
184 #if defined(PRINT_TO_DBG_LOG) || defined(PRINT_ALWAYS)
185 #define UserPrint(x) PrintDbgConsole x
186 #else
187 #define UserPrint(x) {;}
188 #endif // PRINT_TO_DBG_LOG
189
190 #else // defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
191
192 #if defined(PRINT_TO_DBG_LOG) || defined(PRINT_ALWAYS)
193
194 #define UserPrint(x) \
195 { \
196 SkinPrintf x ; \
197 PrintDbgConsole x ; \
198 }
199
200 #else // PRINT_TO_DBG_LOG
201
202 #define UserPrint(x) \
203 { \
204 SkinPrintf x ; \
205 }
206
207 #endif // PRINT_TO_DBG_LOG
208
209 #endif // defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
210
211 #if defined(DBG) || defined(PRINT_ALWAYS)
212
213 #define DbgPrint SkinPrintf
214
215 #ifdef KdPrint
216 #undef KdPrint
217 #endif
218
219 #if defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
220 #ifdef PRINT_TO_DBG_LOG
221 #define KdPrint(x) PrintDbgConsole x;
222 #else
223 #define KdPrint(x) {;}
224 #endif
225 #else
226
227 #if defined(PRINT_TO_DBG_LOG) || defined(PRINT_ALWAYS)
228 #define KdPrint(x) \
229 { \
230 SkinPrintf x ; \
231 PrintDbgConsole x ; \
232 }
233 #else
234 #define KdPrint(x) \
235 { \
236 SkinPrintf x ; \
237 }
238 #endif
239 #endif
240
241 #ifdef USE_MM_PRINT
242 #define MmPrint(_x_) DbgPrint _x_
243 #else
244 #define MmPrint(_x_) {NOTHING;}
245 #endif //USE_MM_PRINT
246
247 #ifdef USE_TIME_PRINT
248 extern ULONG UdfTimeStamp;
249 #define TmPrint(_x_) {UdfTimeStamp++;KdPrint(("TM:%d: ",UdfTimeStamp));KdPrint(_x_);}
250 #else
251 #define TmPrint KdPrint
252 #endif //USE_MM_PRINT
253
254 #ifdef USE_PERF_PRINT
255 #define PerfPrint(_x_) DbgPrint _x_
256 #else
257 #define PerfPrint(_x_) {NOTHING;}
258 #endif //USE_MM_PRINT
259
260 #if defined(CDRW_W32) || defined(LIBUDFFMT) || defined(LIBUDF)
261 #ifdef USE_AD_PRINT
262 #undef USE_AD_PRINT
263 #endif
264 #ifdef USE_TH_PRINT
265 #undef USE_TH_PRINT
266 #endif
267 #endif
268
269 #ifdef USE_AD_PRINT
270 #define AdPrint(_x_) {DbgPrint("Thrd:%x:",PsGetCurrentThread());DbgPrint _x_;}
271 #else
272 #define AdPrint(_x_) {NOTHING;}
273 #endif
274
275 #ifdef USE_TH_PRINT
276 #define ThPrint(_x_) {DbgPrint("Thrd:%x:",PsGetCurrentThread());DbgPrint _x_;}
277 #else
278 #define ThPrint(_x_) {NOTHING;}
279 #endif
280
281 #ifdef USE_DUMP_EXT
282 #define ExtPrint(_x_) DbgPrint _x_
283 #else
284 #define ExtPrint(_x_) {NOTHING;}
285 #endif //USE_MM_PRINT
286
287 #else
288 #define KdPrint(x) {NOTHING;}
289 #define MmPrint(_x_) {NOTHING;}
290 #define TmPrint(_x_) {NOTHING;}
291 #define PerfPrint(_x_) {NOTHING;}
292 #define AdPrint(_x_) {NOTHING;}
293 #define ThPrint(_x_) {NOTHING;}
294 #define ExtPrint(_x_) {NOTHING;}
295 #endif
296
297 #define DbgTouch(a)
298
299 #ifndef NT_NATIVE_MODE
300 #include "assert.h"
301
302 #define ASSERT(_x_) assert(_x_)
303 #define UDFTouch(a)
304
305 #endif //NT_NATIVE_MODE
306
307 #define NonPagedPool 0
308 #define PagedPool 1
309 //#define NonPagedPoolMustSucceed 2
310 #define NonPagedPoolCacheAligned 4
311
312 #define KdDump(a,b) \
313 if((a)!=NULL) { \
314 ULONG i; \
315 for(i=0; i<(b); i++) { \
316 ULONG c; \
317 c = (ULONG)(*(((PUCHAR)(a))+i)); \
318 KdPrint(("%2.2x ",c)); \
319 if ((i & 0x0f) == 0x0f) KdPrint(("\n")); \
320 } \
321 KdPrint(("\n")); \
322 }
323
324 //mem ot
325 //#define ExAllocatePool(hernya,size) MyAllocatePool(size)
326 //#define ExFreePool(size) MyFreePool((PCHAR)(size))
327 //#define SystemAllocatePool(hernya,size) GlobalAlloc(GMEM_DISCARDABLE, size);
328 //#define SystemFreePool(addr) GlobalFree((PVOID)(addr))
329 #define DbgMoveMemory RtlMoveMemory
330 #define DbgCompareMemory RtlCompareMemory
331 #define DbgCopyMemory RtlCopyMemory
332 #define DbgAllocatePool ExAllocatePool
333 #define DbgAllocatePoolWithTag(a,b,c) ExAllocatePool(a,b)
334 #define DbgFreePool ExFreePool
335
336 #ifdef NT_NATIVE_MODE
337 /*
338 #define GlobalAlloc(foo, size) MyGlobalAlloc( size );
339 #define GlobalFree(ptr) MyGlobalFree( ptr );
340
341 extern "C"
342 PVOID MyGlobalAlloc(ULONG Size);
343
344 extern "C"
345 VOID MyGlobalFree(PVOID Addr);
346 */
347 #endif
348
349 #if !defined(KERNEL_MODE_MM_BEHAVIOR) && !defined(USE_THREAD_HEAPS)
350 #define ExAllocatePoolWithTag(hernya,size,tag) GlobalAlloc(GMEM_DISCARDABLE, (size))
351 #define ExAllocatePool(hernya,size) GlobalAlloc(GMEM_DISCARDABLE, (size))
352 #define ExFreePool(addr) GlobalFree((PVOID)(addr))
353 #endif
354
355 #if defined(KERNEL_MODE_MM_BEHAVIOR) || defined(USE_THREAD_HEAPS)
356 #define ExAllocatePoolWithTag(MemoryType,size,tag) ExAllocatePool((MemoryType), (size))
357
358 extern "C"
359 PVOID ExAllocatePool(ULONG MemoryType, ULONG Size);
360
361 extern "C"
362 VOID ExFreePool(PVOID Addr);
363 #endif //KERNEL_MODE_MM_BEHAVIOR || USE_THREAD_HEAPS
364
365 #ifndef NT_NATIVE_MODE
366
367 //string ot
368 typedef struct _UNICODE_STRING {
369 USHORT Length;
370 USHORT MaximumLength;
371 PWSTR Buffer;
372 } UNICODE_STRING;
373 typedef UNICODE_STRING *PUNICODE_STRING;
374
375 typedef struct _ANSI_STRING {
376 USHORT Length;
377 USHORT MaximumLength;
378 PSTR Buffer;
379 } ANSI_STRING;
380 typedef ANSI_STRING *PANSI_STRING;
381
382 #endif //NT_NATIVE_MODE
383
384 #define PtrOffset(BASE,OFFSET) ((ULONG)((ULONG)(OFFSET) - (ULONG)(BASE)))
385
386 // Device object ot
387
388 #ifndef DO_UNLOAD_PENDING
389 // Define Device Object (DO) flags
390 //
391
392 #define DO_UNLOAD_PENDING 0x00000001
393 #define DO_VERIFY_VOLUME 0x00000002
394 #define DO_BUFFERED_IO 0x00000004
395 #define DO_EXCLUSIVE 0x00000008
396 #define DO_DIRECT_IO 0x00000010
397 #define DO_MAP_IO_BUFFER 0x00000020
398 #define DO_DEVICE_HAS_NAME 0x00000040
399 #define DO_DEVICE_INITIALIZING 0x00000080
400 #define DO_SYSTEM_BOOT_PARTITION 0x00000100
401 #define DO_LONG_TERM_REQUESTS 0x00000200
402 #define DO_NEVER_LAST_DEVICE 0x00000400
403 #define DO_SHUTDOWN_REGISTERED 0x00000800
404
405 #endif //DO_UNLOAD_PENDING
406
407 #ifdef NT_NATIVE_MODE
408 #define _DEVICE_OBJECT _MY_DEVICE_OBJECT
409 #define DEVICE_OBJECT MY_DEVICE_OBJECT
410 #define PDEVICE_OBJECT PMY_DEVICE_OBJECT
411 #endif //NT_NATIVE_MODE
412
413 typedef struct _DEVICE_OBJECT {
414
415 #ifndef LIBUDF
416
417 HANDLE h;
418 PVOID DeviceExtension;
419 ULONG Flags;
420 ULONG AlignmentRequirement;
421 UCHAR StackSize;
422
423 #endif // LIBUDF
424
425
426 #ifdef LIBUDFFMT
427
428 struct _UDF_FMT_PARAMETERS* cbio;
429 PVOID lpContext;
430
431 #else
432 #ifdef LIBUDF
433 PVOID lpContext;
434 #endif // LIBUDF
435 #endif // LIBUDFFMT
436
437 } DEVICE_OBJECT, *PDEVICE_OBJECT;
438
439 #ifndef CDRW_W32
440 /*
441 typedef ULONG DEVICE_OBJECT;
442 typedef ULONG PDEVICE_OBJECT;
443 */
444 #define INVALID_PACKET 0x01
445
446 typedef struct _PACKET {
447 // Node Identifier
448 // UDFIdentifier NodeIdentifier;
449 // Pointer to the buffer (in non-paged pool)
450 PCHAR buffer;
451 // Offset, from which this data was read
452 LARGE_INTEGER offset;
453 // Flags
454 UCHAR flags;
455 } PACKET, *PPACKET;
456
457 #define UDFInitPacket(x) STATUS_SUCCESS
458 #endif //CDRW_W32
459
460 #define try_return(S) { S; goto try_exit; }
461 #define NOTHING
462
463 #define FlagOn(x,f) ((x) & (f))
464
465 #define RtlCompareMemory(s1,s2,l) MyRtlCompareMemory(s1,s2,l)
466 // Structure ot
467 extern "C"
468 ULONG
469 MyRtlCompareMemory(
470 PVOID s1,
471 PVOID s2,
472 ULONG len
473 );
474 //#define RtlCompareMemory(d1,d2,l) (ULONG)(memcmp (d1,d2,l))
475
476 #define KeSetEvent(pEvt, foo, foo2) {NOTHING;}
477 #define KeInitializeEvent(pEvt, foo, foo2) {NOTHING;}
478 #define KeWaitForSingleObject(pEvt, foo, a, b, c) {NOTHING;}
479 #define DbgWaitForSingleObject(o, to) KeWaitForSingleObject(o, Executive, KernelMode, FALSE, to);
480 //#define DbgWaitForSingleObject KeWaitForSingleObject
481 #ifdef NT_NATIVE_MODE
482 #define KeDelayExecutionThread(mode, foo, t) { NtDelayExecution(false, t); }
483 #else //NT_NATIVE_MODE
484 #define KeDelayExecutionThread(mode, foo, t) { Sleep( abs((LONG)(((t)->QuadPart)/10000)) ); }
485 #endif //NT_NATIVE_MODE
486
487 /*#define RtlCompareUnicodeString(s1,s2,cs) \
488 (((s1)->Length == (s2)->Length) && \
489 (RtlCompareMemory(s1,s2,(s1)->Length)))
490 */
491 #ifndef CDRW_W32
492 #ifdef _X86_
493
494 // This is an illegal use of INT3
495 #define UDFBreakPoint() __asm int 3
496 #else // _X86_
497
498 #define UDFBreakPoint() DbgBreakPoint()
499 #endif // _X86_
500
501 #ifdef BRUTE
502 #define BrutePoint() UDFBreakPoint()
503 #else
504 #define BrutePoint() {}
505 #endif // BRUTE
506
507 #ifdef VALIDATE_STRUCTURES
508 #define ValidateFileInfo(fi) \
509 { /* validate FileInfo */ \
510 if((fi)->IntegrityTag) { \
511 KdPrint(("UDF: ERROR! Using deallocated structure !!!\n"));\
512 /*BrutePoint();*/ \
513 } \
514 }
515 #else
516 #define ValidateFileInfo(fi) {}
517 #endif
518
519 #else //CDRW_W32
520
521 #ifdef BRUTE
522 #ifdef _X86_
523
524 // This is an illegal use of INT3
525 #define BrutePoint() __asm int 3
526 #else // _X86_
527
528 #define BrutePoint() DbgBreakPoint()
529 #endif // _X86_
530 #else
531 #define BrutePoint() {}
532 #endif // BRUTE
533
534 #endif //CDRW_W32
535
536 #ifndef NT_NATIVE_MODE
537
538 extern "C"
539 ULONG
540 RtlCompareUnicodeString(
541 PUNICODE_STRING s1,
542 PUNICODE_STRING s2,
543 BOOLEAN UpCase);
544
545 extern "C"
546 NTSTATUS
547 RtlUpcaseUnicodeString(
548 PUNICODE_STRING dst,
549 PUNICODE_STRING src,
550 BOOLEAN Alloc
551 );
552
553 extern "C"
554 NTSTATUS
555 RtlAppendUnicodeToString(
556 IN PUNICODE_STRING Str1,
557 IN PWSTR Str2
558 );
559
560 #endif //NT_NATIVE_MODE
561
562 extern "C"
563 NTSTATUS
564 MyInitUnicodeString(
565 IN PUNICODE_STRING Str1,
566 IN PCWSTR Str2
567 );
568
569 #ifndef NT_NATIVE_MODE
570 #define KeQuerySystemTime(t) GetSystemTimeAsFileTime((LPFILETIME)(t));
571
572 typedef struct _FILE_BOTH_DIR_INFORMATION {
573 ULONG NextEntryOffset;
574 ULONG FileIndex;
575 LARGE_INTEGER CreationTime;
576 LARGE_INTEGER LastAccessTime;
577 LARGE_INTEGER LastWriteTime;
578 LARGE_INTEGER ChangeTime;
579 LARGE_INTEGER EndOfFile;
580 LARGE_INTEGER AllocationSize;
581 ULONG FileAttributes;
582 ULONG FileNameLength;
583 ULONG EaSize;
584 CCHAR ShortNameLength;
585 WCHAR ShortName[12];
586 WCHAR FileName[1];
587 } FILE_BOTH_DIR_INFORMATION, *PFILE_BOTH_DIR_INFORMATION;
588
589 #endif //NT_NATIVE_MODE
590
591 typedef UCHAR KIRQL;
592 typedef KIRQL *PKIRQL;
593
594 typedef ULONG ERESOURCE;
595 typedef ERESOURCE *PERESOURCE;
596
597 #define KeRaiseIrql(irql, oldIrql) \
598 { \
599 *oldIrql = 0; \
600 }
601
602 #define KeLowerIrql(oldIrql) {;}
603
604 #define KeInitializeSpinLock(sl) \
605 { \
606 *(sl) = 0; \
607 }
608
609 #define KeAcquireSpinLock(sl,irql) \
610 { \
611 ULONG isLocked = TRUE; \
612 while(isLocked) AcquireXLock(*(sl), isLocked, TRUE);\
613 }
614
615 #define ExAcquireResourceExclusiveLite(res, wait) \
616 { \
617 ULONG isLocked = TRUE; \
618 while(isLocked) AcquireXLock(*(res), isLocked, TRUE);\
619 }
620
621 #define ExAcquireResourceSharedLite(res, wait) \
622 { \
623 ULONG isLocked = TRUE; \
624 while(isLocked) AcquireXLock(*(res), isLocked, TRUE);\
625 }
626
627 #define KeReleaseSpinLock(sl,irql) \
628 { \
629 ULONG isLocked; \
630 AcquireXLock(*(sl), isLocked, FALSE); \
631 }
632
633 #define ExGetCurrentResourceThread() 0
634
635 #define ExReleaseResourceForThreadLite(res, thrdID) \
636 { \
637 ULONG isLocked; \
638 AcquireXLock(*(res), isLocked, FALSE); \
639 }
640
ExInitializeResourceLite(PULONG res)641 NTSTATUS inline ExInitializeResourceLite(PULONG res)
642 {
643 *(res) = 0;
644 return STATUS_SUCCESS;
645 }
646
647 #define ExDeleteResourceLite(res) \
648 { \
649 *(res) = 0; \
650 }
651
652 #define ExConvertExclusiveToSharedLite(res) {/* do nothing */}
653
654 #ifndef CDRW_W32
655
656 #define UDFAcquireResourceExclusive(Resource,CanWait) \
657 ExAcquireResourceExclusiveLite((Resource),(CanWait))
658 #define UDFAcquireResourceShared(Resource,CanWait) \
659 ExAcquireResourceSharedLite((Resource),(CanWait))
660 // a convenient macro (must be invoked in the context of the thread that acquired the resource)
661 #define UDFReleaseResource(Resource) \
662 ExReleaseResourceForThreadLite((Resource), ExGetCurrentResourceThread())
663 #define UDFDeleteResource(Resource) \
664 ExDeleteResourceLite((Resource))
665 #define UDFConvertExclusiveToSharedLite(Resource) \
666 ExConvertExclusiveToSharedLite((Resource))
667 #define UDFInitializeResourceLite(Resource) \
668 ExInitializeResourceLite((Resource))
669 #define UDFAcquireSharedStarveExclusive(Resource,CanWait) \
670 ExAcquireSharedStarveExclusive((Resource),(CanWait))
671 #define UDFAcquireSharedWaitForExclusive(Resource,CanWait) \
672 ExAcquireSharedWaitForExclusive((Resource),(CanWait))
673 //#define UDFDebugAcquireResourceExclusiveLite(a,b,c,d) ExAcquireResourceExclusiveLite(a,b)
674
675 #define UDFInterlockedIncrement(addr) \
676 ((*addr)++)
677 #define UDFInterlockedDecrement(addr) \
678 ((*addr)--)
679 int
680 __inline
UDFInterlockedExchangeAdd(PLONG addr,LONG i)681 UDFInterlockedExchangeAdd(PLONG addr, LONG i) {
682 LONG Old = (*addr);
683 (*addr) += i;
684 return Old;
685 }
686
687 #endif //CDRW_W32
688
689 //
690 // Interrupt Request Level definitions
691 //
692
693 #define PASSIVE_LEVEL 0 // Passive release level
694 #define LOW_LEVEL 0 // Lowest interrupt level
695 #define APC_LEVEL 1 // APC interrupt level
696 #define DISPATCH_LEVEL 2 // Dispatcher level
697
698 #define PROFILE_LEVEL 27 // timer used for profiling.
699 #define CLOCK1_LEVEL 28 // Interval clock 1 level - Not used on x86
700 #define CLOCK2_LEVEL 28 // Interval clock 2 level
701 #define IPI_LEVEL 29 // Interprocessor interrupt level
702 #define POWER_LEVEL 30 // Power failure level
703 #define HIGH_LEVEL 31 // Highest interrupt level
704 #define SYNCH_LEVEL (IPI_LEVEL-1) // synchronization level
705
706 #define KeGetCurrentIrql() PASSIVE_LEVEL
707
708 #ifndef NT_NATIVE_MODE
709
710 typedef struct _TIME_FIELDS {
711 USHORT Year; // range [1601...]
712 USHORT Month; // range [1..12]
713 USHORT Day; // range [1..31]
714 USHORT Hour; // range [0..23]
715 USHORT Minute; // range [0..59]
716 USHORT Second; // range [0..59]
717 USHORT Milliseconds;// range [0..999]
718 USHORT Weekday; // range [0..6] == [Sunday..Saturday]
719 } TIME_FIELDS;
720 typedef TIME_FIELDS *PTIME_FIELDS;
721
722 //#define RtlTimeFieldsToTime(a,b) TRUE
723 BOOLEAN
724 RtlTimeFieldsToTime(
725 IN PTIME_FIELDS TimeFields,
726 IN PLARGE_INTEGER Time
727 );
728
729 #define ExSystemTimeToLocalTime(SysTime, LocTime) FileTimeToLocalFileTime((PFILETIME)(SysTime), (PFILETIME)(LocTime))
730
731 //#define RtlTimeToTimeFields(a,b) {}
732 BOOLEAN
733 RtlTimeToTimeFields(
734 IN PLARGE_INTEGER Time,
735 IN PTIME_FIELDS TimeFields
736 );
737
738 #define ExLocalTimeToSystemTime(LocTime, SysTime) LocalFileTimeToFileTime((PFILETIME)(LocTime), (PFILETIME)(SysTime))
739
740 #endif //NT_NATIVE_MODE
741
742 #ifndef CDRW_W32
743
744 typedef struct _FSRTL_COMMON_FCB_HEADER {
745 SHORT NodeTypeCode;
746 SHORT NodeByteSize;
747 UCHAR Flags;
748 UCHAR IsFastIoPossible;
749 #if (_WIN32_WINNT >= 0x0400)
750 UCHAR Flags2;
751 UCHAR Reserved;
752 #endif // (_WIN32_WINNT >= 0x0400)
753 PERESOURCE Resource;
754 PERESOURCE PagingIoResource;
755 LARGE_INTEGER AllocationSize;
756 LARGE_INTEGER FileSize;
757 LARGE_INTEGER ValidDataLength;
758 } FSRTL_COMMON_FCB_HEADER, *PFSRTL_COMMON_FCB_HEADER;
759
760 typedef struct _SECTION_OBJECT_POINTERS {
761 PVOID DataSectionObject;
762 PVOID SharedCacheMap;
763 PVOID ImageSectionObject;
764 } SECTION_OBJECT_POINTERS;
765 typedef SECTION_OBJECT_POINTERS *PSECTION_OBJECT_POINTERS;
766
767
768 extern NTSTATUS UDFPhReadSynchronous(
769 PDEVICE_OBJECT DeviceObject,
770 PVOID Buffer,
771 ULONG Length,
772 LONGLONG Offset,
773 PULONG ReadBytes,
774 ULONG Flags);
775
776 extern NTSTATUS UDFPhWriteSynchronous(
777 PDEVICE_OBJECT DeviceObject, // the physical device object
778 PVOID Buffer,
779 ULONG Length,
780 LONGLONG Offset,
781 PULONG WrittenBytes,
782 ULONG Flags);
783
784 #if 0
785 extern NTSTATUS
786 UDFPhWriteVerifySynchronous(
787 PDEVICE_OBJECT DeviceObject, // the physical device object
788 PVOID Buffer,
789 ULONG Length,
790 LONGLONG Offset,
791 PULONG WrittenBytes,
792 ULONG Flags
793 );
794 #endif
795
796 #define UDFPhWriteVerifySynchronous UDFPhWriteSynchronous
797
798 extern NTSTATUS UDFPhSendIOCTL(
799 IN ULONG IoControlCode,
800 IN PDEVICE_OBJECT DeviceObject,
801 IN PVOID InputBuffer ,
802 IN ULONG InputBufferLength,
803 OUT PVOID OutputBuffer ,
804 IN ULONG OutputBufferLength,
805 IN BOOLEAN OverrideVerify,
806 OUT PVOID Iosb OPTIONAL);
807
808 #endif //CDRW_W32
809
810 VOID set_image_size(HANDLE h,
811 // ULONG LBA);
812 int64 len);
813
814 #ifdef UDF_FORMAT_MEDIA
815 struct _UDFVolumeControlBlock;
816 #endif
817
818 #ifndef UDF_FORMAT_MEDIA
819 ULONG write(
820 HANDLE h,
821 PCHAR buff,
822 ULONG len);
823 #endif
824
825 extern "C"
826 HANDLE
827 my_open(
828 #ifndef CDRW_W32
829 struct _UDFVolumeControlBlock* Vcb,
830 #endif //CDRW_W32
831 PWCHAR fn);
832
833 #ifdef UDF_FORMAT_MEDIA
834 struct _UDFFmtState;
835 #endif //UDF_FORMAT_MEDIA
836
837 extern
838 void
839 my_exit(
840 #ifdef UDF_FORMAT_MEDIA
841 struct _UDFFmtState* fms,
842 #endif //UDF_FORMAT_MEDIA
843 int rc
844 );
845
846 #ifndef CDRW_W32
847 uint64 udf_lseek64(HANDLE fd, uint64 offset, int whence);
848 #endif //CDRW_W32
849
850 #ifdef LIBUDFFMT
851 BOOLEAN
852 udf_get_sizes(
853 IN PDEVICE_OBJECT DeviceObject,
854 IN ULONG* blocks
855 );
856 #endif //LIBUDFFMT
857
858 int64
859 get_file_size(
860 HANDLE h
861 );
862
863 int64
864 set_file_pointer(
865 HANDLE h,
866 int64 sz
867 );
868
869 #ifndef NT_NATIVE_MODE
870 typedef struct _IO_STATUS_BLOCK {
871 ULONG Status;
872 ULONG Information;
873 } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
874 #endif //NT_NATIVE_MODE
875
876
877 #ifndef UDF_FORMAT_MEDIA
878 extern ULONG LockMode;
879 extern BOOLEAN open_as_device;
880 extern BOOLEAN opt_invalidate_volume;
881 #endif //UDF_FORMAT_MEDIA
882
883 extern "C"
884 ULONG
885 MyLockVolume(
886 HANDLE h,
887 ULONG* pLockMode // OUT
888 );
889
890 extern "C"
891 ULONG
892 MyUnlockVolume(
893 HANDLE h,
894 ULONG* pLockMode // IN
895 );
896
897 #ifndef CDRW_W32
898 ULONG
899 UDFGetDevType(PDEVICE_OBJECT DeviceObject);
900 #endif //CDRW_W32
901
902 #ifndef INVALID_HANDLE_VALUE
903 #define INVALID_HANDLE_VALUE ((HANDLE)(-1))
904 #endif
905
906 #ifndef ANSI_DOS_STAR
907
908 #define ANSI_DOS_STAR ('<')
909 #define ANSI_DOS_QM ('>')
910 #define ANSI_DOS_DOT ('"')
911
912 #define DOS_STAR (L'<')
913 #define DOS_QM (L'>')
914 #define DOS_DOT (L'"')
915
916 #endif //ANSI_DOS_STAR
917
918 extern "C"
919 BOOLEAN
920 ProbeMemory(
921 PVOID MemPtr,
922 ULONG Length,
923 BOOLEAN ForWrite
924 );
925
926 #ifdef NT_NATIVE_MODE
927 #include "env_spec_nt.h"
928 #endif //NT_NATIVE_MODE
929
930 #ifndef InitializeListHead
931
932 //
933 // Doubly-linked list manipulation routines. Implemented as macros
934 // but logically these are procedures.
935 //
936
937 //
938 // VOID
939 // InitializeListHead(
940 // PLIST_ENTRY ListHead
941 // );
942 //
943
944 #define InitializeListHead(ListHead) (\
945 (ListHead)->Flink = (ListHead)->Blink = (ListHead))
946
947 //
948 // BOOLEAN
949 // IsListEmpty(
950 // PLIST_ENTRY ListHead
951 // );
952 //
953
954 #define IsListEmpty(ListHead) \
955 ((ListHead)->Flink == (ListHead))
956
957 //
958 // PLIST_ENTRY
959 // RemoveHeadList(
960 // PLIST_ENTRY ListHead
961 // );
962 //
963
964 #define RemoveHeadList(ListHead) \
965 (ListHead)->Flink;\
966 {RemoveEntryList((ListHead)->Flink)}
967
968 //
969 // PLIST_ENTRY
970 // RemoveTailList(
971 // PLIST_ENTRY ListHead
972 // );
973 //
974
975 #define RemoveTailList(ListHead) \
976 (ListHead)->Blink;\
977 {RemoveEntryList((ListHead)->Blink)}
978
979 //
980 // VOID
981 // RemoveEntryList(
982 // PLIST_ENTRY Entry
983 // );
984 //
985
986 #define RemoveEntryList(Entry) {\
987 PLIST_ENTRY _EX_Blink;\
988 PLIST_ENTRY _EX_Flink;\
989 _EX_Flink = (Entry)->Flink;\
990 _EX_Blink = (Entry)->Blink;\
991 _EX_Blink->Flink = _EX_Flink;\
992 _EX_Flink->Blink = _EX_Blink;\
993 }
994
995 //
996 // VOID
997 // InsertTailList(
998 // PLIST_ENTRY ListHead,
999 // PLIST_ENTRY Entry
1000 // );
1001 //
1002
1003 #define InsertTailList(ListHead,Entry) {\
1004 PLIST_ENTRY _EX_Blink;\
1005 PLIST_ENTRY _EX_ListHead;\
1006 _EX_ListHead = (ListHead);\
1007 _EX_Blink = _EX_ListHead->Blink;\
1008 (Entry)->Flink = _EX_ListHead;\
1009 (Entry)->Blink = _EX_Blink;\
1010 _EX_Blink->Flink = (Entry);\
1011 _EX_ListHead->Blink = (Entry);\
1012 }
1013
1014 //
1015 // VOID
1016 // InsertHeadList(
1017 // PLIST_ENTRY ListHead,
1018 // PLIST_ENTRY Entry
1019 // );
1020 //
1021
1022 #define InsertHeadList(ListHead,Entry) {\
1023 PLIST_ENTRY _EX_Flink;\
1024 PLIST_ENTRY _EX_ListHead;\
1025 _EX_ListHead = (ListHead);\
1026 _EX_Flink = _EX_ListHead->Flink;\
1027 (Entry)->Flink = _EX_Flink;\
1028 (Entry)->Blink = _EX_ListHead;\
1029 _EX_Flink->Blink = (Entry);\
1030 _EX_ListHead->Flink = (Entry);\
1031 }
1032
1033 #endif //InitializeListHead
1034
1035 #endif // __ENV_SPEC_W32__H_
1036