-
Notifications
You must be signed in to change notification settings - Fork 139
Implement sbrk in MARSKernel #304
Comments
@M-ximus Please provide scratch on interface for new class here. |
Could you please share your expectation on completion? |
I have some ideas about this:
|
We definitely should start with high level operations. It would be nicer if the architecture you're making may be extended to add MMU features in future, but it is not necessary at the moment.
You're talking about host memory here, but we need to allocate guest memory, i.e. inside the FuncMemory class. FuncMemory class models (on a functional level) a DRAM chip, and you cannot resize it dynamically. Instead, you need to provide pointers to free guest memory and do not provide pointers to allocated. public:
MemoryManager(Addr ptr_to_mem_seg, uint64_t size);
void allocate_memory(int64_t num_bytes); //if it less than 0 it will decrease the segment Please use our local types defined in |
We can return pointer from Also |
I cannot imagine any alternative, could you please explain?
Yes we should, but that is performed with TLB which is another issue (#625). |
I thought that you wanted MMU(That translates virtual addresses to physical. We have plain and hierarchy model of memory that try to address memory and MMU tries to give them information from this address. It takes virtual address and via linkage table translate it to physical. But both of implementation of memory uses their own arrays for data). How should I work with this models? Can I change them? |
In MIPS/RISC-V translation is handled by TLB.
Surely. We are implementing MARS-OS kernel at the moment.
I believe it should capture |
Should my class control more than one block of memory or only one( |
MARS does not operate with segmented memory, so there is no need right now. |
However, we have stack, OS code and executable code loaded in memory. It worth to protect them from overwrite. |
I used And |
Please use the following syntax in your replies, otherwise it becomes to complicated. ```c++
class Code { };
``` |
class MemoryManager : public FuncMemory The basic idea of inheritance is to represent "is" relation. |
Firstly, MemoryManager a thing that control read(load) and write(store). And other operations(like memcpy) need to use them. But this class should use memory that uses memcpy( class MemoryManager
{
public:
MemoryManager( Addr ptr_to_start_mem = 0, size_t mem_size = 4096 /*FIXME(M-ximus): Do we need a header with mem constants?*/);
Addr allocate( size_t num_bytes);// only checks (block_size <= max) and changes block_size. It returns pointer to start of new memory
template<typename T, Endian endian> T load( Addr addr) const noexcept;
std::string read_string( Addr addr) const;
// I don't sure that we should be able to use unsafe read
template<typename T, Endian endian> void store( T value, Addr addr);
void write_string( const std::string& value, Addr addr);
// I don't sure that we should be able to use unsafe write
std::string dump();
private:
std::shared_ptr<FuncMemory> memory;
size_t block_size;
Addr start_ptr;
} (other methods will be added if they will be needed) |
Nope. You can control address/page permissions without accessing real memory, by checking addresses in TLB or MemoryManager I believe you need that: class MemoryManager
{
public:
explicit MemoryManager( std::shared_ptr<FuncMemory>);
Addr allocate( size_t num_bytes);
void deallocate( Addr addr);
// Optional
bool is_readable( Addr addr) const;
bool is_writeable( Addr addr) const;
private:
std::shared_ptr<FuncMemory> memory;
// ...
}; |
Since we are aligned on interfaces, let's proceed to the next step — unit tests for the interface. |
The question is still actual, although unanswered. |
Removing back to pool since there is no response from owner |
sbrk is a system call inside malloc. To run interesting programs, it should be supported inside MARSKernel class.
The idea is to keep pool of free heap memory in same manner as OS does.
The text was updated successfully, but these errors were encountered: