Skip to content

Commit

Permalink
feat(ports): add python
Browse files Browse the repository at this point in the history
Signed-off-by: Anhad Singh <[email protected]>
  • Loading branch information
Andy-Python-Programmer committed Mar 29, 2024
1 parent 0ca27da commit 93a215b
Show file tree
Hide file tree
Showing 23 changed files with 354 additions and 106 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ KERNEL_TARGET := src/target/x86_64-unknown-none/release/aero_kernel
clean:
rm -rf src/target

.PHONY: check
check:
cd src && cargo check

$(KERNEL_TARGET): $(shell find $(SOURCE_DIR) -type f -not -path '$(SOURCE_DIR)/target/*')
cd src && cargo build --package aero_kernel --release
./build-support/mkiso.sh
Expand Down
File renamed without changes.
54 changes: 54 additions & 0 deletions patches/python/jinx-working-patch.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
diff --git python-clean/configure.ac python-workdir/configure.ac
index cd69f0e..74fc416 100644
--- python-clean/configure.ac
+++ python-workdir/configure.ac
@@ -553,6 +553,9 @@ then
*-*-cygwin*)
ac_sys_system=Cygwin
;;
+ *-*-aero*)
+ ac_sys_system=Aero
+ ;;
*-*-vxworks*)
ac_sys_system=VxWorks
;;
@@ -619,6 +622,9 @@ if test "$cross_compiling" = yes; then
*-*-vxworks*)
_host_cpu=$host_cpu
;;
+ *-*-aero*)
+ _host_cpu=$host_cpu
+ ;;
wasm32-*-* | wasm64-*-*)
_host_cpu=$host_cpu
;;
@@ -3216,6 +3222,9 @@ then
CYGWIN*)
LDSHARED="gcc -shared -Wl,--enable-auto-image-base"
LDCXXSHARED="g++ -shared -Wl,--enable-auto-image-base";;
+ Aero*)
+ LDSHARED='$(CC) -shared'
+ LDCXXSHARED='$(CXX) - shared';;
*) LDSHARED="ld";;
esac
fi
@@ -3268,7 +3277,9 @@ then
else CCSHARED="-Kpic -belf"
fi;;
VxWorks*)
- CCSHARED="-fpic -D__SO_PICABILINUX__ -ftls-model=global-dynamic"
+ CCSHARED="-fpic -D__SO_PICABILINUX__ -ftls-model=global-dynamic";;
+ Aero*)
+ CCSHARED="-fPIC";;
esac
fi
AC_MSG_RESULT([$CCSHARED])
@@ -3338,6 +3349,8 @@ then
LINKFORSHARED='-Wl,-E -N 2048K';;
VxWorks*)
LINKFORSHARED='-Wl,-export-dynamic';;
+ Aero*)
+ LINKFORSHARED='-export-dynamic';;
esac
fi
AC_MSG_RESULT([$LINKFORSHARED])
46 changes: 46 additions & 0 deletions recipes/python
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name=python
version=3.13.0
tarball_url="https://www.python.org/ftp/python/${version}/Python-${version}a1.tar.xz"
tarball_blake2b="62612d22ce652f4b1d7ce93aa30bd5814dbf271dbe98e321b99d003d7da8f74798e55f556db75fc39b676295c1d1f7b31919c444fe3c667d2fbd2ea16799a211"
source_deps="autoconf-archive"
source_hostdeps="automake autoconf libtool pkg-config"
hostdeps="gcc autoconf automake libtool pkg-config"
deps="core-libs libexpat"

regenerate() {
autotools_recursive_regen
}

build() {
mkdir -p ./build
cd ./build

# XXX make this a host dep
if ! [ -f built ]; then
${source_dir}/configure

make -j${parallelism}
touch built
fi

cd -

CONFIG_SITE=${base_dir}/build-support/python/python-config-site autotools_configure \
--with-system-ffi \
--with-system-expat \
--disable-ipv6 \
--without-ensurepip \
--host=x86_64-aero \
--build=x86_64-linux-gnu \
--with-build-python="$(pwd -P)/build/python" \
--with-pkg-config=yes

make -j${parallelism}
}

package() {
DESTDIR="${dest_dir}" make install
ln -sv python3 "${dest_dir}${prefix}/bin/python"
post_package_strip
}

3 changes: 0 additions & 3 deletions src/aero_kernel/src/arch/x86_64/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@
use alloc::alloc::alloc_zeroed;

use aero_syscall::{MMapFlags, MMapProt};
use alloc::boxed::Box;
use alloc::vec::Vec;
use raw_cpuid::CpuId;

