mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-02 21:00:55 +00:00
chore(xenplatform): elf loader should async load the file (#197)
* fix(build): remove unused environment variables * chore(xenplatform): elf loader should async load the file
This commit is contained in:
parent
6c3fc54688
commit
9a45d754bf
6
.github/workflows/nightly.yml
vendored
6
.github/workflows/nightly.yml
vendored
@ -27,16 +27,12 @@ jobs:
|
|||||||
targets: "${{ matrix.arch }}-unknown-linux-gnu,${{ matrix.arch }}-unknown-linux-musl"
|
targets: "${{ matrix.arch }}-unknown-linux-gnu,${{ matrix.arch }}-unknown-linux-musl"
|
||||||
- run: ./hack/ci/install-linux-deps.sh
|
- run: ./hack/ci/install-linux-deps.sh
|
||||||
- run: ./hack/dist/bundle.sh
|
- run: ./hack/dist/bundle.sh
|
||||||
env:
|
|
||||||
KRATA_KERNEL_BUILD_JOBS: "5"
|
|
||||||
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
|
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
|
||||||
with:
|
with:
|
||||||
name: krata-bundle-systemd-${{ matrix.arch }}
|
name: krata-bundle-systemd-${{ matrix.arch }}
|
||||||
path: "target/dist/bundle-systemd-${{ matrix.arch }}.tgz"
|
path: "target/dist/bundle-systemd-${{ matrix.arch }}.tgz"
|
||||||
compression-level: 0
|
compression-level: 0
|
||||||
- run: ./hack/dist/deb.sh
|
- run: ./hack/dist/deb.sh
|
||||||
env:
|
|
||||||
KRATA_KERNEL_BUILD_SKIP: "1"
|
|
||||||
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
|
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
|
||||||
with:
|
with:
|
||||||
name: krata-debian-${{ matrix.arch }}
|
name: krata-debian-${{ matrix.arch }}
|
||||||
@ -51,8 +47,6 @@ jobs:
|
|||||||
path: "target/dist/*_${{ matrix.arch }}.apk"
|
path: "target/dist/*_${{ matrix.arch }}.apk"
|
||||||
compression-level: 0
|
compression-level: 0
|
||||||
- run: ./hack/os/build.sh
|
- run: ./hack/os/build.sh
|
||||||
env:
|
|
||||||
KRATA_KERNEL_BUILD_SKIP: "1"
|
|
||||||
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
|
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
|
||||||
with:
|
with:
|
||||||
name: krata-os-${{ matrix.arch }}
|
name: krata-os-${{ matrix.arch }}
|
||||||
|
@ -16,10 +16,12 @@ use slice_copy::copy;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::{BufReader, Read};
|
use std::io::{BufReader, Read};
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
|
use std::sync::Arc;
|
||||||
use xz2::bufread::XzDecoder;
|
use xz2::bufread::XzDecoder;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct ElfImageLoader {
|
pub struct ElfImageLoader {
|
||||||
data: Vec<u8>,
|
data: Arc<Vec<u8>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn xen_note_value_as_u64(endian: AnyEndian, value: &[u8]) -> Option<u64> {
|
fn xen_note_value_as_u64(endian: AnyEndian, value: &[u8]) -> Option<u64> {
|
||||||
@ -59,7 +61,9 @@ fn xen_note_value_as_u64(endian: AnyEndian, value: &[u8]) -> Option<u64> {
|
|||||||
|
|
||||||
impl ElfImageLoader {
|
impl ElfImageLoader {
|
||||||
pub fn new(data: Vec<u8>) -> ElfImageLoader {
|
pub fn new(data: Vec<u8>) -> ElfImageLoader {
|
||||||
ElfImageLoader { data }
|
ElfImageLoader {
|
||||||
|
data: Arc::new(data),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_gz(data: &[u8]) -> Result<ElfImageLoader> {
|
pub fn load_gz(data: &[u8]) -> Result<ElfImageLoader> {
|
||||||
@ -122,15 +126,8 @@ impl ElfImageLoader {
|
|||||||
|
|
||||||
Err(Error::ElfCompressionUnknown)
|
Err(Error::ElfCompressionUnknown)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
struct ElfNoteValue {
|
fn parse_sync(&self, hvm: bool) -> Result<BootImageInfo> {
|
||||||
value: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl BootImageLoader for ElfImageLoader {
|
|
||||||
async fn parse(&self, hvm: bool) -> Result<BootImageInfo> {
|
|
||||||
let elf = ElfBytes::<AnyEndian>::minimal_parse(self.data.as_slice())?;
|
let elf = ElfBytes::<AnyEndian>::minimal_parse(self.data.as_slice())?;
|
||||||
let headers = elf.section_headers().ok_or(Error::ElfInvalidImage)?;
|
let headers = elf.section_headers().ok_or(Error::ElfInvalidImage)?;
|
||||||
let mut linux_notes: HashMap<u64, Vec<u8>> = HashMap::new();
|
let mut linux_notes: HashMap<u64, Vec<u8>> = HashMap::new();
|
||||||
@ -250,6 +247,18 @@ impl BootImageLoader for ElfImageLoader {
|
|||||||
};
|
};
|
||||||
Ok(image_info)
|
Ok(image_info)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ElfNoteValue {
|
||||||
|
value: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl BootImageLoader for ElfImageLoader {
|
||||||
|
async fn parse(&self, hvm: bool) -> Result<BootImageInfo> {
|
||||||
|
let loader = self.clone();
|
||||||
|
tokio::task::spawn_blocking(move || loader.parse_sync(hvm)).await?
|
||||||
|
}
|
||||||
|
|
||||||
async fn load(&self, image_info: &BootImageInfo, dst: &mut [u8]) -> Result<()> {
|
async fn load(&self, image_info: &BootImageInfo, dst: &mut [u8]) -> Result<()> {
|
||||||
let elf = ElfBytes::<AnyEndian>::minimal_parse(self.data.as_slice())?;
|
let elf = ElfBytes::<AnyEndian>::minimal_parse(self.data.as_slice())?;
|
||||||
|
@ -38,6 +38,8 @@ pub enum Error {
|
|||||||
GenericError(String),
|
GenericError(String),
|
||||||
#[error("failed to parse int: {0}")]
|
#[error("failed to parse int: {0}")]
|
||||||
ParseIntError(#[from] std::num::ParseIntError),
|
ParseIntError(#[from] std::num::ParseIntError),
|
||||||
|
#[error("failed to join async task: {0}")]
|
||||||
|
AsyncJoinError(#[from] tokio::task::JoinError),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
5
hack/dist/bundle.sh
vendored
5
hack/dist/bundle.sh
vendored
@ -4,11 +4,6 @@ set -e
|
|||||||
# shellcheck source-path=SCRIPTDIR source=common.sh
|
# shellcheck source-path=SCRIPTDIR source=common.sh
|
||||||
. "$(dirname "${0}")/common.sh"
|
. "$(dirname "${0}")/common.sh"
|
||||||
|
|
||||||
if [ -z "${KRATA_KERNEL_BUILD_JOBS}" ]
|
|
||||||
then
|
|
||||||
KRATA_KERNEL_BUILD_JOBS="2"
|
|
||||||
fi
|
|
||||||
|
|
||||||
TARGET_ARCH="$("${KRATA_DIR}/hack/build/arch.sh")"
|
TARGET_ARCH="$("${KRATA_DIR}/hack/build/arch.sh")"
|
||||||
BUNDLE_TAR="${OUTPUT_DIR}/bundle-systemd-${TARGET_ARCH}.tgz"
|
BUNDLE_TAR="${OUTPUT_DIR}/bundle-systemd-${TARGET_ARCH}.tgz"
|
||||||
rm -f "${BUNDLE_TAR}"
|
rm -f "${BUNDLE_TAR}"
|
||||||
|
@ -7,7 +7,7 @@ remove_service_if_exists() {
|
|||||||
UNIT_PATH="$(systemctl show -P FragmentPath "${1}")"
|
UNIT_PATH="$(systemctl show -P FragmentPath "${1}")"
|
||||||
if [ -f "${UNIT_PATH}" ]
|
if [ -f "${UNIT_PATH}" ]
|
||||||
then
|
then
|
||||||
echo "[WARN] disabling removing systemd unit ${UNIT_PATH}" > /dev/stderr
|
echo "[WARN] disabling and removing systemd unit ${UNIT_PATH}" > /dev/stderr
|
||||||
systemctl disable --now "${1}" || true
|
systemctl disable --now "${1}" || true
|
||||||
rm "${UNIT_PATH}"
|
rm "${UNIT_PATH}"
|
||||||
fi
|
fi
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/sbin/openrc-run
|
#!/sbin/openrc-run
|
||||||
description="Krata Control Daemon"
|
description="Krata Isolation Engine"
|
||||||
command="/usr/libexec/kratad"
|
command="/usr/libexec/kratad"
|
||||||
supervisor="supervise-daemon"
|
supervisor="supervise-daemon"
|
||||||
output_log="/var/log/kratad.log"
|
output_log="/var/log/kratad.log"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Krata Control Daemon
|
Description=Krata Isolation Engine
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Krata Networking Daemon
|
Description=Krata Networking Engine
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Wants=kratad.service
|
Wants=kratad.service
|
||||||
|
Loading…
Reference in New Issue
Block a user