-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
392 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
pub mod runtime; | ||
#[cfg(target_os = "linux")] | ||
mod linux; | ||
|
||
#[cfg(target_os = "linux")] | ||
pub use linux::LinuxRuntime as CatpowderRuntime; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
|
||
[package] | ||
name = "xdp-rs" | ||
version = "1.0.0" | ||
authors = ["Microsoft Corporation"] | ||
edition = "2021" | ||
description = "Rust Bindings for XDP" | ||
homepage = "https://aka.ms/demikernel" | ||
repository = "https://github.com/demikernel/demikernel" | ||
|
||
[dependencies] | ||
cfg-if = "1.0.0" | ||
windows = { version = "0.56.0", features = [ | ||
"Win32_Foundation", | ||
"Win32_Networking_WinSock", | ||
"Win32_Security", | ||
"Win32_Storage_FileSystem", | ||
"Win32_System_IO", | ||
"Win32_System_Pipes", | ||
"Win32_System_Threading", | ||
] } | ||
|
||
[build-dependencies] | ||
anyhow = "1.0.83" | ||
bindgen = "0.69.4" | ||
cc = "1.0.97" | ||
|
||
# Build profile used for releases. | ||
[profile.release] | ||
opt-level = 3 # Enable all compiler optimizations. | ||
debug = false # Do not include any debug info in the binary. | ||
debug-assertions = false # Do not include any debug assertions in the binary. | ||
overflow-checks = false # Do not check for overflows at runtime. | ||
lto = "fat" # Perform link time optimizations across all dependencies (overridden). | ||
panic = "abort" # Terminate the process upon panic (overridden). | ||
incremental = false # Disable incremental compilation. | ||
codegen-units = 1 # Produce a single code generation unit (overridden). | ||
rpath = false # Disable runtime search path. | ||
|
||
# Build profile used for development and debugging. | ||
[profile.dev] | ||
opt-level = 0 # Disable all compiler optimizations. | ||
debug = true # Output full debug info in the binary. | ||
debug-assertions = true # Include debug assertions in the binary. | ||
overflow-checks = true # Check for overflows at runtime. | ||
lto = "off" # Disable link time optimization (overridden). | ||
panic = 'unwind' # Unwind the stack upon panic. | ||
incremental = true # Incremental build. | ||
codegen-units = 256 # Produce multiple code generation units. | ||
rpath = false # Disable runtime search path. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
//============================================================================== | ||
// Extern Linkage | ||
//============================================================================== | ||
|
||
extern crate bindgen; | ||
extern crate cc; | ||
|
||
//============================================================================== | ||
// Imports | ||
//============================================================================== | ||
|
||
use anyhow::Result; | ||
use bindgen::{ | ||
Bindings, | ||
Builder, | ||
}; | ||
use cc::Build; | ||
use std::{ | ||
env, | ||
path::{ | ||
Path, | ||
PathBuf, | ||
}, | ||
}; | ||
|
||
//============================================================================== | ||
// Standalone Functions | ||
//============================================================================== | ||
|
||
static WRAPPER_HEADER_NAME: &str = "wrapper.h"; | ||
static INLINED_C_NAME: &str = "inlined.c"; | ||
static OUT_DIR_VAR: &str = "OUT_DIR"; | ||
static XDP_PATH_VAR: &str = "XDP_PATH"; | ||
static INCLUDE_DIR: &str = "\\include"; | ||
static LIB_DIR: &str = "\\lib"; | ||
static XDP_API_LIB: &str = "xdpapi"; | ||
static SAL_BLOCKLIST_REGEX: &str = r".*SAL.*"; | ||
static TYPE_BLOCKLIST: [&str; 8] = [ | ||
".*OVERLAPPED.*", | ||
"HANDLE", | ||
"HRESULT", | ||
"IN_ADDR", | ||
"IN6_ADDR", | ||
"in_addr.*", | ||
"in6_addr.*", | ||
"_?XDP_INET_ADDR", | ||
]; | ||
static FILE_ALLOWLIST_REGEX: &str = r".*xdp.*"; | ||
|
||
fn main() -> Result<()> { | ||
let out_dir_s: String = env::var(OUT_DIR_VAR).unwrap(); | ||
let out_dir: &Path = Path::new(&out_dir_s); | ||
|
||
let libxdp_path: String = env::var(XDP_PATH_VAR)?; | ||
|
||
let include_path: String = format!("{}{}", &libxdp_path, INCLUDE_DIR); | ||
let lib_path: String = format!("{}{}", &libxdp_path, LIB_DIR); | ||
|
||
println!("include_path: {}", include_path); | ||
println!("lib_path: {}", lib_path); | ||
|
||
// Point cargo to the libraries. | ||
println!("cargo:rustc-link-search={}", lib_path); | ||
println!("cargo:rustc-link-lib=dylib={}", XDP_API_LIB); | ||
|
||
let mut builder = Builder::default(); | ||
for t in TYPE_BLOCKLIST.iter() { | ||
builder = builder.blocklist_type(t); | ||
} | ||
|
||
// Generate bindings for headers. | ||
let bindings: Bindings = builder | ||
.clang_arg(&format!("-I{}", include_path)) | ||
.clang_arg("-mavx") | ||
.header(WRAPPER_HEADER_NAME) | ||
// NB SAL defines still get included despite having no functional impact. | ||
.blocklist_item(SAL_BLOCKLIST_REGEX) | ||
.allowlist_file(FILE_ALLOWLIST_REGEX) | ||
// Allow the inline function wrappers to be generated. | ||
.allowlist_file(format!(".*{}", WRAPPER_HEADER_NAME)) | ||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) | ||
.generate() | ||
.unwrap_or_else(|e| panic!("Failed to generate bindings: {:?}", e)); | ||
let bindings_out: PathBuf = out_dir.join("bindings.rs"); | ||
bindings.write_to_file(bindings_out).expect("Failed to write bindings"); | ||
|
||
// Build inlined functions. | ||
let mut builder: Build = cc::Build::new(); | ||
builder.opt_level(3); | ||
builder.pic(true); | ||
builder.flag("-march=native"); | ||
builder.file(INLINED_C_NAME); | ||
builder.include(include_path); | ||
builder.compile("inlined"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
REM bindgen --blocklist-item ".*SAL.*" --blocklist-file ".*vadefs.h" --blocklist-file ".*excpt.h" --blocklist-file ".*vcruntime.*" --blocklist-file ".*[Ww]indows [Kk]its.*" --verbose wrapper.h -o bindings.rs -- "-IC:\Program Files\xdp\include" | ||
|
||
bindgen --blocklist-item ".*SAL.*" --blocklist-type ".*OVERLAPPED.*" --allowlist-file ".*xdp.*" --verbose wrapper.h -o bindings.rs -- "-IC:\Program Files\xdp\include" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
/* | ||
* This file contains wrappers for inline functions in <xdpapi.h>. | ||
*/ | ||
|
||
#include "wrapper.h" | ||
|
||
HRESULT | ||
_XdpLoadApi( | ||
_In_ UINT32 XdpApiVersion, | ||
_Out_ XDP_LOAD_API_CONTEXT *XdpLoadApiContext, | ||
_Out_ CONST XDP_API_TABLE **XdpApiTable | ||
) | ||
{ | ||
return XdpLoadApi(XdpApiVersion, XdpLoadApiContext, XdpApiTable); | ||
} | ||
|
||
|
||
VOID | ||
_XdpUnloadApi( | ||
_In_ XDP_LOAD_API_CONTEXT XdpLoadApiContext, | ||
_In_ CONST XDP_API_TABLE *XdpApiTable | ||
) | ||
{ | ||
XdpUnloadApi(XdpLoadApiContext, XdpApiTable); | ||
} | ||
|
||
VOID | ||
_XskRingInitialize( | ||
_Out_ XSK_RING *Ring, | ||
_In_ const XSK_RING_INFO *RingInfo | ||
) | ||
{ | ||
XskRingInitialize(Ring, RingInfo); | ||
} | ||
|
||
UINT32 | ||
_XskRingConsumerReserve( | ||
_In_ XSK_RING *Ring, | ||
_In_ UINT32 MaxCount, | ||
_Out_ UINT32 *Index | ||
) | ||
{ | ||
return XskRingConsumerReserve(Ring, MaxCount, Index); | ||
} | ||
|
||
UINT32 | ||
_XskRingProducerReserve( | ||
_In_ XSK_RING *Ring, | ||
_In_ UINT32 MaxCount, | ||
_Out_ UINT32 *Index | ||
) | ||
{ | ||
return XskRingProducerReserve(Ring, MaxCount, Index); | ||
} | ||
|
||
VOID | ||
_XskRingConsumerRelease( | ||
_Inout_ XSK_RING *Ring, | ||
_In_ UINT32 Count | ||
) | ||
{ | ||
XskRingConsumerRelease(Ring, Count); | ||
} | ||
|
||
VOID | ||
_XskRingProducerSubmit( | ||
_Inout_ XSK_RING *Ring, | ||
_In_ UINT32 Count | ||
) | ||
{ | ||
XskRingProducerSubmit(Ring, Count); | ||
} | ||
|
||
VOID * | ||
_XskRingGetElement( | ||
_In_ const XSK_RING *Ring, | ||
_In_ UINT32 Index | ||
) { | ||
return XskRingGetElement(Ring, Index); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nightly-2024-05-02 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#![cfg_attr(feature = "strict", deny(clippy:all))] | ||
#![allow(non_upper_case_globals)] | ||
#![allow(non_camel_case_types)] | ||
#![allow(non_snake_case)] | ||
#![allow(unused)] | ||
|
||
// Redefinition of some types to allow tight integration with windows crate. | ||
extern crate windows; | ||
|
||
use windows::{ | ||
Win32::{ | ||
System::IO::OVERLAPPED, | ||
Foundation::HANDLE, | ||
Networking::WinSock::{ | ||
IN_ADDR, | ||
IN6_ADDR, | ||
} | ||
}, | ||
core::HRESULT, | ||
}; | ||
|
||
// Redefining this type prevents bindgen from having to wrap the whole union. Since this is a | ||
// high-use type, prioritize syntax over maintainability. | ||
#[repr(C)] | ||
#[derive(Copy, Clone)] | ||
pub union _XDP_INET_ADDR { | ||
pub Ipv4: IN_ADDR, | ||
pub Ipv6: IN6_ADDR, | ||
} | ||
pub type XDP_INET_ADDR = _XDP_INET_ADDR; | ||
|
||
include!(concat!(env!("OUT_DIR"), "/bindings.rs")); |
Oops, something went wrong.