Loading...
Searching...
No Matches
vspace::internals::VMem Struct Reference

`#include <vspace.h>`

## Public Member Functions

VSeg | segment (vaddr_t vaddr)
size_t | segment_no (vaddr_t vaddr)
vaddr_t | vaddr (size_t segno, segaddr_t addr)
segaddr_t | segaddr (vaddr_t vaddr)
Block * | block_ptr (vaddr_t vaddr)
void | ensure_is_mapped (vaddr_t vaddr)
void * | to_ptr (vaddr_t vaddr)
size_t | filesize ()
Status | init (int fd)
Status | init ()
Status | init (const char *path)
void | deinit ()
void * | mmap_segment (int seg)
void | add_segment ()

## Data Fields

MetaPage * | metapage
int | fd
std::FILE * | file_handle
int | current_process
vaddr_t * | freelist
VSeg | segments [MAX_SEGMENTS]
ProcessChannel | channels [MAX_PROCESS]

## Static Public Attributes

static VMem | vmem_global

## Detailed Description

Definition at line 1587 of file vspace.h.

## Member Function Documentation

## add_segment()

void vspace::internals::VMem::add_segment | ( |  | ) |

Definition at line 716 of file vspace.cc.

{
int seg = metapage->segment_count++;
ftruncate(fd, METABLOCK_SIZE + metapage->segment_count * SEGMENT_SIZE);
void *map_addr = mmap_segment(seg);
segments[seg] = VSeg(map_addr);
Block *top = block_ptr(seg * SEGMENT_SIZE);
top->next = freelist[LOG2_SEGMENT_SIZE];
top->prev = VADDR_NULL;
freelist[LOG2_SEGMENT_SIZE] = seg * SEGMENT_SIZE;
}
vspace::internals::VADDR_NULL
const vaddr_t VADDR_NULL
Definition vspace.h:1417
vspace::internals::SEGMENT_SIZE
static const size_t SEGMENT_SIZE
Definition vspace.h:1424
vspace::internals::METABLOCK_SIZE
static const size_t METABLOCK_SIZE
Definition vspace.h:1420
vspace::internals::LOG2_SEGMENT_SIZE
static const int LOG2_SEGMENT_SIZE
Definition vspace.h:1421
vspace::internals::VMem::block_ptr
Block * block_ptr(vaddr_t vaddr)
Definition vspace.h:1610
vspace::internals::VMem::mmap_segment
void * mmap_segment(int seg)
Definition vspace.cc:702
vspace::internals::VMem::metapage
MetaPage * metapage
Definition vspace.h:1589
vspace::internals::VMem::fd
int fd
Definition vspace.h:1590
vspace::internals::VMem::freelist
vaddr_t * freelist
Definition vspace.h:1593
vspace::internals::VMem::segments
VSeg segments[MAX_SEGMENTS]
Definition vspace.h:1594

## block_ptr()

Block * vspace::internals::VMem::block_ptr | ( | vaddr_t | vaddr | ) |

inline

Definition at line 1610 of file vspace.h.

{
if (vaddr == VADDR_NULL)
return NULL;
return (Block *) (segment(vaddr).base + segaddr(vaddr));
}
NULL
#define NULL
Definition omList.c:12
vspace::internals::VMem::segment
VSeg segment(vaddr_t vaddr)
Definition vspace.h:1596
vspace::internals::VMem::vaddr
vaddr_t vaddr(size_t segno, segaddr_t addr)
Definition vspace.h:1602
vspace::internals::VMem::segaddr
segaddr_t segaddr(vaddr_t vaddr)
Definition vspace.h:1605
vspace::internals::VSeg::base
unsigned char * base
Definition vspace.h:1567

## deinit()

void vspace::internals::VMem::deinit | ( |  | ) |

Definition at line 680 of file vspace.cc.

{
if (file_handle) {
fclose(file_handle);
file_handle = NULL;
} else {
close(fd);
}
munmap(metapage, METABLOCK_SIZE);
metapage = NULL;
current_process = -1;
freelist = NULL;
for (int i = 0; i < MAX_SEGMENTS; i++) {
if (!segments[i].is_free())
munmap(segments[i].base, SEGMENT_SIZE);
segments[i] = VSeg(NULL);
}
for (int i = 0; i < MAX_PROCESS; i++) {
close(channels[i].fd_read);
close(channels[i].fd_write);
}
}
i
int i
Definition cfEzgcd.cc:132
vspace::internals::MAX_SEGMENTS
static const size_t MAX_SEGMENTS
Definition vspace.h:1423
vspace::internals::MAX_PROCESS
static const int MAX_PROCESS
Definition vspace.h:1419
vspace::internals::VMem::file_handle
std::FILE * file_handle
Definition vspace.h:1591
vspace::internals::VMem::current_process
int current_process
Definition vspace.h:1592
vspace::internals::VMem::channels
ProcessChannel channels[MAX_PROCESS]
Definition vspace.h:1595

## ensure_is_mapped()

void vspace::internals::VMem::ensure_is_mapped | ( | vaddr_t | vaddr | ) |

inline

Definition at line 1615 of file vspace.h.

{
int seg = vaddr >> LOG2_SEGMENT_SIZE;
if (segments[seg].is_free())
segments[seg] = mmap_segment(seg);
}

## filesize()

size_t vspace::internals::VMem::filesize | ( |  | ) |

Definition at line 629 of file vspace.cc.

{
struct stat stat;
fstat(fd, &stat);
return stat.st_size;
}

## init() [1/3]

Status vspace::internals::VMem::init | ( |  | ) |

Definition at line 658 of file vspace.cc.

