Example #1
0
void
TEightTrack::Close()
{
	int	i;

	mem_check();

	fclose(fpPhysFile);
	
	if (pCache)	
	{
		FREE (pCache);
		pCache = 0;
	}

	for (i=0; i<numTracks; i++)
	{
		if(aTracks[i].pSegmentArray)
		{
			FREE (aTracks[i].pSegmentArray);
		}
	}

	numSectors = 0;
	numTracks = 0;
	numSegments = 0;
	segmentsToRead = 0;
	memset (aTracks, 0, sizeof(aTracks));

	mem_check();
}
Example #2
0
static void heap_malloc_init()
{
	rt_uint8_t *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;

	ptr1 = rt_malloc(1);
	ptr2 = rt_malloc(13);
	ptr3 = rt_malloc(31);
	ptr4 = rt_malloc(127);
	ptr5 = rt_malloc(0);

	memset(ptr1, 1, 1);
	memset(ptr2, 2, 13);
	memset(ptr3, 3, 31);
	memset(ptr4, 4, 127);

	if (mem_check(ptr1, 1, 1)   != RT_FALSE) goto _failed;
	if (mem_check(ptr2, 2, 13)  != RT_FALSE) goto _failed;
	if (mem_check(ptr3, 3, 31)  != RT_FALSE) goto _failed;
	if (mem_check(ptr4, 4, 127) != RT_FALSE) goto _failed;

	rt_free(ptr4);
	rt_free(ptr3);
	rt_free(ptr3);
	rt_free(ptr1);

	if (ptr5 != RT_NULL)
	{
		rt_free(ptr5);
	}

	tc_done(TC_STAT_PASSED);

_failed:
	tc_done(TC_STAT_FAILED);
}
Example #3
0
Bool symbol_is_valid(const Symbol* sym)
{
   if (sym == NULL || !SID_ok(sym, SYMBOL_SID))
      return FALSE;

   mem_check(sym);
   mem_check(sym->entry);
      
   return TRUE;
}
Example #4
0
//Set a decimal variable
void set_var_decimal(Variable *varArry, int arrySpot){
	String value = (String)malloc(ARRAYLENGHT * sizeof(char));
	int flag;
	//Check if memory allocated properly.
	mem_check(value);

	do{
		//User interaction
		printf("%s", "\n\nGive the variables value (Decimal):");
		fgets(value, ARRAYLENGHT, stdin);

		//Check for valid lenght
		flag = false;
		if (value[strlen(value) - 1] == '\n' && strlen(value) > 1)
			value[strcspn(value, "\n")] = 0; //Drop the \n from the input
		else{
			flag = true;
			printf("%s", "\n\nInvalid lenght. It must be between 1 and 255 characters!\n\n");
			if (strlen(value) > 1)
				clear_stdin(); //Clear stdin from extra input
		}

		//Check if user entered a decimal
		if (!isdecimal(value) || flag)
			printf("%s", "\n\nThe value you gave is not a decimal!\n\n");

	} while (!isdecimal(value));

	//Copy the decimal to our array and free the buffer
	strcpy(varArry[arrySpot].value, value);

	free(value);
}
Example #5
0
void set_var_bool(Variable *varArry, int arrySpot){
	String value = (String)malloc(ARRAYLENGHT * sizeof(char));
	int flag;

	//Check if memory allocated properly.
	mem_check(value);

	do{
		printf("%s", "\n\nGive the variables value (true/false):");
		fgets(value, ARRAYLENGHT, stdin);

		//Check for valid lenght
		flag = false;
		if (value[strlen(value) - 1] == '\n' && strlen(value) > 1){
			value[strcspn(value, "\n")] = 0; //Drop the \n from the input

			if (!isbool(value))
				printf("%s", "\n\nThe value you gave is not a bool!\n\n");
		}
		else{
			flag = true;
			printf("%s", "\n\nInvalid lenght. It must be between 1 and 255 characters!\n\n");
			if (strlen(value) > 1)
				clear_stdin(); //Clear stdin from extra input
		}

	} while (!isbool(value));

	//Copy the value to the array and free memory
	strcpy(varArry[arrySpot].value, value);

	free(value);
}
Example #6
0
/** Deallocate BIP data structure.
 */
