diff --git a/kernel/src/drivers/mod.rs b/kernel/src/drivers/mod.rs index 799fd80..da64652 100644 --- a/kernel/src/drivers/mod.rs +++ b/kernel/src/drivers/mod.rs @@ -2,7 +2,6 @@ use alloc::prelude::*; use alloc::sync::Arc; use lazy_static::lazy_static; -use smoltcp::socket::SocketSet; use smoltcp::wire::{EthernetAddress, Ipv4Address}; use spin::RwLock; diff --git a/kernel/src/drivers/net/e1000.rs b/kernel/src/drivers/net/e1000.rs index 3d52bd7..743070b 100644 --- a/kernel/src/drivers/net/e1000.rs +++ b/kernel/src/drivers/net/e1000.rs @@ -25,7 +25,6 @@ use volatile::Volatile; use crate::memory::active_table; use crate::net::SOCKETS; use crate::sync::SpinNoIrqLock as Mutex; -use crate::sync::{MutexGuard, SpinNoIrq}; use crate::HEAP_ALLOCATOR; use super::super::{DeviceType, Driver, DRIVERS, NET_DRIVERS, SOCKET_ACTIVITY}; diff --git a/kernel/src/drivers/net/ixgbe.rs b/kernel/src/drivers/net/ixgbe.rs index 8adfcb6..351187c 100644 --- a/kernel/src/drivers/net/ixgbe.rs +++ b/kernel/src/drivers/net/ixgbe.rs @@ -1,15 +1,10 @@ //! Intel 10Gb Network Adapter 82599 i.e. ixgbe network driver //! Datasheet: https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/82599-10-gbe-controller-datasheet.pdf -use alloc::alloc::{GlobalAlloc, Layout}; use alloc::prelude::*; use alloc::sync::Arc; -use core::mem::size_of; -use core::slice; -use core::sync::atomic::{fence, Ordering}; use alloc::collections::BTreeMap; -use bitflags::*; use isomorphic_drivers::net::ethernet::intel::ixgbe; use log::*; use rcore_memory::paging::PageTable; diff --git a/kernel/src/process/structs.rs b/kernel/src/process/structs.rs index 30cd633..c3f06aa 100644 --- a/kernel/src/process/structs.rs +++ b/kernel/src/process/structs.rs @@ -6,10 +6,11 @@ use spin::{Mutex, RwLock}; use xmas_elf::{ElfFile, header, program::{Flags, Type}}; use rcore_memory::PAGE_SIZE; use rcore_thread::Tid; +use core::str; use crate::arch::interrupt::{Context, TrapFrame}; use crate::memory::{ByFrame, GlobalFrameAlloc, KernelStack, MemoryAttr, MemorySet}; -use crate::fs::{FileHandle, OpenOptions}; +use crate::fs::{FileHandle, OpenOptions, INodeExt}; use crate::sync::Condvar; use crate::net::{SocketWrapper, SOCKETS}; @@ -198,6 +199,33 @@ impl Thread { _ => panic!("ELF is not executable or shared object"), } + if let Some(interp) = elf.program_iter().filter(|ph| ph.get_type() == Ok(Type::Interp)).next() { + let offset = interp.offset() as usize; + let size = interp.file_size() as usize - 1; // skip last '\0' + if offset + size < data.len() { + if let Ok(loader_path) = str::from_utf8(&data[offset..(offset+size)]) { + if let Ok(inode) = crate::fs::ROOT_INODE.lookup(&loader_path[1..]) { + if let Ok(buf) = inode.read_as_vec() { + debug!("using loader {}", &loader_path); + // Elf loader should not have INTERP + // No infinite loop + let mut new_args: Vec<&str> = args.collect(); + new_args.insert(0, loader_path); + return Thread::new_user(buf.as_slice(), new_args.into_iter()); + } else { + warn!("loader specified as {} but failed to read", &loader_path); + } + } else { + warn!("loader specified as {} but not found", &loader_path); + } + } else { + warn!("loader specified but not found"); + } + } else { + warn!("loader specified but invalid"); + } + } + // Make page table let (mut vm, entry_addr) = memory_set_from(&elf);