My Project
Loading...
Searching...
No Matches
Public Member Functions | Data Fields | Static Public Attributes
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)
 
Blockblock_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

MetaPagemetapage
 
int fd
 
std::FILE * file_handle
 
int current_process
 
vaddr_tfreelist
 
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 670 of file vspace.cc.

670 {
671 int seg = metapage->segment_count++;
673 void *map_addr = mmap_segment(seg);
674 segments[seg] = VSeg(map_addr);
675 Block *top = block_ptr(seg * SEGMENT_SIZE);
676 top->next = freelist[LOG2_SEGMENT_SIZE];
677 top->prev = VADDR_NULL;
679}
const vaddr_t VADDR_NULL
Definition: vspace.h:1417
static const size_t SEGMENT_SIZE
Definition: vspace.h:1424
static const size_t METABLOCK_SIZE
Definition: vspace.h:1420
static const int LOG2_SEGMENT_SIZE
Definition: vspace.h:1421
Block * block_ptr(vaddr_t vaddr)
Definition: vspace.h:1610
void * mmap_segment(int seg)
Definition: vspace.cc:656
MetaPage * metapage
Definition: vspace.h:1589
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.

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

◆ deinit()

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

Definition at line 634 of file vspace.cc.

634 {
635 if (file_handle) {
636 fclose(file_handle);
638 } else {
639 close(fd);
640 }
641 munmap(metapage, METABLOCK_SIZE);
642 metapage = NULL;
643 current_process = -1;
644 freelist = NULL;
645 for (int i = 0; i < MAX_SEGMENTS; i++) {
646 if (!segments[i].is_free())
647 munmap(segments[i].base, SEGMENT_SIZE);
648 segments[i] = VSeg(NULL);
649 }
650 for (int i = 0; i < MAX_PROCESS; i++) {
651 close(channels[i].fd_read);
652 close(channels[i].fd_write);
653 }
654}
int i
Definition: cfEzgcd.cc:132
static const size_t MAX_SEGMENTS
Definition: vspace.h:1423
static const int MAX_PROCESS
Definition: vspace.h:1419
std::FILE * file_handle
Definition: vspace.h:1591
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.

1615 {
1616 int seg = vaddr >> LOG2_SEGMENT_SIZE;
1617 if (segments[seg].is_free())
1618 segments[seg] = mmap_segment(seg);
1619 }

◆ filesize()

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

Definition at line 583 of file vspace.cc.

583 {
584 struct stat stat;
585 fstat(fd, &stat);
586 return stat.st_size;
587}

◆ init() [1/3]

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

Definition at line 612 of file vspace.cc.

612 {
613 FILE *fp = tmpfile();
614 Status result = init(fileno(fp));
615 if (!result.ok())
616 return result;
617 current_process = 0;
618 file_handle = fp;
619 metapage->process_info[0].pid = getpid();
620 return Status(ErrNone);
621}
CanonicalForm fp
Definition: cfModGcd.cc:4102
return result
Definition: facAbsBiFact.cc:75
ProcessInfo process_info[MAX_PROCESS]
Definition: vspace.h:1513
@ ErrNone
Definition: vspace.h:1376

◆ init() [2/3]

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

Definition at line 623 of file vspace.cc.

623 {
624 int fd = open(path, O_RDWR | O_CREAT, 0600);
625 if (fd < 0)
626 return Status(ErrFile);
627 init(fd);
629 // TODO: enter process in meta table
631 return Status(ErrNone);
632}
void unlock_metapage()
Definition: vspace.cc:883
void lock_metapage()
Definition: vspace.cc:879
@ ErrFile
Definition: vspace.h:1378
int status int void size_t count int const void size_t count open
Definition: si_signals.h:73

◆ init() [3/3]

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

Definition at line 589 of file vspace.cc.

589 {
590 this->fd = fd;
591 for (int i = 0; i < MAX_SEGMENTS; i++)
592 segments[i] = VSeg(NULL);
593 for (int i = 0; i < MAX_PROCESS; i++) {
594 int channel[2];
595 if (pipe(channel) < 0) {
596 for (int j = 0; j < i; j++) {
597 close(channels[j].fd_read);
598 close(channels[j].fd_write);
599 }
600 return Status(ErrOS);
601 }
602 channels[i].fd_read = channel[0];
603 channels[i].fd_write = channel[1];
604 }
606 init_metapage(filesize() == 0);
609 return Status(ErrNone);
610}
int j
Definition: facHensel.cc:110
vaddr_t freelist[LOG2_SEGMENT_SIZE+1]
Definition: vspace.h:1511
void init_metapage(bool create)
Definition: vspace.cc:887
@ ErrOS
Definition: vspace.h:1380

◆ mmap_segment()

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

Definition at line 656 of file vspace.cc.

656 {
658 void *map = mmap(NULL, SEGMENT_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
660 if (map == MAP_FAILED) {
661 // This is an "impossible to proceed from here, because system state
662 // is impossible to proceed from" situation, so we abort the program.
663 perror("mmap");
664 abort();
665 }
667 return map;
668}
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:504

◆ segaddr()

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

Definition at line 1605 of file vspace.h.

1605 {
1606 if (vaddr == VADDR_NULL)
1607 return SEGADDR_NULL;
1608 return vaddr & SEGMENT_MASK;
1609 }
static const size_t SEGMENT_MASK
Definition: vspace.h:1425
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.

1596 {
1597 return segments[vaddr >> LOG2_SEGMENT_SIZE];
1598 }

◆ segment_no()

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

Definition at line 1599 of file vspace.h.

1599 {
1600 return vaddr >> LOG2_SEGMENT_SIZE;
1601 }

◆ to_ptr()

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

Definition at line 1620 of file vspace.h.

1620 {
1621 if (vaddr == VADDR_NULL)
1622 return NULL;
1624 return segment(vaddr).ptr(segaddr(vaddr));
1625 }
void ensure_is_mapped(vaddr_t vaddr)
Definition: vspace.h:1615
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.

1602 {
1603 return (segno << LOG2_SEGMENT_SIZE) | addr;
1604 }

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: