Ejemplo n.º 1
0
void AddStructRef( Unions *thisunion, Structs *stref)
{   Strefs *temp = HEAP( Strefs);

    StrefStr(temp) = stref;
    StrefNext(temp) = NULL;
    AddToStrefList( temp, UnionStrefs( thisunion));
}
Ejemplo n.º 2
0
ListNode *CreateList()
{   ListNode *list = HEAP(ListNode);

    ListSize(list) = 0;
    ListHead(list) = ListTail(list) = NULL;
    return(list);
}
Ejemplo n.º 3
0
static int checkFreeList( unsigned long *free_size )
{
    __segment           seg;
    FRLPTR( seg )       frl;
    unsigned long       total_size;

    total_size = 0;
    for( seg = __fheapbeg; seg != _NULLSEG; seg = HEAP( seg )->nextseg ) {
        __fheapchk_current = frl = HEAP( seg )->freehead.next;
        while( (unsigned)frl != offsetof( heapblk, freehead ) ) {
            total_size += frl->len;
            __fheapchk_current = frl = frl->next;
        }
    }
    *free_size = total_size;
    return( _HEAPOK );
}
Ejemplo n.º 4
0
Enumerateds *CreateEnumerated( char *name, int value )
{   Enumerateds *enumerated = HEAP(Enumerateds);

    EnumeratedName(enumerated) = Initialise(name);
    EnumeratedValue(enumerated) = value;
    EnumeratedNext(enumerated) = NULL;
    return(enumerated);
}
Ejemplo n.º 5
0
Primitives *CreatePrimitive( char *name)
{   Primitives *prim = HEAP(Primitives);

    PrimitiveName( prim) = heapstr(name);
    PrimitiveDefined( prim) = FALSE;
    PrimitiveValues( prim) = CreateList();
    PrimitiveNext( prim) = NULL;
    return( prim);
}
Ejemplo n.º 6
0
Macros *CreateMacro( char *name, char *field, int pos )
{   Macros *macro = HEAP(Macros);

    MacroName(macro) = Initialise(name);   /* This calls heaps its result */
    MacroField(macro) = Initialise(field);
    MacroPos(macro) = pos;
    MacroNext(macro) = NULL;
    return(macro);
}
Ejemplo n.º 7
0
Unions *CreateUnion(char *name, int token)
{   Unions *a_union = HEAP(Unions);

    UnionName(a_union) = heapstr(name);
    UnionDefined(a_union) = FALSE;
    UnionToken(a_union) = token;
    UnionStrefs(a_union) = CreateList();
    UnionNext(a_union) = NULL;
    return(a_union);
}
Ejemplo n.º 8
0
Sort *CreateSort()
{   Sort *sort_node = HEAP(Sort);

    SortValue(sort_node) = NULL;
    SortBase(sort_node) = NULL;
    SortNext(sort_node) = NULL;
    SortHasvec(sort_node) = 0;
    SortHassec(sort_node) = 0;
    return(sort_node);
}
Ejemplo n.º 9
0
_WCRTLINK int _bfreeseg( __segment seg )
{
    __segment       next_seg;
    __segment       prev_seg;

    _AccessFHeap();
    /* unlink from heap list */
    prev_seg = HEAP( seg )->prevseg;
    next_seg = HEAP( seg )->nextseg;
    if( next_seg != _NULLSEG ) {
        HEAP( next_seg )->prevseg = prev_seg;
    }
    if( prev_seg == _NULLSEG ) {
        __bheapbeg = next_seg;
    } else {
        HEAP( prev_seg )->nextseg = next_seg;
    }
    _ReleaseFHeap();
    return( __FreeSeg( seg ) );
}
Ejemplo n.º 10
0
/*
 * Heapsort -- Knuth, Vol. 3, page 145.  Runs in O (N lg N), both average
 * and worst.  While heapsort is faster than the worst case of quicksort,
 * the BSD quicksort does median selection so that the chance of finding
 * a data set that will trigger the worst case is nonexistent.  Heapsort's
 * only advantage over quicksort is that it requires no additional memory.
 */
