Skip to content

Commit

Permalink
[driver] Detect some windows kernel mode libs.
Browse files Browse the repository at this point in the history
  • Loading branch information
egorpugin committed Oct 26, 2024
1 parent 45f8098 commit 538e82a
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions src/sw/driver/compiler/detect_win_sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ struct WinSdkInfo
wk.kit_root = kr;
wk.idir_subversion = v.toString();
wk.ldir_subversion = v.toString();
//wk.idirs.push_back("shared"); // also shared?
wk.idirs.push_back("km/crt");
wk.add(DETECT_ARGS_PASS, settings, v);
}

Expand Down Expand Up @@ -415,6 +417,86 @@ struct WinSdkInfo
wk.bdir_subversion = v.toString();
wk.addTools(DETECT_ARGS_PASS);
}

// wdf
auto add_wdf = [&](auto &&type) {
auto incroot = kr / "Include" / "wdf" / type;
auto libroot = kr / "Lib" / "wdf" / type;
if (!fs::exists(incroot)) {
return;
}
for (auto &&p : fs::directory_iterator{incroot})
{
if (!p.is_directory()) {
continue;
}
sw::Version v{p.path().filename().string()};

for (auto target_arch : { sw::ArchType::x86_64,sw::ArchType::x86,sw::ArchType::arm,sw::ArchType::aarch64 })
{
auto settings2 = settings;
settings2.Arch = target_arch;

auto ts1 = toTargetSettings(settings2);
sw::TargetSettings ts;
ts["os"]["kernel"] = ts1["os"]["kernel"];
ts["os"]["arch"] = ts1["os"]["arch"];

auto libdir = libroot / toStringWindows(target_arch) / (std::to_string(v.getMajor()) + "."s + std::to_string(v.getMinor()));
if (fs::exists(libdir))
{
auto &t = sw::addTarget<sw::PredefinedTarget>(DETECT_ARGS_PASS, sw::LocalPackage(s.getLocalStorage(), sw::PackageId("com.Microsoft.Windows.WDF."s + type, v)), ts);
//t.ts["os"]["version"] = v.toString();

t.public_ts["properties"]["6"]["system_include_directories"].push_back(p.path());
t.public_ts["properties"]["6"]["system_link_directories"].push_back(libdir);
}
}
}
};
add_wdf("kmdf");
add_wdf("umdf");

auto add_versioned_um_system = [&](auto &&type) {
auto incroot = kr / "Include" / v.toString() / "um" / type;
auto libroot = kr / "Lib" / v.toString() / "um";
if (!fs::exists(incroot)) {
return;
}
for (auto &&p : fs::directory_iterator{incroot})
{
if (!p.is_directory()) {
continue;
}
sw::Version v{p.path().filename().string()};

for (auto target_arch : { sw::ArchType::x86_64,sw::ArchType::x86,sw::ArchType::arm,sw::ArchType::aarch64 })
{
auto settings2 = settings;
settings2.Arch = target_arch;

auto ts1 = toTargetSettings(settings2);
sw::TargetSettings ts;
ts["os"]["kernel"] = ts1["os"]["kernel"];
ts["os"]["arch"] = ts1["os"]["arch"];

auto libdir = libroot / toStringWindows(target_arch) / type / (std::to_string(v.getMajor()) + "."s + std::to_string(v.getMinor()));
if (fs::exists(libdir))
{
auto &t = sw::addTarget<sw::PredefinedTarget>(DETECT_ARGS_PASS, sw::LocalPackage(s.getLocalStorage(), sw::PackageId("com.Microsoft.Windows.SDK.um."s + type, v)), ts);
//t.ts["os"]["version"] = v.toString();

t.public_ts["properties"]["6"]["system_include_directories"].push_back(p.path());
t.public_ts["properties"]["6"]["system_link_directories"].push_back(libdir);
}
}
}
};
add_versioned_um_system("iddcx");
add_versioned_um_system("nfc");
add_versioned_um_system("pos");
add_versioned_um_system("sensors");
add_versioned_um_system("ucm");
}

void addKit(DETECT_ARGS, const path &kr, const String &k) const
Expand Down

0 comments on commit 538e82a

Please sign in to comment.