The Windows 7 Windows Driver Kit Eliyas Yakub
The Windows 7 Windows Driver Kit Eliyas Yakub Dev Lead - Windows Driver Framework Dev Manager – Windows Driver Kit
Agenda Installation How build works Techniques for investigating build issues Build Environment Changes in Win 7 New Tools and Samples Sample Quality Improvements Documentation Improvements Q&A
WDK Installation Using Kitsetup Single UI for all kit components Single EULA for all kit components Documentation installation is part of complete kit installation Supports servicing Updates to WDK will be made available on Microsoft Connect as needed Support for Windows 2000 build environment is removed
Kit. Setup
How Build Works
The WDK Build Tools The WDK Build environment includes: Build utilities: build. exe and nmake. exe Files used to control the build environment: setenv. bat Files to identify what is to be built: dirs files , sources files , makefiles. Compiler cl. exe and linker link. exe Supporting tools: midl. exe, rc. exe , binplace. exe , stampinf. exe , etc. New in WDK for Win 7: oacrcl. exe and oacrlink. exe
Setting Up the Build Environment Open the build environment window by using use the Start menu path Start | All Programs | Windows Driver Kits | WDK_Version | Build Environment | Operating System | Build Environment. Command Prompt window appears The setenv. bat executes in this window, setting the values of numerous environment variables. The setenv. bat command line options include: Type of the build: checked or free Processor architecture: x 86, amd 64 or IA 64 Operating system: Win. XP, Win. NET, Win. LH, Win 7 New for Win 7: setenv. bat has more command line parameters no_oacr flag and no_separate_object_root flags
How the WDK Build Process Works 1. Build. exe scans the dirs files for DIRS and OPTIONAL_DIRS macros 2. Build. exe recurces the tree looking for leaf nodes (sources file) to process 3. Once build. exe found sources file it look for the macros: TARGETNAME, TARGETPATH, SOURCES, INCLUDES 4. Build. exe builds objects. mac for this directory 5. Build. exe calls nmake in each dir as necessary based on what macros are listed in the sources file. 6. If the sources file has a NTTARGETFILEx macro, this causes Bar makefile. def to include makefile. inc 7. Nmake is called per a leaf dir per build pass.
How the Build Process Works dirs Foo dirs Bar 1 Bar 2 Fred
Build Passes Build. exe uses a multi-pass process: Pass 0 produces source code: runs midl. exe (. idl >. h/. c/. tlb ) or other tools to produce source code. . Pass 1 compiles source code to objects/libs (runs cl. exe ) Pass 2 links objects/libs into final images: -. exe , . sys , . dll (runs link. exe ) Before build. exe starts Build. exe Scan Pass 0 Pass 1 Pass 2 After build. exe exits
Build Passes - Example Build. exe scans the list of targets as: dirs Pass 0 Foo (Library) Bar (. idl, dynlink) Pass 1 Fred (Driver) Pass 2 • run Nmake->midl. exe->Bar. idl • run Nmake ->cl. exe->Foo. lib • run Nmake ->cl. exe->Bar. lib (import) • run Nmake->cl. exe->Fred. obj • run Nmake ->link. exe->Bar. dll • run Nmake ->link. exe->Fred. sys
Multiprocessor Build No need to do anything in the WDK build environment to run on a multiprocessor machine! WDK sets the environment variable BUILD_MULTIPROCESSOR = 1 Enables build. exe to run 1 thread per processor. M option of build. exe Same as –M No synchronization required between different build passes For example: No synchronization is needed between a LIB produced in Pass 1 and a sys file consuming LIB in Pass 2. All tasks of a pass complete before next pass starts
Multiprocessor Build (Contd. ) PRODUCES/CONSUMES macros for synchronization within the same pass Different macros for different build passes: BUILD_PASS 0_PRODUCES/ BUILD_PASS 0_CONSUMES //for Pass 0 BUILD_PRODUCES/BUILD_CONSUMES //for Pass 1 BUILD_PASS 2_PRODUCES/BUILD_PASS 2_CONSUMES //for Pass 2 Order in DIRS is still important If consumes is seen without any prior matching produces, it is ignored One producer – many consumers Producer and consumer match by a string
Synchonization Example Build. exe DIRS = Geometry Cos. c Sin. c makefile sources Math Math. c makefile sources Plot Plot. c Plot. rc Plot. inx makefile. inc sources ; sources file for Geometry Project TARGETNAME = Geometry TARGETTYPE = LIBRARY BUILD_PRODUCES = geometry_lib SOURCES = Cos. c Sin. c ; sources file for Math Project TARGETNAME = Math TARGETTYPE = LIBRARY BUILD_CONSUMES = geometry_lib SOURCES = Math. c OBJLIBFILES = $(OBJ_PATH). . Geometry$(O)geometry_lib ; sources file for Plot Project TARGETNAME = Plot TARGETYPE = DRIVER SOURCES = Plot. c TARGETLIBS = $(OBJ_PATH). . Geometry$(O)Math. lib Geometry. lib Pass 1 Math. lib Plot. obj Pass 2 Plot. obj + Math. lib
Incorporating Custom Build Steps To run a custom build step at any pass of the build use a combination of NTTARGETFILE# = Target and makefile. inc. Use NTTARGETFILE 0, NTTARGETFILE 1, NTTARGETFILE 2 macros Don’t use NTTARGETFILES NTTARGETFILE# causes makefile. def to include makefile. inc steps are executed after the corresponding pass steps are done Makefile. inc in the same directory as the sources file.
Running Custom Steps at Different Build Passes … TARGETNAME= WUDFEcho. Driver UMDF Echo TARGETTYPE=DYNLINK sample sources INF_NAME = Wudf. Echo. Driver USE_MSVCRT=1 … DLLENTRY= _Dll. Main. CRTStartup DLLDEF=exports. def MSC_WARNING_LEVEL=/W 4 /WX STAMP= stampinf SOURCES= Echo. rc $(OBJ_PATH)$(O)$(INF_NAME). inf: dllsup. cpp $(_INX)$(INF_NAME). inx comsup. cpp driver. cpp copy $(@B). inx $@ device. cpp $(STAMP) -f $@ -a $(_BUILDARCH) -u queue. cpp $(UMDF_VERSION_MAJOR). $(UMDF_VERSION_MIN TARGETLIBS= OR). 0 $(SDK_LIB_PATH)strsafe. lib $(SDK_LIB_PATH)kernel 32. lib $(SDK_LIB_PATH)advapi 32. lib NTTARGETFILE 1=$(OBJ_PATH)$(O)Wudf. Echo. Driver. inf … TARGET_DESTINATION = wudf makefile. inc
Code Optimization By default WDK code optimization is turned on the free build Use checked build when you want to step into the code and avoid all optimizations To turn off the optimization on free build, use MSC_OPTIMIZATION macro in your sources file MSC_OPTIMIZATION =/Od /Oi Use platform specific optimization macros 386_OPTIMIZATION , IA 64_OPTIMIZATION or AMD 64_OPTIMIZATION to override WDK build environment setting for MSC_OPTIMIZATION (Ex. 386_OPTIMIZATION = /Od)
Investigating Compilation Issues Generating a preprocessor file -. pp file • • Where does some type/function prototype/header file come from? • Nmake toaster. pp Generating assembly code – cod file • • Nmake toaster. cod Find out all the macros are defined by the build environment • • Nmake /P
Investigating Link Issues To get verbose information from linker • set LINKER_FLAGS=$(LINKER_FLAGS) /VERBOSE • • How functions get resolved by the linker? • What libs are searched to produce this image? • Which object files or libraries used? • Which linker options are used to product the image? Build log has detailed information
Separate Object and Binplace Roots – New to Win 7 All objects and binaries that are built are stored separately in an object folder Source code could be immutable (stored on an external disk, read only) Easy to clean up the results of the build of object and binaries folders and start fresh. Example: Win. DDK6801. 0 – the WDK installation folder Win. DDK6801. 0. obj. x 86 fre – the object root Win. DDK6801. 0. binaries. x 86 fre – the binaries root
Macros for Binplacing Files – New Binplace. exe utility has been provided in WDK for stripping symbol files, splitting and moving files Win 7 introduces two new macros for binplacing files as part of build TARGET_DESTINATION PASS 2_BINPLACE Can be used to copy additional files that are not produced by build such as INF, CAT file DEST switch (multiple -: DEST possible) Source folder relative to the object root Example: Win. DDK6801. 0. obj. x 86 fresrc. . . Destination folder is relative to the binaries root Example: Win. DDK6801. 0. obj. x 86 fresrc. . .
OACR – Automated Code Review Runs Pre. Fast for Drivers (PFD) asynchronously as part of build Reports status via icon in taskbar Highly configurable via. ini files Snooze option available in taskbar (preferred method). Pass No_OACR flag to setenv. bat to disable
demo Introducing OACR
New Device Technologies Biometrics XPS Print Hypervisor Sensor/PC 3 Windows Vista Display Driver Model (WDDM) updates Wave Real-Time (Wave. RT) Wireless Wide Area Network (WWAN) updates Windows Driver Foundation (WDF) 1. 9 And more…
New Tools in the WDK Computer. Model. ID OACR IRP Concurrency Coverage (proposed) Service Discovery Profile (SDP) Verifier (proposed) CTRPP (proposed)
Sample Changes in the WDK New Samples Technology Wi. Fi, WLAN Wi. Fi, Neterion 10 G NDIS Miniport Networking mini. Spy, null. Filter, pass. Through, scanner, Metadata Manager, ctx, cdo, Encryption, Name Provider, Reparse Points, Cancel. Safe, swap. Buffers File. Systems Wpd. Basic. Hardware. Driver, Wpd. Service. Sample. Driver, Wpd. Multi. Transport. Driver (UMDF) Consumer IR Receiver Sample Driver (smscir) (KMDF) WPD IR
Kit Content Quality Improvement
WDK Content Quality Efforts Add header annotations to WDK headers Run PREfast for Drivers (PFD) on samples Run Static Driver Verifier (SDV) on sample Compile with MSC_WARNING_LEVEL=/W 4 /WX in sources Run Application Verifier against UMDF samples and driver tools Run Driver Verifier against samples Remove obsolete and poor samples
Static Analysis Tools Run Against WDK Samples PREfast for Drivers 112 bug fixes 3110 PFD defects removed from samples Header annotations added to reduce false positives Static Driver Verifier 14 bug fixes Role type annotations added to samples
W 4 Compiler Warnings Found by setting MSC_WARNING_LEVEL=/W 4 /WX in sources files 159 bug fixes 3934 warnings removed from samples Typical errors include uninitialized variables, unreferenced parameters MS 08 -014 – Security vulnerability could have been prevented by /W 4 compilation Many Windows 7 samples will default to /W 4 in the sample sources file
Windows Driver Kit Documentation
WDK Documentation Over two thousand new topics WDK documentation monthly update on MSDN and WHDC Biometrics, XPS, Hypervisor, WDDM, Wave. RT, WWAN, WDF ~1, 000 million page views per month on MSDN Complete technical review of all 802 topics in the Kernel-Mode Driver Architecture Reference ~10, 000 downloads per month on WHDC Windows 7 docs coming at Beta Expanded requirements block for new DDIs OS version IRQL requirements Header/lib “Roadmaps” with basic steps to create drivers Increased visibility WDK Doc Blog http: //blogs. msdn. com/wdkdocs ) (http: //blogs. msdn. com/wdkdocs
Side-by-Side Translation English to Simplified Chinese on http: //translator. live. com
Translation Results and Plans Machine Translation Beta participation totaled 502, 730 visits Pilot ran Oct. 1 st, 2007 through Feb. 28 th, 2008 Windows Driver Kit 3 rd most viewed of 10 in pilot Majority of our customers non-native English speakers Used survey data to prioritize target languages for side-by-side translation Content in some top languages targeted by end of FY 09 Japanese, Chinese (Simplified), Chinese (Traditional), Russian, Korean, Portuguese, French, Spanish
Call To Action Send feedback on Docs, Build Environment, etc. Try Microsoft Automated Code Review – tell us what you think Use the new binplace macros
Additional Resources Contact the WDK Team: WDKPMFT@microsoft. com (WDK PM team) WDKQA@microsoft. com (WDK Test team) DDKSurv 1@microsoft. com (WDK Docs team) Available online: WHDC website: http: //www. microsoft. com/wdk Read the WDK Doc blog at http: //blogs. msdn. com/wdkdocs/default. aspx Download monthly WDK doc refresh from http: //www. microsoft. com/whdc/Dev. Tools/WDKdocs. mspx Driver Development Newsgroup: http: //msdn. microsoft. com/newsgroups/default. aspx? dg=microsof t. public. development. device. drivers&lang=en&cr=US
Questions?
- Slides: 37