Example #1
0
bool ModuleParser::parseMemoryHelper(bool isImport)
{
    // We don't allow redeclaring memory. Either via import or definition.
    if (m_module->memory)
        return false;

    PageCount initialPageCount;
    PageCount maximumPageCount;
    {
        uint32_t initial;
        std::optional<uint32_t> maximum;
        if (!parseResizableLimits(initial, maximum))
            return false;
        ASSERT(!maximum || *maximum >= initial);
        if (!PageCount::isValid(initial))
            return false;

        initialPageCount = PageCount(initial);

        if (maximum) {
            if (!PageCount::isValid(*maximum))
                return false;
            maximumPageCount = PageCount(*maximum);
        }
    }
    ASSERT(initialPageCount);
    ASSERT(!maximumPageCount || maximumPageCount >= initialPageCount);

    Vector<unsigned> pinnedSizes = { 0 };
    m_module->memory = MemoryInformation(initialPageCount, maximumPageCount, pinnedSizes, isImport);
    return true;
}
Example #2
0
bool EbookController::GoToNextPage()
{
    int dist = IsDoublePage() ? 2 : 1;
    if (currPageNo + dist > PageCount())
        return false;
    GoToPage(currPageNo + dist, false);
    return true;
}
Example #3
0
/*
 * Get memory 
 */
LOCAL void* imalloc( size_t size, IMACB *imacb )
{
	QUEUE	*q;
	VP	mem;
	UW	imask;

	/* If it is smaller than the minimum fragment size,
	   allocate the minimum size to it. */
	if ( size < MIN_FRAGMENT ) {
		size = MIN_FRAGMENT;
	}
	size = ROUND(size);

	DI(imask);  /* Exclusive control by interrupt disable */
	SpinLock(&MemLockObj);

	/* Search FreeQue */
	q = searchFreeArea(size, imacb);
	if ( q != &imacb->freeque ) {
		/* There is free area: Split from FreeQue once */
		removeFreeQue(q);

		q = q - 1;
	} else {
		/* Reserve new pages because there is no free space */
		QUEUE	*e;
		size_t	n;

		/* Reserve pages */
		SpinUnlock(&MemLockObj);
		EI(imask);
		n = PageCount(size + sizeof(QUEUE) * 2);
		q = GetSysMemBlk(n, imacb->mematr);
		if ( q == NULL ) {
			goto err_ret;  /* Insufficient memory */
		}
		DI(imask);
		SpinLock(&MemLockObj);

		/* Register on AreaQue */
		e = (QUEUE*)((VB*)q + n * pagesz) - 1;
		insertAreaQue(&imacb->areaque, e);
		insertAreaQue(&imacb->areaque, q);
		setAreaFlag(q, AREA_TOP);
		setAreaFlag(e, AREA_END);
	}

	/* Allocate memory */
	mem = mem_alloc(q, size, imacb);

	SpinUnlock(&MemLockObj);
	EI(imask);
	return mem;

err_ret:
	BMS_DEBUG_PRINT(("imalloc error\n"));
	return NULL;
}
Example #4
0
std::string PDFPagesListObject::ObjectEntry()
{
	buffer =  "<<\r";
	buffer += "/Type /Pages\r";
	buffer += KidPagesStr();
	buffer += "/Count ";
	buffer += intToStr( PageCount() );
	buffer += "\r";
	buffer += SizeStr();
	buffer += ">>\r";
	AddContents( buffer );
	return PDFBodyObject::ObjectEntry();
}
Example #5
0
void EbookController::GoToPage(int pageNo, bool addNavPoint)
{
    // we're still formatting, disable page movement
    if (incomingPages) {
        //lf("EbookController::GoToPage(%d): skipping because incomingPages != nullptr", pageNo);
        return;
    }

    CrashIf(!pages);
    // Hopefully prevent crashes like 55175
    if (!pages) {
        return;
    }

    if (addNavPoint)
        AddNavPoint();

    int pageCount = PageCount();
    int n = IsDoublePage() ? 1 : 0;
    if (pageNo + n > pageCount)
        pageNo = pageCount - n;
    // if have only 1 page and showing double, we could go below 1
    if (pageNo < 1)
        pageNo = 1;

    HtmlPage *p = pages->At(pageNo - 1);
    currPageNo = pageNo;
    currPageReparseIdx = p->reparseIdx;
    ctrls->pagesLayout->GetPage1()->SetPage(p);
    if (IsDoublePage() && pages->Count() > 1) {
        p = pages->At(pageNo);
        ctrls->pagesLayout->GetPage2()->SetPage(p);
    } else {
        ctrls->pagesLayout->GetPage2()->SetPage(nullptr);
    }
    UpdateStatus();
    // update the ToC selection
    cb->PageNoChanged(this, pageNo);
}