use core::alloc::Layout;
use core::ptr::Unique;

use crate::arch::controlregs::MxCsr;
use crate::arch::interrupts::InterruptErrorStack;
use crate::fs::cache::DirCacheItem;
use crate::mem::alloc_boxed_buffer;
use crate::mem::paging::*;
use crate::syscall::ExecArgs;
use crate::userland::vm::Vm;
Expand Down
2 changes: 1 addition & 1 deletion src/aero_kernel/src/arch/x86_64/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn pit_irq_handler(_stack: &mut InterruptStack) {

if value % PIT_FREQUENCY_HZ == 0 {
UPTIME_SEC.fetch_add(1, Ordering::Relaxed); // Increment uptime seconds
crate::syscall::check_timers();
crate::syscall::time::check_timers();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/aero_kernel/src/drivers/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl INodeInterface for Mouse {
assert_eq!(buffer.len(), size);

unsafe {
*(buffer.as_mut_ptr() as *mut Packet) = packet;
*(buffer.as_mut_ptr().cast::<Packet>()) = packet;
}

Ok(size)
Expand Down
2 changes: 1 addition & 1 deletion src/aero_kernel/src/fs/devfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl INodeInterface for DevFb {
count = buffer.len() - ((offset + buffer.len()) - fb.len());
}

let raw = buffer.as_ptr() as *const u32;
let raw = buffer.as_ptr().cast::<u32>();
let src = unsafe { core::slice::from_raw_parts(raw, count) };

fb[offset..offset + count].copy_from_slice(src);
Expand Down
4 changes: 2 additions & 2 deletions src/aero_kernel/src/fs/eventfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl INodeInterface for EventFd {

// SAFETY: We have above verified that it is safe to dereference
// the value.
let value = unsafe { &mut *(buffer.as_mut_ptr() as *mut u64) };
let value = unsafe { &mut *(buffer.as_mut_ptr().cast::<u64>()) };
let mut count = self.wq.block_on(&self.count, |e| **e != 0)?;

*value = *count;
Expand All @@ -75,7 +75,7 @@ impl INodeInterface for EventFd {
assert!(buffer.len() >= chunk_size);

// TODO: use bytemuck to remove the unsafe.
let target = unsafe { *(buffer.as_ptr() as *const u64) };
let target = unsafe { *(buffer.as_ptr().cast::<u64>()) };

if target == u64::MAX {
return Err(FileSystemError::NotSupported);
Expand Down
3 changes: 2 additions & 1 deletion src/aero_kernel/src/fs/ext2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use self::group_desc::GroupDescriptors;
use super::block::{self, BlockDevice, CachedAccess};

use super::cache::{DirCacheItem, INodeCacheItem};
use super::path::PathBuf;
use super::{cache, FileSystemError};

use super::inode::{DirEntry, INodeInterface, Metadata, PollFlags, PollTable};
Expand Down Expand Up @@ -518,7 +519,7 @@ impl INodeInterface for INode {
self.make_inode(name, FileType::Socket, Some(inode))
}

fn resolve_link(&self) -> super::Result<String> {
fn resolve_link(&self) -> super::Result<PathBuf> {
if !self.metadata()?.is_symlink() {
return Err(FileSystemError::NotSupported);
}
Expand Down
2 changes: 1 addition & 1 deletion src/aero_kernel/src/fs/file_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl FileHandle {
let file_type = entry.inode().metadata()?.file_type();
let file_type: aero_syscall::SysFileType = file_type.into();

let sysd = unsafe { &mut *(buffer.as_mut_ptr() as *mut SysDirEntry) };
let sysd = unsafe { &mut *(buffer.as_mut_ptr().cast::<SysDirEntry>()) };

sysd.inode = entry.inode().metadata()?.id();
sysd.offset = reclen;
Expand Down
3 changes: 2 additions & 1 deletion src/aero_kernel/src/fs/inode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::utils::sync::{BMutex, Mutex, WaitQueue};
use super::cache::{Cacheable, CachedINode, DirCacheItem, INodeCacheItem};
use super::devfs::DevINode;
use super::file_table::FileHandle;
use super::path::PathBuf;
use super::{cache, FileSystem, FileSystemError, Result};

static DIR_CACHE_MARKER: AtomicUsize = AtomicUsize::new(0x00);
Expand Down Expand Up @@ -120,7 +121,7 @@ pub trait INodeInterface: Send + Sync {
/// ## Errors
/// - `FileSystemError::NotSupported` - If the inode is not a symbolic link or the filesystem
/// does not support symbolic links.
fn resolve_link(&self) -> Result<String> {
fn resolve_link(&self) -> Result<PathBuf> {
Err(FileSystemError::NotSupported)
}

Expand Down
90 changes: 28 additions & 62 deletions src/aero_kernel/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

use core::mem;

pub mod path;

// TODO: Do not re-export this.
pub use path::Path;

use aero_syscall::SyscallError;
use alloc::collections::BTreeMap;
use alloc::sync::Arc;
Expand Down Expand Up @@ -80,8 +85,8 @@ impl MountManager {
let current_data = directory.data.lock();
let mut root_data = root_dir.data.lock();

root_data.name = current_data.name.clone();
root_data.parent = current_data.parent.clone();
root_data.name.clone_from(&current_data.name);
root_data.parent.clone_from(&current_data.parent);

mem::drop(root_data);
mem::drop(current_data);
Expand Down Expand Up @@ -157,53 +162,6 @@ impl From<FileSystemError> for SyscallError {
}
}

/// A slice of a path (akin to [str]).
#[derive(Debug)]
pub struct Path(str);

impl Path {
pub fn new(path: &str) -> &Self {
unsafe { &*(path as *const str as *const Path) }
}

#[inline]
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}

/// Returns [`true`] if the path is absolute.
pub fn is_absolute(&self) -> bool {
self.0.starts_with('/')
}

/// Returns an iterator over the components of the path.
pub fn components(&self) -> impl Iterator<Item = &str> {
self.0.split('/').filter(|e| !e.is_empty() && *e != ".")
}

pub fn as_str(&self) -> &str {
&self.0
}

/// Helper function that returns the parent path and the base name
/// of the path.
pub fn parent_and_basename(&self) -> (&Self, &str) {
if let Some(slash_index) = self.0.rfind('/') {
let parent_dir = if slash_index == 0 {
Path::new("/")
} else {
Path::new(&self.0[..slash_index])
};

let basename = &self.0[(slash_index + 1)..];
(parent_dir, basename)
} else {
// A relative path without any slashes.
(Path::new(""), &self.0)
}
}
}

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum LookupMode {
None,
Expand All @@ -215,7 +173,10 @@ pub fn lookup_path_with(
mut cwd: DirCacheItem,
path: &Path,
mode: LookupMode,
resolve_last: bool,
) -> Result<DirCacheItem> {
let components_len = path.components().count();

// Iterate and resolve each component. For example `a`, `b`, and `c` in `a/b/c`.
for (i, component) in path.components().enumerate() {
match component {
Expand Down Expand Up @@ -249,7 +210,7 @@ pub fn lookup_path_with(
if err == FileSystemError::EntryNotFound
&& mode == LookupMode::Create =>
{
if i == path.components().count() - 1 {
if i == components_len - 1 {
cwd = cwd.inode().touch(cwd.clone(), component)?;
} else {
// todo: fix this shit
Expand All @@ -258,6 +219,7 @@ pub fn lookup_path_with(
cwd.clone(),
Path::new(component),
LookupMode::None,
resolve_last,
) {
Ok(x) => x,
Err(e) => {
Expand All @@ -275,16 +237,19 @@ pub fn lookup_path_with(
let inode = cwd.inode();
let metadata = inode.metadata()?;

if metadata.is_symlink() {
let resolved_path_str = inode.resolve_link()?;
let resolved_path = Path::new(&resolved_path_str);

if resolved_path.is_absolute() {
cwd = lookup_path(resolved_path)?;
continue;
}

cwd = lookup_path_with(parent, resolved_path, LookupMode::None)?;
if metadata.is_symlink() && resolve_last {
let resolved_path = inode.resolve_link()?;

cwd = lookup_path_with(
if resolved_path.is_absolute() {
root_dir().clone()
} else {
parent
},
resolved_path.as_ref(),
LookupMode::None,
resolve_last,
)?;
} else if metadata.is_directory() {
if let Ok(mount_point) = MOUNT_MANAGER.find_mount(cwd.clone()) {
cwd = mount_point.root_entry;
Expand All @@ -299,12 +264,13 @@ pub fn lookup_path_with(

pub fn lookup_path(path: &Path) -> Result<DirCacheItem> {
let cwd = if !path.is_absolute() {
scheduler::get_scheduler().current_task().cwd_dirent()
scheduler::current_thread().cwd_dirent()
} else {
root_dir().clone()
};

lookup_path_with(cwd, path, LookupMode::None)
// TODO:Keep `resolve_last` set to true as a default?
lookup_path_with(cwd, path, LookupMode::None, true)
}

pub fn root_dir() -> &'static DirCacheItem {
Expand Down
Loading

0 comments on commit 93a215b

Please sign in to comment.