Пример #1
0
void
Heap_Resize(Heap_t* h, long newSize, int reset)
{
	long usedSize;
	long maxSize = (h->mappedTop - h->bottom) * sizeof(val_t);
	long oldWriteableSize = (h->writeableTop - h->bottom) * sizeof(val_t);
	long newSizeRound = RoundUp(newSize, TILT_PAGESIZE);

	if (newSize > maxSize) DIE("resized heap too big");
	if (reset) {
		h->cursor = h->bottom;
	}
	usedSize = (h->cursor - h->bottom) * sizeof(val_t);
	assert(usedSize <= newSize);
	h->top = h->bottom + (newSize / sizeof(val_t));

	if (newSizeRound > oldWriteableSize) {
		my_mprotect(6,(caddr_t) h->writeableTop,
			newSizeRound - oldWriteableSize,
			PROT_READ | PROT_WRITE);
		h->writeableTop = h->bottom + newSizeRound / sizeof(val_t);
	}
	else if (paranoid && newSizeRound < oldWriteableSize) {
		my_mprotect(7,(caddr_t) (h->bottom +
			newSizeRound / sizeof(val_t)),
			oldWriteableSize - newSizeRound, PROT_NONE);
		h->writeableTop = h->bottom + newSizeRound / sizeof(val_t);
	}
	assert(h->bottom <= h->cursor);
	assert(h->cursor <= h->top);
	assert(h->top <= h->writeableTop);
	assert(h->writeableTop <= h->mappedTop);
}
Пример #2
0
void jump_function(){
	//CHAR_walk_move
	//函數
	my_mprotect((int)JUMP_CHAR_walk_move_SUB);
	*(char*)((int)JUMP_CHAR_walk_move_SUB +  0)= 0x57; //PUSH edi
	*(char*)((int)JUMP_CHAR_walk_move_SUB +  1)= 0xE8; //CALL
	*(int *)((int)JUMP_CHAR_walk_move_SUB +  2)= (int)JUMP_CHAR_walk_move -4 -((int)JUMP_CHAR_walk_move_SUB + 2);
	*(char*)((int)JUMP_CHAR_walk_move_SUB +  6)= 0x83; //ADD esp, 4
	*(char*)((int)JUMP_CHAR_walk_move_SUB +  7)= 0xC4;
	*(char*)((int)JUMP_CHAR_walk_move_SUB +  8)=  0x4;
	*(char*)((int)JUMP_CHAR_walk_move_SUB +  9)= 0x83; //cmp [ebp+var_38], 6
	*(char*)((int)JUMP_CHAR_walk_move_SUB + 10)= 0x7D;
	*(char*)((int)JUMP_CHAR_walk_move_SUB + 11)= 0xC8;
	*(char*)((int)JUMP_CHAR_walk_move_SUB + 12)= 0x06;
	*(char*)((int)JUMP_CHAR_walk_move_SUB + 13)= 0x0F; //jz loc_807C19C
	*(char*)((int)JUMP_CHAR_walk_move_SUB + 14)= 0x84;
	*(int *)((int)JUMP_CHAR_walk_move_SUB + 15)= 0x0807C19C -4 -((int)JUMP_CHAR_walk_move_SUB + 15) ;
	*(char*)((int)JUMP_CHAR_walk_move_SUB + 19)= 0xE9; //jmp loc_0807BDC1
	*(int *)((int)JUMP_CHAR_walk_move_SUB + 20)= 0x0807BDC1 -4 -((int)JUMP_CHAR_walk_move_SUB + 20);
	//jump
	my_mprotect(0x0807BDB7);
	*(char*)(0x0807BDB7)= 0xE9;
	*(int *)(0x0807BDB8)= (int)JUMP_CHAR_walk_move_SUB -4 -0x0807BDB8;

}
Пример #3
0
static Stacklet_t*
Stacklet_Alloc(StackChain_t* stackChain)
{
	int i;
	Stacklet_t *res = NULL;
	/*
		Each stacklet contains the primary and replica.  Each one
		starts with a guard page, a C area, and then an ML area.
	*/
	int size = (GuardStackletSize + MLStackletSize + CStackletSize) * kilobyte;	/* for just one of the two: primary and replica */

	assert(stackletOffset == size);
	for (i=0; i<NumStacklet; i++)
		if (CompareAndSwap(&Stacklets[i].count, 0, 1) == 0) {
			res = &Stacklets[i];
			break;
		}
	if (res == NULL)
		DIE("out of stack space");

	res->parent = stackChain;
	res->state = Inconsistent;
	if (!res->mapped) {
		mem_t start = my_mmap(2 * size, PROT_READ | PROT_WRITE);
		mem_t middle = start + size / (sizeof (val_t));

		res->baseExtendedBottom = start +
			(GuardStackletSize * kilobyte) / (sizeof (val_t));
		res->baseBottom = res->baseExtendedBottom +
			(CStackletSize * kilobyte) / (sizeof (val_t));
		res->baseTop = res->baseBottom +
			(MLStackletSize * kilobyte) / (sizeof (val_t));
		assert(res->baseTop == middle);
		/*
			Get some initial room in multiples of 64 bytes; Sparc
			requires at least 68 byte for the save area.
		*/
		res->baseTop -= (128 / sizeof(val_t));
		my_mprotect(0, (caddr_t) start, GuardStackletSize * kilobyte,
			PROT_NONE);	/* Guard page at bottom of primary */
		my_mprotect(1, (caddr_t) middle, GuardStackletSize * kilobyte,
			PROT_NONE);	/* Guard page at bottom of replica */

		res->callinfoStack = SetCreate(size / (32 * sizeof (val_t)));
		res->mapped = 1;
	}
	res->baseCursor = res->baseTop;
	for (i=0; i<32; i++)
		res->bottomBaseRegs[i] = 0;
	SetReset(res->callinfoStack);
	return res;
}