Skip to content

Commit

Permalink
Merge pull request #6 from tylerfanelli/gh
Browse files Browse the repository at this point in the history
github: CI tests and CODEOWNERS for reviews
Signed-off-by: German Maglione <[email protected]>
  • Loading branch information
slp authored and germag committed May 23, 2024
2 parents cbb5742 + 112dcdf commit ea02118
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .github/workflows/code_quality-aarch64-darwin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Code Quality (rustfmt and clippy)
on: [pull_request, create]

jobs:
build:
if: github.event_name == 'pull_request'
name: Code Quality (clippy, rustfmt)
runs-on: fedora-latest
strategy:
matrix:
rust:
- stable
target:
- aarch64-apple-darwin
steps:
- name: Code checkout
uses: actions/checkout@v2
- name: Install Rust toolchain (${{ matrix.rust }})
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
override: true
components: rustfmt, clippy

- name: Formatting (rustfmt)
run: cargo fmt -- --check

- name: Clippy (default features)
run: cargo clippy --target aarch64-apple-darwin -- -D warnings
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @tylerfanelli @slp
4 changes: 4 additions & 0 deletions src/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ pub struct Args {
/// GUI option for compatibility with vfkit (ignored).
#[arg(long, default_value_t = false)]
pub gui: bool,

/// SMBIOS OEM String
#[arg(long = "oem-string")]
pub oem_strings: Option<Vec<String>>,
}

/// Parse a string into a vector of substrings, all of which are separated by commas.
Expand Down
32 changes: 31 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ use crate::{
virtio::KrunContextSet,
};

use std::ffi::{c_char, CString};
use std::{convert::TryFrom, thread};

use anyhow::anyhow;
use anyhow::{anyhow, Context};

#[link(name = "krun-efi")]
extern "C" {
fn krun_create_ctx() -> i32;
fn krun_set_gpu_options(ctx_id: u32, virgl_flags: u32) -> i32;
fn krun_set_vm_config(ctx_id: u32, num_vcpus: u8, ram_mib: u32) -> i32;
fn krun_set_smbios_oem_strings(ctx_id: u32, oem_strings: *const *const c_char) -> i32;
fn krun_start_enter(ctx_id: u32) -> i32;
}

Expand Down Expand Up @@ -67,6 +69,8 @@ impl TryFrom<Args> for KrunContext {
unsafe { device.krun_ctx_set(id)? }
}

set_smbios_oem_strings(id, &args.oem_strings)?;

Ok(Self { id, args })
}
}
Expand All @@ -89,3 +93,29 @@ impl KrunContext {
Ok(())
}
}

fn set_smbios_oem_strings(
ctx_id: u32,
oem_strings: &Option<Vec<String>>,
) -> Result<(), anyhow::Error> {
let Some(oem_strings) = oem_strings else {
return Ok(());
};

if oem_strings.len() > u8::MAX as usize {
return Err(anyhow!("invalid number of SMBIOS OEM strings"));
}

let mut cstr_vec = Vec::with_capacity(oem_strings.len());
for s in oem_strings {
let cs = CString::new(s.as_str()).context("invalid SMBIOS OEM string")?;
cstr_vec.push(cs);
}
let ptr_vec: Vec<_> = cstr_vec.iter().map(|s| s.as_ptr()).collect();

let ret = unsafe { krun_set_smbios_oem_strings(ctx_id, ptr_vec.as_ptr()) };
if ret < 0 {
return Err(anyhow!("unable to set SMBIOS OEM Strings"));
}
Ok(())
}

0 comments on commit ea02118

Please sign in to comment.