diff options
| author | ruki <[email protected]> | 2018-05-06 22:15:31 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-05-06 22:15:31 +0800 |
| commit | 19897786b3cfef22fe20275af7e72ae6826a75f5 (patch) | |
| tree | 549a2f1641a8c7f98fc90239a933652961001ba1 | |
| parent | 3567313cb859aa88e71ef9aa84e484f09fbccce8 (diff) | |
compile kmdf driver and binary
| -rw-r--r-- | tests/projects/wdk/kmdf/ioctl/public.h (renamed from tests/projects/wdk/kmdf/ioctl/driver/public.h) | 0 | ||||
| -rw-r--r-- | tests/projects/wdk/kmdf/ioctl/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/wdk/load.lua | 142 | ||||
| -rw-r--r-- | xmake/rules/wdk/xmake.lua | 8 |
4 files changed, 93 insertions, 63 deletions
diff --git a/tests/projects/wdk/kmdf/ioctl/driver/public.h b/tests/projects/wdk/kmdf/ioctl/public.h index 02e24be2e..02e24be2e 100644 --- a/tests/projects/wdk/kmdf/ioctl/driver/public.h +++ b/tests/projects/wdk/kmdf/ioctl/public.h diff --git a/tests/projects/wdk/kmdf/ioctl/xmake.lua b/tests/projects/wdk/kmdf/ioctl/xmake.lua index 6fbca5543..0c85a258c 100644 --- a/tests/projects/wdk/kmdf/ioctl/xmake.lua +++ b/tests/projects/wdk/kmdf/ioctl/xmake.lua @@ -2,6 +2,9 @@ -- add modes: debug and release add_rules("mode.debug", "mode.release") +-- add include directories +add_includedirs(".") + -- add target target("nonpnp") @@ -14,6 +17,9 @@ target("nonpnp") -- add files add_files("driver/*.c", {rule = "wdk.tracewpp"}) + add_links("BufferOverflowFastFailK", "ntoskrnl", "hal", "wmilib", "WdfLdr", "WdfDriverEntry", "ntstrsafe", "wdmsec") + add_ldflags("-ENTRY:FxDriverEntry", "-SUBSYSTEM:NATIVE,10.00", "-Driver", "-kernel", {force = true}) + -- add target target("app") diff --git a/xmake/rules/wdk/load.lua b/xmake/rules/wdk/load.lua index ae58a7121..dd9344c6b 100644 --- a/xmake/rules/wdk/load.lua +++ b/xmake/rules/wdk/load.lua @@ -24,101 +24,125 @@ -- imports import("core.project.config") -import("lib.detect.find_path") --- load for umdf -function _load_for_umdf(target, wdk, arch, kind) +-- load for umdf driver +function umdf_driver(target) + + -- get wdk + local wdk = target:data("wdk") + + -- set kind + target:set("kind", "shared") -- add defines - target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL") + local arch = config.arch() + local umdfver = wdk.umdfver:split('%.') if arch == "x64" then target:add("defines", "_WIN64", "_AMD64_", "AMD64") end + target:add("defines", "UMDF_VERSION_MAJOR=" .. umdfver[1], "UMDF_VERSION_MINOR=" .. umdfver[2], "UMDF_USING_NTSTATUS") + target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL") - -- add link and include directories - target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "um", arch)) + -- add include directories target:add("includedirs", path.join(wdk.includedir, wdk.sdkver, "um")) + target:add("includedirs", path.join(wdk.includedir, "wdf", "umdf", wdk.umdfver)) - -- add link and include directories for umdf driver - if kind == "shared" then + -- add link directories + target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "um", arch)) + target:add("linkdirs", path.join(wdk.libdir, "wdf", "umdf", arch, wdk.umdfver)) - -- check umdf version - assert(wdk.umdfver, "umdf version not found!") + -- add links + target:add("links", "WdfDriverStubUm", "ntdll", "OneCoreUAP", "mincore", "ucrt") + target:add("ldflags", "-NODEFAULTLIB:kernel32.lib", "-NODEFAULTLIB:user32.lib", "-NODEFAULTLIB:libucrt.lib", {force = true}) +end - -- add include directories - target:add("includedirs", path.join(wdk.includedir, "wdf", "umdf", wdk.umdfver)) +-- load for umdf binary +function umdf_binary(target) - -- add link directories - target:add("linkdirs", path.join(wdk.libdir, "wdf", "umdf", arch, wdk.umdfver)) + -- get wdk + local wdk = target:data("wdk") - -- add links - target:add("links", "WdfDriverStubUm") + -- set kind + target:set("kind", "binary") - -- add defines - local umdfver = wdk.umdfver:split('%.') - target:add("defines", "UMDF_VERSION_MAJOR=" .. umdfver[1], "UMDF_VERSION_MINOR=" .. umdfver[2], "UMDF_USING_NTSTATUS") + -- add defines + local arch = config.arch() + if arch == "x64" then + target:add("defines", "_WIN64", "_AMD64_", "AMD64") end + target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL") + + -- add include directories + target:add("includedirs", path.join(wdk.includedir, wdk.sdkver, "um")) + target:add("includedirs", path.join(wdk.includedir, "wdf", "umdf", wdk.umdfver)) + + -- add link directories + target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "um", arch)) + target:add("linkdirs", path.join(wdk.libdir, "wdf", "umdf", arch, wdk.umdfver)) + + -- add links target:add("links", "ntdll", "OneCoreUAP", "mincore", "ucrt") target:add("ldflags", "-NODEFAULTLIB:kernel32.lib", "-NODEFAULTLIB:user32.lib", "-NODEFAULTLIB:libucrt.lib", {force = true}) end --- load for kmdf -function _load_for_kmdf(target, wdk, arch, kind) +-- load for kmdf driver +function kmdf_driver(target) + + -- get wdk + local wdk = target:data("wdk") + + -- set kind + target:set("kind", "binary") -- add defines - target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL") + local arch = config.arch() + local kmdfver = wdk.kmdfver:split('%.') if arch == "x64" then target:add("defines", "_WIN64", "_AMD64_", "AMD64") end + target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL") + target:add("defines", "KMDF_VERSION_MAJOR=" .. kmdfver[1], "KMDF_VERSION_MINOR=" .. kmdfver[2], "KMDF_USING_NTSTATUS") - -- add link and include directories - target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "km", arch)) + -- add include directories target:add("includedirs", path.join(wdk.includedir, wdk.sdkver, "km")) + target:add("includedirs", path.join(wdk.includedir, "wdf", "kmdf", wdk.kmdfver)) - -- add link and include directories for kmdf driver - if kind == "shared" then - - -- check kmdf version - assert(wdk.kmdfver, "kmdf version not found!") - - -- add include directories - target:add("includedirs", path.join(wdk.includedir, "wdf", "kmdf", wdk.kmdfver)) - - -- add link directories - target:add("linkdirs", path.join(wdk.libdir, "wdf", "kmdf", arch, wdk.kmdfver)) + -- add link directories + target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "km", arch)) + target:add("linkdirs", path.join(wdk.libdir, "wdf", "kmdf", arch, wdk.kmdfver)) - -- add defines - local kmdfver = wdk.kmdfver:split('%.') - target:add("defines", "KMDF_VERSION_MAJOR=" .. kmdfver[1], "KMDF_VERSION_MINOR=" .. kmdfver[2], "KMDF_USING_NTSTATUS") - end - target:add("links", "ntdll", "OneCoreUAP", "mincore", "ucrt") - target:add("ldflags", "-NODEFAULTLIB:kernel32.lib", "-NODEFAULTLIB:user32.lib", "-NODEFAULTLIB:libucrt.lib", {force = true}) + -- add links + target:add("links", "BufferOverflowFastFailK", "ntoskrnl", "hal", "wmilib", "WdfLdr", "WdfDriverEntry", "ntstrsafe", "wdmsec") + target:add("ldflags", "-entry:FxDriverEntry", "-subsystem:native,10.00", "-driver", "-kernel", {force = true}) end --- the main entry -function main(target, opt) - - -- init options - opt = opt or {} +-- load for kmdf binary +function kmdf_binary(target) -- get wdk local wdk = target:data("wdk") - -- get arch - local arch = config.arch() - -- set kind - if opt.kind then - target:set("kind", opt.kind) - end + target:set("kind", "binary") - -- load for umdf - if opt.mode == "umdf" then - _load_for_umdf(target, wdk, arch, opt.kind) + -- add defines + local arch = config.arch() + local kmdfver = wdk.kmdfver:split('%.') + if arch == "x64" then + target:add("defines", "_WIN64", "_AMD64_", "AMD64") end + target:add("defines", "WIN32_LEAN_AND_MEAN=1", "_WIN32_WINNT=0x0A00", "WINVER=0x0A00", "WINNT=1", "NTDDI_VERSION=0x0A000004", "_WINDLL") + target:add("defines", "KMDF_VERSION_MAJOR=" .. kmdfver[1], "KMDF_VERSION_MINOR=" .. kmdfver[2]) - -- load for kmdf - if opt.mode == "kmdf" then - _load_for_kmdf(target, wdk, arch, opt.kind) - end + -- add include directories + target:add("includedirs", path.join(wdk.includedir, wdk.sdkver, "km")) + target:add("includedirs", path.join(wdk.includedir, "wdf", "kmdf", wdk.kmdfver)) + + -- add link directories + target:add("linkdirs", path.join(wdk.libdir, wdk.sdkver, "km", arch)) + target:add("linkdirs", path.join(wdk.libdir, "wdf", "kmdf", arch, wdk.kmdfver)) + + -- add links + target:add("links", "kernel32", "user32", "gdi32", "winspool", "comdlg32") + target:add("links", "advapi32", "shell32", "ole32", "oleaut32", "uuid", "odbc32", "odbccp32", "setupapi") end diff --git a/xmake/rules/wdk/xmake.lua b/xmake/rules/wdk/xmake.lua index a2a57de52..7ad2b137f 100644 --- a/xmake/rules/wdk/xmake.lua +++ b/xmake/rules/wdk/xmake.lua @@ -163,7 +163,7 @@ rule("wdk.umdf.driver") -- on load on_load(function (target) - import("load")(target, {kind = "shared", mode = "umdf"}) + import("load").umdf_driver(target) end) -- define rule: umdf binary @@ -174,7 +174,7 @@ rule("wdk.umdf.binary") -- on load on_load(function (target) - import("load")(target, {kind = "binary", mode = "umdf"}) + import("load").umdf_binary(target) end) -- define rule: kmdf driver @@ -185,7 +185,7 @@ rule("wdk.kmdf.driver") -- on load on_load(function (target) - import("load")(target, {kind = "shared", mode = "kmdf"}) + import("load").kmdf_driver(target) end) -- define rule: kmdf binary @@ -196,5 +196,5 @@ rule("wdk.kmdf.binary") -- on load on_load(function (target) - import("load")(target, {kind = "binary", mode = "kmdf"}) + import("load").kmdf_binary(target) end) |
