1
0
forked from Rativel/BurritOS

Add ucontext_t

This commit is contained in:
Quentin Legot
2023-03-06 16:31:35 +01:00
committed by François Autin
parent e4db7ec96b
commit 3457f67a7c
5 changed files with 103 additions and 11 deletions

View File

@@ -1,14 +1,10 @@
use std::sync::Arc;
use std::{sync::Arc};
use super::{process::Process, mgerror::ErrorCode, system::{ObjectType, G_ALIVE, G_SCHEDULER}};
use super::{process::Process, mgerror::ErrorCode, system::{ObjectType, G_ALIVE, G_SCHEDULER}, ucontext::UContextT};
use crate::{simulator::machine::{NUM_INT_REGS, NUM_FP_REGS, STACK_REG}};
const SIMULATORSTACKSIZE: usize = 32 * 1024;
#[derive(PartialEq)]
struct SimulatorContext {
// todo
}
const STACK_FENCEPOST: u32 = 0xdeadbeef;
#[derive(PartialEq)]
struct ThreadContext {
@@ -21,7 +17,7 @@ struct ThreadContext {
pub struct Thread {
name: String,
process: Option<Process>,
simulation_context: SimulatorContext,
// simulation_context: UContextT,
thread_context: ThreadContext,
stack_pointer: i32,
object_type: ObjectType
@@ -33,7 +29,7 @@ impl Thread {
Self {
name,
process: None,
simulation_context: SimulatorContext { },
// simulation_context: UContextT::new(),
thread_context: ThreadContext {
int_registers: [0; NUM_INT_REGS],
float_registers: [0; NUM_FP_REGS],
@@ -79,7 +75,18 @@ impl Thread {
}
fn init_simulator_context(&self, base_stack_addr: [i8; SIMULATORSTACKSIZE]) {
todo!();
// let res = self.simulation_context.get_context();
// if res != 0 {
// panic!("getcontext returns non-zero value {}", res);
// }
// self.simulation_context.buf.uc_stack.ss_sp = base_stack_addr;
// self.simulation_context.buf.uc_stack.ss_size = base_stack_addr.len();
// self.simulation_context.buf.uc_stack.ss_flags = 0;
// self.simulation_context.buf.uc_link = UContextT::new().buf;
// self.simulation_context.make_context(start_thread_execution, 0);
// self.simulation_context.stackBottom = base_stack_addr.to_vec();
// self.simulation_context.stackBottom[0] = STACK_FENCEPOST;
}
/// Wait for another thread to finish its execution
@@ -147,4 +154,8 @@ impl Drop for Thread {
todo!();
}
}
fn start_thread_execution() {
}