Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

134 lines (105 sloc) 2.498 kB
#ifndef RBX_VM_FIBER_DATA_HPP
#define RBX_VM_FIBER_DATA_HPP
#include "vm/config.h"
#include "prelude.hpp"
#include "gc/variable_buffer.hpp"
namespace rubinius {
#if defined(IS_X86)
#define FIBER_ENABLED
#define FIBER_ASM_X8632
struct fiber_context_t {
void* eip;
void* esp;
void* ebp;
void* ebx;
};
#elif defined(IS_X8664)
#define FIBER_ENABLED
#define FIBER_ASM_X8664
struct fiber_context_t {
void* rip;
void* rsp;
void* rbp;
void* rbx;
void* r12;
void* r13;
void* r14;
void* r15;
};
#else
struct fiber_context_t {
int dummy;
}
#endif
class FiberStack;
class FiberData {
fiber_context_t machine_;
enum Status {
eInitial = 1,
eRunning,
eOnStack,
eOnHeap,
eDead
} status_;
FiberStack* stack_;
void* heap_;
size_t heap_size_;
size_t heap_capacity_;
VariableRootBuffers variable_root_buffers_;
public:
FiberData(bool root=false)
: status_(root ? eOnStack : eInitial)
, stack_(0)
, heap_(0)
, heap_size_(0)
, heap_capacity_(0)
{}
VariableRootBuffers& variable_root_buffers() {
return variable_root_buffers_;
}
bool uninitialized_p() {
return status_ == eInitial && stack_ == 0;
}
fiber_context_t* machine() {
return &machine_;
}
void* stack_address() {
return stack_ ? stack_->address() : 0;
}
size_t stack_size() {
return stack_ ? stack_->size() : 0;
}
void* stack_bottom() {
#if defined(FIBER_ASM_X8632)
return machine_.esp;
#elif defined(FIBER_ASM_X8664)
return machine_.rsp;
#else
#error "not supported, you shouldn't be here"
#endif
}
intptr_t data_offset() {
if(status_ != eOnHeap) return 0;
return (intptr_t)heap_ - (intptr_t)stack_bottom();
}
intptr_t data_lower_bound() {
if(status_ != eOnHeap) return 0;
return (intptr_t)stack_->address();
}
intptr_t data_upper_bound() {
if(status_ != eOnHeap) return 0;
return (intptr_t)stack_->address() + stack_->size();
}
bool currently_on_stack_p(FiberData* cur) {
return stack_ && stack_->user() == cur;
}
FiberStack* allocate_stack(STATE);
void take_stack(STATE);
void copy_stack(STATE, void* addr, size_t size);
void copy_to_heap(STATE);
void orphan(STATE);
void switch_to(STATE, FiberData* from);
void switch_and_orphan(STATE, FiberData* from);
};
}
#endif
Jump to Line
Something went wrong with that request. Please try again.