Beispiel #1
0
void run()
{
	initRun();

	while(!feof(f))
		procCom(fgetc(f));

	printf("\n");

	fclose(f);

	if(!isEmpty_Stack(loopPntsStack))
		prLog("[!] Warning: Invalide loops: Expected the ending of the loop!\n");

	delete_Stack(loopPntsStack);
}
Beispiel #2
0
/**
* Get the next free chunk 
* 
* @param size The size of the chunk to allocate
* @param allocated The address to store the address of the allocated chunk
*
* @return 0 if successful, -42 is something went terribly wrong
*/
int getNextFreeChunk(int size, void** allocated)
{
	int ret=0;
	int chunk_size=0;
	int bitmap_size=0;
	int index;
	Run* run_ptr;

	// Get the next run with free space
	chunk_size = (1 << size);
	bitmap_size = _SC_PAGESIZE/(1 << size);
	for(run_ptr=pool[size-1]; run_ptr != NULL && testBit(run_ptr->bitmap, bitmap_size-1); run_ptr=run_ptr->next) {
		int found=0;
		for(int i=0; i<bitmap_size; i++) {
			if(!testBit(run_ptr->bitmap, i)) {
				found=1;
				break;
			}
		}
		if(found)
			break;
	}

	// If all runs are full
	if(run_ptr == NULL) {
		initRun(&run_ptr, chunk_size);
		run_ptr->next = pool[size-1];
		pool[size-1] = run_ptr;
		*allocated = run_ptr->memory;
		return 0;
	}

	// Find free space in run
	for(int i=0; i<bitmap_size; i++) {
		if(!testBit(run_ptr->bitmap, i)) {
			char* mem_ptr;
			mem_ptr = (char *)run_ptr->memory;
			*allocated = mem_ptr + i*chunk_size;
			setBit(run_ptr->bitmap,i);
			return 0;
		}
	}


	// Should never get here
	return -42;
}
PyObject *run(PyObject *self, PyObject *args)
{
    struct Runobj runobj = {0};
    struct Result rst = {0};
    rst.re_call = -1;
    
    if(initRun(&runobj, args)){
        if(runobj.args)
            free((void*)runobj.args);
        return NULL;
    }
    
    if(runit(&runobj, &rst) == -1)
        return NULL;
    if(runobj.args)
        free((void*)runobj.args);
    
    return genResult(&rst);
}