void bip_exit(BIP* bip)
{
   assert(bip_is_valid(bip));
   
   mem_check(bip);
   
   free(bip);
}
Example #7
0
Bool define_is_valid(const Define* def)
{
   if (def == NULL || !SID_ok(def, DEFINE_SID))
      return FALSE;

   mem_check(def);

   return TRUE;
}
Example #8
0
void
bin_test(struct bin_info *p)
{
	int b;

	for(b=0; b<p->bins; b++) {
		if(mem_check(p->m[b].ptr, p->m[b].size)) {
			printf("memory corrupt!\n");
			abort();
		}
	}
}
Example #9
0
/*
    ===========================================================
    mem_alloc
    ===========================================================
    Allocates a MAB of the specified size and returns a pointer
    to this MAB. The allocation algorithm employed is a
    first-fit policy.
    
    Uses the global variable 'memory' as the head of the MAB 
    list.
    -----------------------------------------------------------
    size:       The size of the MAB being requested.
    -----------------------------------------------------------
    return value:
                A pointer to the requested MAB. NULL if no such
                MAB could be found.
    -----------------------------------------------------------
*/
MAB *mem_alloc(unsigned int size) {
    MAB *m = NULL;                                      /* the requested MAB - null if none found */
    
    if (size > 0) {
        /* try to allocate memory */
        if ((m = mem_check(size)) && mem_split(m, size)) {
            m->allocated = true;
        }
    }
    
    /* return the (un)allocated memory */
    return m;
}
Example #10
0
void
mem_init(void)
{
	if (!cpu_onboot())	// only do once, on the boot CPU
		return;

	// Determine how much base (<640K) and extended (>1MB) memory
	// is available in the system (in bytes),
	// by reading the PC's BIOS-managed nonvolatile RAM (NVRAM).
	// The NVRAM tells us how many kilobytes there are.
	// Since the count is 16 bits, this gives us up to 64MB of RAM;
	// additional RAM beyond that would have to be detected another way.
	size_t basemem = ROUNDDOWN(nvram_read16(NVRAM_BASELO)*1024, PAGESIZE);
	size_t extmem = ROUNDDOWN(nvram_read16(NVRAM_EXTLO)*1024, PAGESIZE);

	warn("Assuming we have 1GB of memory!");
	extmem = 1024*1024*1024 - MEM_EXT;	// assume 1GB total memory

	// The maximum physical address is the top of extended memory.
	mem_max = MEM_EXT + extmem;

	// Compute the total number of physical pages (including I/O holes)
	mem_npage = mem_max / PAGESIZE;

	cprintf("Physical memory: %dK available, ", (int)(mem_max/1024));
	cprintf("base = %dK, extended = %dK\n",
		(int)(basemem/1024), (int)(extmem/1024));

  spinlock_init(&_freelist_lock);
  pageinfo *mem_pageinfo = (pageinfo*)ROUNDUP((uint32_t)end, (uint32_t)sizeof(pageinfo));
  memset(mem_pageinfo, 0, sizeof(pageinfo)*mem_npage);
	pageinfo **freetail = &mem_freelist;
	int i;
	// Pages 0 and 1 are reserved.
	for (i = 2; i < mem_npage; i++) {           
    // All of base memory otherwise is free after the kernel
    // and the pageinfo table all memory should be free
    if(i < basemem/4096 ||          
      i >= (uint32_t)(ROUNDUP(&mem_pageinfo[mem_npage],4096))/4096) {
      // A free page has no references to it.
      mem_pageinfo[i].refcount = 0;
      // Add the page to the end of the free list.
      *freetail = &mem_pageinfo[i];
      freetail = &mem_pageinfo[i].free_next;
    }
	}
	*freetail = NULL;	// null-terminate the freelist
	// Check to make sure the page allocator seems to work correctly.
	mem_check();
}
Example #11
0
void
bin_test(void)
{
	int b, i;

	for(b=0; b<n_blocks; b++) {
		mutex_lock(&blocks[b].mutex);
		for(i=0; i<BINS_PER_BLOCK; i++) {
			if(mem_check(blocks[b].b[i].ptr, blocks[b].b[i].size)) {
				printf("memory corrupt!\n");
				exit(1);
			}
		}
		mutex_unlock(&blocks[b].mutex);
	}
}
Example #12
0
static void
_init(JxTuiEvent *in_event)
{
    /* configuration */
    g_edit_globals.max_line_size = EDIT_LIMIT_MAX_LINE_SIZE;

    /* loading a document */
    g_edit_globals.doc = edit_doc_open("/Users/josh/Desktop/test.txt");

    /* editor setup */
    edit_view_create();

    /* debugging */
    doc_debug(g_edit_globals.doc);

    mem_check();
}
int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen)
{
	int uninitialized_var(err);
	struct net *net = sock_net(sk);
	struct ipv6_pinfo *np = inet6_sk(sk);
	struct in6_flowlabel_req freq;
	struct ipv6_fl_socklist *sfl1=NULL;
	struct ipv6_fl_socklist *sfl, **sflp;
	struct ip6_flowlabel *fl, *fl1 = NULL;


	if (optlen < sizeof(freq))
		return -EINVAL;

	if (copy_from_user(&freq, optval, sizeof(freq)))
		return -EFAULT;

	switch (freq.flr_action) {
	case IPV6_FL_A_PUT:
		write_lock_bh(&ip6_sk_fl_lock);
		for (sflp = &np->ipv6_fl_list; (sfl=*sflp)!=NULL; sflp = &sfl->next) {
			if (sfl->fl->label == freq.flr_label) {
				if (freq.flr_label == (np->flow_label&IPV6_FLOWLABEL_MASK))
					np->flow_label &= ~IPV6_FLOWLABEL_MASK;
				*sflp = sfl->next;
				write_unlock_bh(&ip6_sk_fl_lock);
				fl_release(sfl->fl);
				kfree(sfl);
				return 0;
			}
		}
		write_unlock_bh(&ip6_sk_fl_lock);
		return -ESRCH;

	case IPV6_FL_A_RENEW:
		read_lock_bh(&ip6_sk_fl_lock);
		for (sfl = np->ipv6_fl_list; sfl; sfl = sfl->next) {
			if (sfl->fl->label == freq.flr_label) {
				err = fl6_renew(sfl->fl, freq.flr_linger, freq.flr_expires);
				read_unlock_bh(&ip6_sk_fl_lock);
				return err;
			}
		}
		read_unlock_bh(&ip6_sk_fl_lock);

		if (freq.flr_share == IPV6_FL_S_NONE && capable(CAP_NET_ADMIN)) {
			fl = fl_lookup(net, freq.flr_label);
			if (fl) {
				err = fl6_renew(fl, freq.flr_linger, freq.flr_expires);
				fl_release(fl);
				return err;
			}
		}
		return -ESRCH;

	case IPV6_FL_A_GET:
		if (freq.flr_label & ~IPV6_FLOWLABEL_MASK)
			return -EINVAL;

		fl = fl_create(net, sk, &freq, optval, optlen, &err);
		if (fl == NULL)
			return err;
		sfl1 = kmalloc(sizeof(*sfl1), GFP_KERNEL);

		if (freq.flr_label) {
			err = -EEXIST;
			read_lock_bh(&ip6_sk_fl_lock);
			for (sfl = np->ipv6_fl_list; sfl; sfl = sfl->next) {
				if (sfl->fl->label == freq.flr_label) {
					if (freq.flr_flags&IPV6_FL_F_EXCL) {
						read_unlock_bh(&ip6_sk_fl_lock);
						goto done;
					}
					fl1 = sfl->fl;
					atomic_inc(&fl1->users);
					break;
				}
			}
			read_unlock_bh(&ip6_sk_fl_lock);

			if (fl1 == NULL)
				fl1 = fl_lookup(net, freq.flr_label);
			if (fl1) {
recheck:
				err = -EEXIST;
				if (freq.flr_flags&IPV6_FL_F_EXCL)
					goto release;
				err = -EPERM;
				if (fl1->share == IPV6_FL_S_EXCL ||
				    fl1->share != fl->share ||
				    fl1->owner != fl->owner)
					goto release;

				err = -EINVAL;
				if (!ipv6_addr_equal(&fl1->dst, &fl->dst) ||
				    ipv6_opt_cmp(fl1->opt, fl->opt))
					goto release;

				err = -ENOMEM;
				if (sfl1 == NULL)
					goto release;
				if (fl->linger > fl1->linger)
					fl1->linger = fl->linger;
				if ((long)(fl->expires - fl1->expires) > 0)
					fl1->expires = fl->expires;
				fl_link(np, sfl1, fl1);
				fl_free(fl);
				return 0;

release:
				fl_release(fl1);
				goto done;
			}
		}
		err = -ENOENT;
		if (!(freq.flr_flags&IPV6_FL_F_CREATE))
			goto done;

		err = -ENOMEM;
		if (sfl1 == NULL || (err = mem_check(sk)) != 0)
			goto done;

		fl1 = fl_intern(net, fl, freq.flr_label);
		if (fl1 != NULL)
			goto recheck;

		if (!freq.flr_label) {
			if (copy_to_user(&((struct in6_flowlabel_req __user *) optval)->flr_label,
					 &fl->label, sizeof(fl->label))) {
				/* Intentionally ignore fault. */
			}
		}

		fl_link(np, sfl1, fl);
		return 0;

	default:
		return -EINVAL;
	}

done:
	fl_free(fl);
	kfree(sfl1);
	return err;
}
Example #14
0
File: mem.c Project: bhup99/PIOS
void
mem_init(void)
{
	if (!cpu_onboot())	// only do once, on the boot CPU
		return;

	// Determine how much base (<640K) and extended (>1MB) memory
	// is available in the system (in bytes),
	// by reading the PC's BIOS-managed nonvolatile RAM (NVRAM).
	// The NVRAM tells us how many kilobytes there are.
	// Since the count is 16 bits, this gives us up to 64MB of RAM;
	// additional RAM beyond that would have to be detected another way.
	size_t basemem = ROUNDDOWN(nvram_read16(NVRAM_BASELO)*1024, PAGESIZE);
	size_t extmem = ROUNDDOWN(nvram_read16(NVRAM_EXTLO)*1024, PAGESIZE);

	warn("Assuming we have 1GB of memory!");
	extmem = 1024*1024*1024 - MEM_EXT;	// assume 1GB total memory

	// The maximum physical address is the top of extended memory.
	mem_max = MEM_EXT + extmem;

	// Compute the total number of physical pages (including I/O holes)
	mem_npage = mem_max / PAGESIZE;

	cprintf("Physical memory: %dK available, ", (int)(mem_max/1024));
	cprintf("base = %dK, extended = %dK\n",
		(int)(basemem/1024), (int)(extmem/1024));


	// Insert code here to:
	// (1)	allocate physical memory for the mem_pageinfo array,
	//	making it big enough to hold mem_npage entries.
	// (2)	add all pageinfo structs in the array representing
	//	available memory that is not in use for other purposes.
	//
	// For step (2), here is some incomplete/incorrect example code
	// that simply marks all mem_npage pages as free.
	// Which memory is actually free?
	//  1) Reserve page 0 for the real-mode IDT and BIOS structures
	//     (do not allow this page to be used for anything else).
	//  2) Reserve page 1 for the AP bootstrap code (boot/bootother.S).
	//  3) Mark the rest of base memory as free.
	//  4) Then comes the IO hole [MEM_IO, MEM_EXT).
	//     Mark it as in-use so that it can never be allocated.      
	//  5) Then extended memory [MEM_EXT, ...).
	//     Some of it is in use, some is free.
	//     Which pages hold the kernel and the pageinfo array?
	//     Hint: the linker places the kernel (see start and end above),
	//     but YOU decide where to place the pageinfo array.
	// Change the code to reflect this.
	pageinfo **freetail = &mem_freelist;
	int i;
	for (i = 0; i < mem_npage; i++) {
		// A free page has no references to it.
		mem_pageinfo[i].refcount = 0;

		// Add the page to the end of the free list.
		*freetail = &mem_pageinfo[i];
		freetail = &mem_pageinfo[i].free_next;
	}
	*freetail = NULL;	// null-terminate the freelist

	// ...and remove this when you're ready.
	panic("mem_init() not implemented");

	// Check to make sure the page allocator seems to work correctly.
	mem_check();
}
Example #15
0
//Create new variable menu.
int create_var_menu(Variable *varArry, int *arrySize, int arrySpot){
	String type = (String)malloc(ARRAYLENGHT * sizeof (char));
	String name = (String)malloc(ARRAYLENGHT * sizeof (char));
	int flag;

	//Check if memory allocated properly.
	mem_check(type);
	mem_check(name);

	//Get the variable's type
	do{
		//User interaction.
		printf("%s", "\n\nGive the variable's type. Valid types are Integer, Decimal, String and Bool. To go back type <:");
		fgets(type, ARRAYLENGHT, stdin);
		
		flag = false;
		if (type[strlen(type) - 1] == '\n' && strlen(type) > 1){
			type[strcspn(type, "\n")] = 0; //Drop the \n from fgets input
			strtolower(type); //Convert the string to lowercase for ease of use.

			//Check for back input
			if (!strcmp(type, "<")){
				return false;
			}

			//Check for valid input.
			if (strcmp(type, "integer") && strcmp(type, "decimal") && strcmp(type, "string") && strcmp(type, "bool")){
				printf("%s", "\n\nInvalid type!\n\n");
			}
		}
		else{
			flag = true;
			printf("%s", "\n\nInvalid lenght. It must be between 1 and 255 characters!\n\n");
			if (strlen(type) > 1)
				clear_stdin(); //Clear stdin from extra input
		}
	
	} while (strcmp(type, "integer") && strcmp(type, "decimal") && strcmp(type, "string") && strcmp(type, "bool") || flag); //Loop until user decides to cooperate.

	//Get the variable's name.
	do{
		//User interaction.
		printf("%s", "\n\nGive a name for the variable. The max lenght is 255 characters. It can't contain whitespaces or symbols, except underscores (_):");
		fgets(name, ARRAYLENGHT, stdin);

		flag = false;
		//Check for valid lenght
		if (name[strlen(name) - 1] == '\n' && strlen(name) > 2){
			name[strcspn(name, "\n")] = 0; //Drop the \n from fgets input.

			//Check for valid input
			if (strpbrk(name, " !@#$%^&*()-+=\\|[]{};\':\",./<>?") != NULL){
				printf("%s", "\n\nInvalid name!\n\n");
			}
			else if (var_exist(varArry, name, *arrySize)){
				printf("%s", "\n\nA variable with that name already exists!\n\n");
			}
		}
		else{
			flag = true;
			printf("%s", "\n\nInvalid lenght. It must be between 1 and 255 characters!\n\n");
			if (strlen(name) > 1)
				clear_stdin(); //Clear stdin from extra input
		}
	} while (flag || strpbrk(name, " `~!@#$%^&*()-+=\\|[]{};\':\",./<>?") != NULL || var_exist(varArry, name, *arrySize)); //Loop until valid.

	//Copy the name and the type in the variables struct array.
	strcpy(varArry[arrySpot].type, type);
	strcpy(varArry[arrySpot].name, name);

	//Free the memory we don't need anymore.
	free(name);
	free(type);

	//Run the function corresponding to the entered type.
	if (!strcmp(varArry[arrySpot].type, "integer")){
		set_var_int(varArry, arrySpot);
	}
	else if (!strcmp(varArry[arrySpot].type, "decimal")){
		set_var_decimal(varArry, arrySpot);
	}
	else if (!strcmp(varArry[arrySpot].type, "string")){
		//Loop until the lenght is correct.
		do{
			//User interaction. For strings we don't need any valid input checks.
			printf("%s", "\n\nGive the variables value (String, 255 characters max):");
			fgets(varArry[arrySpot].value, ARRAYLENGHT, stdin);

			flag = false;
			if (varArry[arrySpot].value[strlen(varArry[arrySpot].value) - 1] == '\n')
				varArry[arrySpot].value[strcspn(varArry[arrySpot].value, "\n")] = 0; //Drop the \n from fgets input.
			else{
				flag = true;
				printf("%s", "\n\nInvalid lenght. It must be between 1 and 255 characters!\n\n");
				clear_stdin(); //Clear stdin from extra input
			}

		} while (flag);
	}
	else{
		set_var_bool(varArry, arrySpot);
	}

	return true;
}
Example #16
0
void createProcess(struct Process* process, EntryPoint entryPoint, struct Process* parent, char* args, int terminal, int kernel) {

    process->pid = ++pid;
    process->kernel = !!kernel;
    process->terminal = terminal;
    process->active = 0;

    process->parent = parent;
    process->firstChild = NULL;

    process->cycles = 0;
    process->curr_cycles = 0;
    process->prev_cycles = 0;
    process->timeStart = _time(NULL);

    process->uid = 0;
    process->gid = 0;
    if (parent != NULL) {
        process->uid = parent->uid;
        process->gid = parent->gid;
    }

    process->prev = NULL;
    if (parent == NULL) {
        process->ppid = 0;
        process->next = NULL;

        process->cwd = kalloc(2 * sizeof(char));
        strcpy(process->cwd, "/");
    } else {
        process->ppid = parent->pid;

        process->next = parent->firstChild;
        if (parent->firstChild) {
            parent->firstChild->prev = process;
        }

        parent->firstChild = process;

        process->cwd = kalloc(strlen(parent->cwd) + 1);
        strcpy(process->cwd, parent->cwd);
    }

    process->entryPoint = entryPoint;
    if (args == NULL) {
        process->args[0] = 0;
    } else {
        int i;
        for (i = 0; *(args + i) && i < ARGV_SIZE - 1; i++) {
            process->args[i] = args[i];
        }
        process->args[i] = 0;
    }

    process->schedule.priority = 2;
    process->schedule.status = StatusReady;
    process->schedule.inWait = 0;
    process->schedule.ioWait = 0;
    process->schedule.done = 0;

    for (size_t i = 0; i < MAX_OPEN_FILES; i++) {

        if (parent && parent->fdTable[i].inode) {
            fs_dup(&process->fdTable[i], parent->fdTable[i]);
        } else {
            process->fdTable[i].inode = NULL;
        }
    }

    {
        process->mm.pagesInKernelStack = KERNEL_STACK_PAGES;
        struct Pages* mem = reserve_pages(process, process->mm.pagesInKernelStack);
        assert(mem != NULL);

        process->mm.esp0 = (char*)mem->start + PAGE_SIZE * process->mm.pagesInKernelStack;
        process->mm.kernelStack = process->mm.esp0;
    }

    if (kernel) {
        process->mm.pagesInHeap = 0;
        process->mm.mallocContext = NULL;
    } else {
        process->mm.pagesInHeap = 256;
        struct Pages* mem = reserve_pages(process, process->mm.pagesInHeap);
        assert(mem != NULL);

        process->mm.mallocContext = mm_create_context(mem->start, process->mm.pagesInHeap * PAGE_SIZE);
        mem_check();
    }

    if (!kernel) {
        process->mm.pagesInStack = 16;
        struct Pages* mem = reserve_pages(process, process->mm.pagesInStack);
        assert(mem != NULL);

        process->mm.esp = (char*)mem->start + PAGE_SIZE * process->mm.pagesInStack;
    } else {
        process->mm.pagesInStack = 0;
        process->mm.esp = NULL;
    }

    setup_page_directory(process, kernel);

    if (!kernel) {
        struct Pages* ungetPage = reserve_pages(process, 1);
        assert(ungetPage != NULL);
        mm_pagination_map(process, (unsigned int)ungetPage->start, (unsigned int)STACK_TOP_MAPPING, 1, 1, 1);
        FILE* files;
        
        for (int i = 0; i < 3; i++) {
            files = ungetPage->start + i * sizeof(FILE);
            files->fd = i;
            files->flag = 0;
            files->unget = 0;
        }
    }

    int codeSegment, dataSegment;
    if (kernel) {
        codeSegment = KERNEL_CODE_SEGMENT;
        dataSegment = KERNEL_DATA_SEGMENT;

        char* esp0 = (char*) process->mm.esp0 - ARGV_SIZE;
        for (size_t i = 0; i < ARGV_SIZE; i++) {
            esp0[i] = process->args[i];
        }
        process->mm.esp0 = esp0;

        push((unsigned int**) &process->mm.esp0, (unsigned int) process->mm.esp0);
        push((unsigned int**) &process->mm.esp0, (unsigned int) exit);
        push((unsigned int**) &process->mm.esp0, 0x202);
    } else {
        codeSegment = USER_CODE_SEGMENT;
        dataSegment = USER_DATA_SEGMENT;

        char* esp = (char*) process->mm.esp - ARGV_SIZE;
        for (size_t i = 0; i < ARGV_SIZE; i++) {
            esp[i] = process->args[i];
        }
        process->mm.esp = esp;

        push((unsigned int**) &process->mm.esp, STACK_TOP_MAPPING - ARGV_SIZE);
        push((unsigned int**) &process->mm.esp, (unsigned int) exit);

        push((unsigned int**) &process->mm.esp0, dataSegment);
        push((unsigned int**) &process->mm.esp0, STACK_TOP_MAPPING - 2 * sizeof(int) - ARGV_SIZE);
        push((unsigned int**) &process->mm.esp0, 0x3202);
    }

    push((unsigned int**) &process->mm.esp0, codeSegment);
    push((unsigned int**) &process->mm.esp0, (unsigned int) entryPoint);
    push((unsigned int**) &process->mm.esp0, dataSegment);
    push((unsigned int**) &process->mm.esp0, dataSegment);
    push((unsigned int**) &process->mm.esp0, dataSegment);
    push((unsigned int**) &process->mm.esp0, dataSegment);
    push((unsigned int**) &process->mm.esp0, (unsigned int) _interruptEnd);
    push((unsigned int**) &process->mm.esp0, (unsigned int) signalPIC);
    push((unsigned int**) &process->mm.esp0, 0);
}
Example #17
0
void jpeg_decode (byte *data, int size, byte *dest, int line_bytes, int bpp,
                  int max_width, int max_height)
   {
   struct jpeg_decompress_struct cinfo;
   JSAMPARRAY buffer;/* Output row buffer */
   jpeg_source_info source;
   int tile_bytes;
   struct my_error_mgr jerr;

   jpeg_create_decompress(&cinfo);
   cinfo.err = jpeg_std_error(&jerr.mgr);

   cinfo.src = &source.pub;
//   source.max = max;
//   source.chunk = chunk;
   source.data = data;
   source.size = size;
   source.done = FALSE;
//   source.pos = pos;
   source.pub.init_source = init_source;
   source.pub.fill_input_buffer = fill_input_buffer;
   source.pub.skip_input_data = skip_input_data;
   source.pub.resync_to_restart = jpeg_resync_to_restart;/* use default method */
   source.pub.term_source = term_source;
   source.pub.bytes_in_buffer = 0;   /* forces fill_input_buffer on first read */
   source.pub.next_input_byte = NULL;/* until buffer loaded */

   cinfo.err = jpeg_std_error(&jerr.mgr);
   jerr.err = 0;
   jerr.mgr.error_exit = my_error_exit;
   if (!setjmp(jerr.setjmp_buffer))
      {
      jpeg_read_header(&cinfo, TRUE);
      jpeg_start_decompress(&cinfo);

      /* Make a one-row-high sample array that will go away when done with image */
      tile_bytes = cinfo.output_width * cinfo.output_components;
      buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, tile_bytes, 1);

//      printf ("width = %d, tile_bytes = %d, line_bytes = %d\n",
//         cinfo.output_width, tile_bytes, line_bytes);

      while (cinfo.output_scanline < cinfo.output_height &&
             cinfo.output_scanline < max_height)
         {
         jpeg_read_scanlines(&cinfo, buffer, 1);
         if (cinfo.output_components == 3 && bpp == 32)
            {
            byte *in;
            u_int32_t *out;
            int i;

            mem_check ();
            in = (byte *)buffer [0];
            i = cinfo.output_width;
            if (max_width != -1 && i > max_width)
                i = max_width;
            for (out = (u_int32_t *)dest; i != 0;
                 i--, in += 3)
               *out++ = in [2] | (in [1] << 8) | (in [0] << 16);
            mem_check ();
            }
         else
            memcpy (dest, buffer[0], tile_bytes);
         dest += line_bytes;
         }
//       debug1 (("width = %d, tile_bytes = %d, line_bytes = %d, decoded %d lines\n",
//          cinfo.output_width, tile_bytes, line_bytes, cinfo.output_height));

      jpeg_finish_decompress(&cinfo);
      }
   jpeg_destroy_decompress(&cinfo);
   if (jerr.err)
      printf ("error = %d\n", jerr.err);
   }