{
FILE *fp = tmpfile();
Status result = init(fileno(fp));
if (!result.ok())
return result;
current_process = 0;
file_handle = fp;
metapage->process_info[0].pid = getpid();
return Status(ErrNone);
}
fp
CanonicalForm fp
Definition cfModGcd.cc:4110
result
return result
Definition facAbsBiFact.cc:76
vspace::ErrNone
@ ErrNone
Definition vspace.h:1376
vspace::internals::VMem::init
Status init()
Definition vspace.cc:658

## init() [2/3]

Status vspace::internals::VMem::init | ( | const char * | path | ) |

Definition at line 669 of file vspace.cc.

{
int fd = open(path, O_RDWR | O_CREAT, 0600);
if (fd < 0)
return Status(ErrFile);
init(fd);
lock_metapage();
// TODO: enter process in meta table
unlock_metapage();
return Status(ErrNone);
}
vspace::internals::unlock_metapage
void unlock_metapage()
Definition vspace.cc:929
vspace::internals::lock_metapage
void lock_metapage()
Definition vspace.cc:925
vspace::ErrFile
@ ErrFile
Definition vspace.h:1378
open
int status int void size_t count open
Definition si_signals.h:83

## init() [3/3]

Status vspace::internals::VMem::init | ( | int | fd | ) |

Definition at line 635 of file vspace.cc.

{
this->fd = fd;
for (int i = 0; i < MAX_SEGMENTS; i++)
segments[i] = VSeg(NULL);
for (int i = 0; i < MAX_PROCESS; i++) {
int channel[2];
if (pipe(channel) < 0) {
for (int j = 0; j < i; j++) {
close(channels[j].fd_read);
close(channels[j].fd_write);
}
return Status(ErrOS);
}
channels[i].fd_read = channel[0];
channels[i].fd_write = channel[1];
}
lock_metapage();
init_metapage(filesize() == 0);
unlock_metapage();
freelist = metapage->freelist;
return Status(ErrNone);
}
j
int j
Definition facHensel.cc:110
vspace::internals::init_metapage
void init_metapage(bool create)
Definition vspace.cc:933
vspace::ErrOS
@ ErrOS
Definition vspace.h:1380
vspace::internals::VMem::filesize
size_t filesize()
Definition vspace.cc:629

## mmap_segment()

void * vspace::internals::VMem::mmap_segment | ( | int | seg | ) |

Definition at line 702 of file vspace.cc.

{
lock_metapage();
void *map = mmap(NULL, SEGMENT_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
METABLOCK_SIZE + seg * SEGMENT_SIZE);
if (map == MAP_FAILED) {
// This is an "impossible to proceed from here, because system state
// is impossible to proceed from" situation, so we abort the program.
perror("mmap");
abort();
}
unlock_metapage();
return map;
}
map
CanonicalForm map(const CanonicalForm &primElem, const Variable &alpha, const CanonicalForm &F, const Variable &beta)
map from to such that is mapped onto
Definition cf_map_ext.cc:505

## segaddr()

segaddr_t vspace::internals::VMem::segaddr | ( | vaddr_t | vaddr | ) |

inline

Definition at line 1605 of file vspace.h.

{
if (vaddr == VADDR_NULL)
return SEGADDR_NULL;
return vaddr & SEGMENT_MASK;
}
vspace::internals::SEGMENT_MASK
static const size_t SEGMENT_MASK
Definition vspace.h:1425
vspace::internals::SEGADDR_NULL
const segaddr_t SEGADDR_NULL
Definition vspace.h:1416

## segment()

VSeg vspace::internals::VMem::segment | ( | vaddr_t | vaddr | ) |

inline

Definition at line 1596 of file vspace.h.

{
return segments[vaddr >> LOG2_SEGMENT_SIZE];
}

## segment_no()

size_t vspace::internals::VMem::segment_no | ( | vaddr_t | vaddr | ) |

inline

Definition at line 1599 of file vspace.h.

{
return vaddr >> LOG2_SEGMENT_SIZE;
}

## to_ptr()

void * vspace::internals::VMem::to_ptr | ( | vaddr_t | vaddr | ) |

inline

Definition at line 1620 of file vspace.h.

{
if (vaddr == VADDR_NULL)
return NULL;
ensure_is_mapped(vaddr);
return segment(vaddr).ptr(segaddr(vaddr));
}
vspace::internals::VMem::ensure_is_mapped
void ensure_is_mapped(vaddr_t vaddr)
Definition vspace.h:1615
vspace::internals::VSeg::ptr
void * ptr(segaddr_t addr)
Definition vspace.h:1578

## vaddr()

vaddr_t vspace::internals::VMem::vaddr | ( | size_t | segno,
|  | segaddr_t | addr )

inline

Definition at line 1602 of file vspace.h.

{
return (segno << LOG2_SEGMENT_SIZE) | addr;
}

## Field Documentation

## channels

ProcessChannel vspace::internals::VMem::channels[MAX_PROCESS]

Definition at line 1595 of file vspace.h.

## current_process

int vspace::internals::VMem::current_process

Definition at line 1592 of file vspace.h.

## fd

int vspace::internals::VMem::fd

Definition at line 1590 of file vspace.h.

## file_handle

std::FILE* vspace::internals::VMem::file_handle

Definition at line 1591 of file vspace.h.

## freelist

vaddr_t* vspace::internals::VMem::freelist

Definition at line 1593 of file vspace.h.

## metapage

MetaPage* vspace::internals::VMem::metapage

Definition at line 1589 of file vspace.h.

## segments

VSeg vspace::internals::VMem::segments[MAX_SEGMENTS]

Definition at line 1594 of file vspace.h.

## vmem_global

VMem vspace::internals::VMem::vmem_global

static

Definition at line 1588 of file vspace.h.

The documentation for this struct was generated from the following files:

- kernel/oswrapper/vspace.h
- kernel/oswrapper/vspace.cc