void heapsort(void *bot, size_t nmemb)
/*	register void *bot;
	register size_t nmemb, size;
	int (*compar) __P((const void *, const void *)); */
{
	register char *p, *t;
	register size_t i, j, l;
    const size_t size = sizeof(Element);

	if (nmemb <= 1)
		return;
	if (!size) {
		return;
	}
	/*
	 * Items are numbered from 1 to nmemb, so offset from size bytes
	 * below the starting address.
	 */
    bot = (void *) (((char *) bot) - size);

	for (l = nmemb / 2 + 1; --l;)
		HEAP(l);

	/*
	 * For each element of the heap, save the largest element into its
	 * final slot, then recreate the heap.
	 */
	while (nmemb > 1) {
		p = (char *)bot + size;
		t = (char *)bot + nmemb * size;
		swap_memory(p, t, size);
		--nmemb;
		HEAP(1);
	}
	return;
}
Ejemplo n.º 11
0
_WCRTLINK int _bheapset( __segment seg, unsigned int fill )
{
    int         heap_status;

    if( seg == _DGroup() )
        return( _nheapset( fill ) );
    if( seg == _NULLSEG ) {
        for( seg = __bheapbeg; seg != _NULLSEG; seg = HEAP( seg )->nextseg ) {
            heap_status = _bheapset( seg, fill );
            if( heap_status != _HEAPOK ) {
                return( heap_status );
            }
        }
        return( _HEAPOK );
    }
    heap_status = _bheapchk( seg );
    if( heap_status != _HEAPOK )
        return( heap_status );
    return( __HeapSet( seg, fill ) );
}
Ejemplo n.º 12
0
Structs *CreateStruct(char *name, int token)
{   Structs *a_struct;

    if (token < FIRST_SORT)
    {   a_struct = HEAP(Structs);
        StructName(a_struct) = heapstr(name);
        StructDefined(a_struct) = FALSE;
        StructToken(a_struct) = token;
        StructUnion_sorts(a_struct) = CreateList();
        StructChildren_sorts(a_struct) = CreateList();
        StructChildren_names(a_struct) = CreateList();
        StructNext(a_struct) = NULL;
    }
    else
    {   fprintf( stderr,
                 "Not enough tokens for structs - change union start token\n");
        exit(EXIT_FAILURE);
    }
    return(a_struct);
}
Ejemplo n.º 13
0
/*
 * Executes a program.
 */
PUBLIC int sys_execve(const char *filename, const char **argv, const char **envp)
{
	int i;                /* Loop index.          */
	struct inode *inode;  /* File inode.          */
	struct region *reg;   /* Process region.      */
	addr_t entry;         /* Program entry point. */
	addr_t sp;            /* User stack pointer.  */
	char *name;           /* File name.           */
	char stack[ARG_MAX];  /* Stack size.          */

	/* Get file name. */
	if ((name = getname(filename)) == NULL)
		return (curr_proc->errno);

	/* Build arguments before freeing user memory. */
	kmemset(stack, 0, ARG_MAX);
	if (!(sp = buildargs(stack, ARG_MAX, argv, envp)))
	{
		putname(name);
		return (curr_proc->errno);
	}

	/* Get file's inode. */
	if ((inode = inode_name(name)) == NULL)
	{
		putname(name);
		return (curr_proc->errno);
	}

	/* Not a regular file. */
	if (!S_ISREG(inode->mode))
	{
		putname(name);
		inode_put(inode);
		return (-EACCES);
	}

	/* Not allowed. */
	if (!permission(inode->mode, inode->uid, inode->gid, curr_proc, MAY_EXEC, 0))
	{
		putname(name);
		inode_put(inode);
		return (-EACCES);
	}

	/* Close file descriptors. */
	for (i = 0; i < OPEN_MAX; i++)
	{
		if (curr_proc->close & (1 << i))
			do_close(i);
	}

	/* Detach process memory regions. */
	for (i = 0; i < NR_PREGIONS; i++)
		detachreg(curr_proc, &curr_proc->pregs[i]);
	
	/* Reset signal handlers. */
	curr_proc->restorer = NULL;
	for (i = 0; i < NR_SIGNALS; i++)
	{
		if (curr_proc->handlers[i] != SIG_DFL)
		{
			if (curr_proc->handlers[i] != SIG_IGN)
				curr_proc->handlers[i] = SIG_DFL;
		}
	}
	
	/* Load executable. */
	if (!(entry = load_elf32(inode)))
		goto die0;

	/* Attach stack region. */
	if ((reg = allocreg(S_IRUSR | S_IWUSR, PAGE_SIZE, REGION_DOWNWARDS)) == NULL)
		goto die0;
	if (attachreg(curr_proc, STACK(curr_proc), USTACK_ADDR - 1, reg))
		goto die1;
	unlockreg(reg);

	/* Attach heap region. */
	if ((reg = allocreg(S_IRUSR | S_IWUSR, PAGE_SIZE, REGION_UPWARDS)) == NULL)
		goto die0;
	if (attachreg(curr_proc, HEAP(curr_proc), UHEAP_ADDR, reg))
		goto die1;
	unlockreg(reg);
	
	inode_put(inode);
	putname(name);

	kmemcpy((void *)(USTACK_ADDR - ARG_MAX), stack, ARG_MAX);
	
	user_mode(entry, sp);
	
	/* Will not return. */
	return (0);

die1:
	unlockreg(reg);
	freereg(reg);
die0:
	inode_put(inode);
	putname(name);
	die(((SIGSEGV & 0xff) << 16) | (1 << 9));
	return (-1);
}