Example #18
0
int main(int argc, char * argv[])
{
  int policy; /* replacement policy */
  int current;  /* current page accessed */
  FILE * fp; /* The file containing the page accesses */
  FILE * rp; /* output file */
  char filename[30]={""};
  const char * extension[] ={".fifo", ".lru", "new"};
  float num_accesses = 0.0; /* total number of page accesses */
  float page_faults = 0.0;
  unsigned victim = 0;  /* page to be replaced */
  
  /* Getting and checking the input from the command line */
  if(argc != 4)
  {
    printf("usage: pager policy size filename\n");
    exit(1);
  }
  
  policy = atoi(argv[1]);
  mem_size = atoi(argv[2]);
  
  if( policy < 0 || policy > 2)
  { 
    printf("policy must be 0, 1, or 2\n");
    exit(1);
  }
  
  if(mem_size <= 0 )
  {
    printf("Size must be a positive integer.\n");
    exit(1);
  }
  
  /* Allocate and initialize the memory */
  mem = (int *)calloc(mem_size, sizeof(int));
  if(!mem)
  {
    printf("Cannot allocate mem\n");
    exit(1);
  }
  
  /* open the memory access file */
  fp = fopen(argv[3], "r");
  if(!fp)
  {
    printf("Cannot open file %s\n", argv[3]);
    exit(1);
  }
  
  /* Create the output file */
  strcat(filename, argv[3]);
  strcat(filename,extension[policy]);
  rp = fopen(filename, "w");
  if(!rp)
  {
    printf("Cannot create file %s\n", filename);
    exit(1);
  }
  
  /* The main loop of the program */
  fscanf(fp,"%d", &current);
  while(!feof(fp))
  {
    num_accesses++;
    if(mem_check(current) == PAGEMISS)
      page_faults++;
    
    switch(policy)
    {
      case 0: if( IsFull())
	      {
		victim = fifo();
		mem[victim] = current;
	      }
	      else
		insert(current);
	      break;
	     
      case 1: if( IsFull())
	      {
		victim = lru();
		mem[victim] = current;
	      }
	      else
		insert(current);
	      break;
	      
      case 2: if( IsFull())
	      {
		victim = own();
		mem[victim] = current;
	      }
	      else
		insert(current);
	      break;
	      
	      
      default: printf("Unknown policy ... Exiting\n");
	       exit(1);
      
    }/* end switch-case */
    
    print_mem(rp);
    fscanf(fp,"%d", &current);

  }/* end while */
  fprintf(rp,"percentage of page faults = %f", page_faults/num_accesses);
  
  /* wrap-up */
  fclose(fp);
  fclose(rp);
  free(mem);
  
  return 1;

}
Example #19
0
int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen)
{
	int uninitialized_var(err);
	struct net *net = sock_net(sk);
	struct ipv6_pinfo *np = inet6_sk(sk);
	struct in6_flowlabel_req freq;
	struct ipv6_fl_socklist *sfl1 = NULL;
	struct ipv6_fl_socklist *sfl;
	struct ipv6_fl_socklist __rcu **sflp;
	struct ip6_flowlabel *fl, *fl1 = NULL;


	if (optlen < sizeof(freq))
		return -EINVAL;

	if (copy_from_user(&freq, optval, sizeof(freq)))
		return -EFAULT;

	switch (freq.flr_action) {
	case IPV6_FL_A_PUT:
		if (freq.flr_flags & IPV6_FL_F_REFLECT) {
			if (sk->sk_protocol != IPPROTO_TCP)
				return -ENOPROTOOPT;
			if (!np->repflow)
				return -ESRCH;
			np->flow_label = 0;
			np->repflow = 0;
			return 0;
		}
		spin_lock_bh(&ip6_sk_fl_lock);
		for (sflp = &np->ipv6_fl_list;
		     (sfl = rcu_dereference(*sflp)) != NULL;
		     sflp = &sfl->next) {
			if (sfl->fl->label == freq.flr_label) {
				if (freq.flr_label == (np->flow_label&IPV6_FLOWLABEL_MASK))
					np->flow_label &= ~IPV6_FLOWLABEL_MASK;
				*sflp = rcu_dereference(sfl->next);
				spin_unlock_bh(&ip6_sk_fl_lock);
				fl_release(sfl->fl);
				kfree_rcu(sfl, rcu);
				return 0;
			}
		}
		spin_unlock_bh(&ip6_sk_fl_lock);
		return -ESRCH;

	case IPV6_FL_A_RENEW:
		rcu_read_lock_bh();
		for_each_sk_fl_rcu(np, sfl) {
			if (sfl->fl->label == freq.flr_label) {
				err = fl6_renew(sfl->fl, freq.flr_linger, freq.flr_expires);
				rcu_read_unlock_bh();
				return err;
			}
		}
		rcu_read_unlock_bh();

		if (freq.flr_share == IPV6_FL_S_NONE &&
		    ns_capable(net->user_ns, CAP_NET_ADMIN)) {
			fl = fl_lookup(net, freq.flr_label);
			if (fl) {
				err = fl6_renew(fl, freq.flr_linger, freq.flr_expires);
				fl_release(fl);
				return err;
			}
		}
		return -ESRCH;

	case IPV6_FL_A_GET:
		if (freq.flr_flags & IPV6_FL_F_REFLECT) {
			struct net *net = sock_net(sk);
			if (net->ipv6.sysctl.flowlabel_consistency) {
				net_info_ratelimited("Can not set IPV6_FL_F_REFLECT if flowlabel_consistency sysctl is enable\n");
				return -EPERM;
			}

			if (sk->sk_protocol != IPPROTO_TCP)
				return -ENOPROTOOPT;

			np->repflow = 1;
			return 0;
		}

		if (freq.flr_label & ~IPV6_FLOWLABEL_MASK)
			return -EINVAL;

		fl = fl_create(net, sk, &freq, optval, optlen, &err);
		if (!fl)
			return err;
		sfl1 = kmalloc(sizeof(*sfl1), GFP_KERNEL);

		if (freq.flr_label) {
			err = -EEXIST;
			rcu_read_lock_bh();
			for_each_sk_fl_rcu(np, sfl) {
				if (sfl->fl->label == freq.flr_label) {
					if (freq.flr_flags&IPV6_FL_F_EXCL) {
						rcu_read_unlock_bh();
						goto done;
					}
					fl1 = sfl->fl;
					atomic_inc(&fl1->users);
					break;
				}
			}
			rcu_read_unlock_bh();

			if (!fl1)
				fl1 = fl_lookup(net, freq.flr_label);
			if (fl1) {
recheck:
				err = -EEXIST;
				if (freq.flr_flags&IPV6_FL_F_EXCL)
					goto release;
				err = -EPERM;
				if (fl1->share == IPV6_FL_S_EXCL ||
				    fl1->share != fl->share ||
				    ((fl1->share == IPV6_FL_S_PROCESS) &&
				     (fl1->owner.pid == fl->owner.pid)) ||
				    ((fl1->share == IPV6_FL_S_USER) &&
				     uid_eq(fl1->owner.uid, fl->owner.uid)))
					goto release;

				err = -ENOMEM;
				if (!sfl1)
					goto release;
				if (fl->linger > fl1->linger)
					fl1->linger = fl->linger;
				if ((long)(fl->expires - fl1->expires) > 0)
					fl1->expires = fl->expires;
				fl_link(np, sfl1, fl1);
				fl_free(fl);
				return 0;

release:
				fl_release(fl1);
				goto done;
			}
		}
		err = -ENOENT;
		if (!(freq.flr_flags&IPV6_FL_F_CREATE))
			goto done;

		err = -ENOMEM;
		if (!sfl1)
			goto done;

		err = mem_check(sk);
		if (err != 0)
			goto done;

		fl1 = fl_intern(net, fl, freq.flr_label);
		if (fl1)
			goto recheck;

		if (!freq.flr_label) {
			if (copy_to_user(&((struct in6_flowlabel_req __user *) optval)->flr_label,
					 &fl->label, sizeof(fl->label))) {
				/* Intentionally ignore fault. */
			}
		}

		fl_link(np, sfl1, fl);
		return 0;

	default:
		return -EINVAL;
	}