Beispiel #1
0
void
kmain( void* mdb,u32i magic )
{
	if( magic != 0x2BADB002 )
	{
		while(1);
	}
	InitDescriptorTables();
	VideoInit();
	SetColor(BLACK,BRIGHT_WHITE);
	KPrintf("This is Atomic Kernel 12715A\n");
	KPrintf("Starting Timer...");
	InitTimer(100);
	KPrintf("Done.\n");
	KPrintf("Starting Keyboard...");
	InitKeyboard();
	KPrintf("Done.\n");
	KPrintf("Starting Paging...");
	InitialisePaging();
	KPrintf("Done.\n");
	KPrintf("Starting Heap...");
	HeapInit();
	KPrintf("Done.\n");
	u32i *A,*B,*C;
	A = Kmalloc(8);
	B = Kmalloc(8);
	KPrintf("A:%x,B:%x",A,B);
	KFree(A);
	KFree(B);
	C = Kmalloc(16);
	KPrintf("C:%x\n",C);
	while(1);
}
Beispiel #2
0
struct Mount *AllocAssign (char *alias, char *path)
{
    struct Mount *assign;
    int alias_len;


    alias_len = StrLen (alias) + 1;

    if ((assign = KMalloc (sizeof (struct Mount))) != NULL)
    {
        if ((assign->name = KMalloc (alias_len)) != NULL)
        {
            StrLCpy (assign->name, alias, alias_len);

            if (ValidAlias (assign->name) == 0)
            {
                if ((assign->pathname = TranslatePathnameAliases (path)) != NULL)
                {
                    assign->type = MOUNT_ASSIGN;

                    AddMount (assign);

                    return assign;
                }
            }

            KFree (assign->name);
        }

        KFree (assign);
    }


    return NULL;
}
Beispiel #3
0
int CreatePathInfo (struct PathInfo *pi, char *pathname, bool keep_canon)
{
    pi->buffer = NULL;
    pi->canon = NULL;


    if ((pi->canon = CanonPathname(pathname)) != NULL)
    {
        if ((pi->buffer = TranslatePathnameAliases (pi->canon)) != NULL)
        {
            if (InitPathInfo (pi) == 0)
            {
                KPRINTF ("pi->canon = %s", pi->canon);

                if (keep_canon != KEEP_CANON)
                {
                    KFree (pi->canon);
                    pi->canon = NULL;
                }

                return 0;
            }

            KFree (pi->buffer);
        }

        KFree (pi->canon);
    }

    SetError (ENOENT);
    return -1;
}
Beispiel #4
0
void FreeAssign (struct Mount *assign)
{
    RemMount (assign);
    KFree (assign->name);
    KFree (assign->pathname);
    KFree (assign);
}
Beispiel #5
0
static void MPIData_extend(KonohaContext *kctx, kMPIData *p, int size) {
	size_t newSize = p->offset + size;
	if(p->size < newSize) {
		switch(p->typeId) {
		case KMPI_BYTES: {
			kBytes *b = (kBytes *)KLIB new_kObjectDontUseThis(kctx, CT_Bytes, (uintptr_t)newSize, OnStack);
			memcpy(b->buf, p->b->buf, p->size);
			p->b = b;
			p->size = newSize;
			break;
		}
		case KMPI_FARRAY: {
			kfloat_t *fa = KCalloc_UNTRACE(sizeof(kfloat_t), newSize);
			memcpy(fa, p->fa, p->size * sizeof(kfloat_t));
			KFree(p->fa, p->size * sizeof(kfloat_t));
			p->fa = fa;
			p->size = newSize;
			break;
		}
		case KMPI_IARRAY: {
			kint_t *ia = KCalloc_UNTRACE(sizeof(kint_t), newSize);
			memcpy(ia, p->ia, p->size * sizeof(kint_t));
			KFree(p->ia, p->size * sizeof(kint_t));
			p->ia = ia;
			p->size = newSize;
			break;
		}
		default:
			abort();
		}
	}
}
Beispiel #6
0
void FreePathInfo (struct PathInfo *pi)
{
    if (pi->canon != NULL)
        KFree (pi->canon);

    KFree (pi->buffer);
}
Beispiel #7
0
static void KRuntimeContext_Free(KonohaContext *kctx, KonohaContextVar *ctx)
{
	if(ctx->stack->evaljmpbuf != NULL) {
		KFree(ctx->stack->evaljmpbuf, sizeof(jmpbuf_i));
	}
	KLIB KArray_Free(kctx, &ctx->stack->cwb);
	KFree(ctx->stack->stack, sizeof(KonohaStack) * ctx->stack->stacksize);
	KFree(ctx->stack, sizeof(KRuntimeContextVar));
}
OVS_ARGUMENT* CreateArgFromPacketInfo(const OVS_OFPACKET_INFO* pPacketInfo, const OVS_OFPACKET_INFO* pMask, UINT16 groupType)
{
    OVS_ARGUMENT_SLIST_ENTRY* pList = NULL;
    UINT16 count = 0;
    UINT size = 0;
    OVS_ARGUMENT* args = NULL, *pResult = NULL;
    OVS_ARGUMENT_GROUP* pArgGroup = NULL;

    pList = _CreateArgListFromPacketInfo(pPacketInfo, pMask);
    if (!pList)
    {
        DEBUGP(LOG_ERROR, __FUNCTION__ " _CreateArgListFromPacketInfo failed\n");
        return NULL;
    }

    args = ArgumentListToArray(pList, &count, &size);
    if (!args)
    {
        DEBUGP(LOG_ERROR, __FUNCTION__ " could not convert arg list to array\n");
        DestroyOrFreeArgList(&pList, /*destroy*/ TRUE);
        return NULL;
    }

    OVS_CHECK(size <= MAXUINT16);

    pArgGroup = KZAlloc(sizeof(OVS_ARGUMENT_GROUP));
    if (!pArgGroup)
    {
        DEBUGP(LOG_ERROR, __FUNCTION__ " failed allocating arg group\n");

        DestroyOrFreeArgList(&pList, /*destroy*/ TRUE);
        KFree(args);
        return NULL;
    }

    pArgGroup->args = args;
    pArgGroup->count = count;
    pArgGroup->groupSize = (UINT16)size;

    pResult = CreateArgumentFromGroup(groupType, pArgGroup);
    if (!pResult)
    {
        DEBUGP(LOG_ERROR, "CreateArgumentFromGroup failed\n");
        DestroyOrFreeArgList(&pList, /*destroy*/ TRUE);
        KFree(args);
        return NULL;
    }

    DBGPRINT_ARG(LOG_INFO, pResult, 0, 0);

    DestroyOrFreeArgList(&pList, /*destroy*/ FALSE);

    VerifyGroup_Size_Recursive(pArgGroup);

    return pResult;
}
VOID DbgPrintArg(ULONG logLevel, _In_ OVS_ARGUMENT* pArg, int depth, int index)
{
    char* padding = NULL;

    OVS_CHECK(pArg);
    OVS_CHECK(depth >= 0);

    padding = KAlloc(depth + 1);
    if (!padding)
    {
        return;
    }

    memset(padding, '\t', depth);
    padding[depth] = 0;

    DbgPrintArgType(logLevel, pArg->type, padding, index);
    DEBUGP_ARG(logLevel, "%ssize: 0x%x\n", padding, pArg->length);

    if (IsArgTypeGroup(pArg->type))
    {
        ++depth;
        DbgPrintArgGroup(logLevel, pArg->data, depth);
    }

    KFree(padding);
}
static BOOLEAN _CreateActionsGroupToList(OVS_ARGTYPE groupType, const OVS_ARGUMENT_GROUP* pArgGroup, OVS_ARGUMENT_SLIST_ENTRY** ppArgList)
{
    OVS_ARGUMENT_SLIST_ENTRY* pCurListArg = NULL, *pHeadArg = NULL;
    OVS_ARGUMENT* pGroupArg = NULL;
    BOOLEAN ok = TRUE;

    pHeadArg = KZAlloc(sizeof(OVS_ARGUMENT_SLIST_ENTRY));
    if (!pHeadArg)
    {
        return FALSE;
    }

    pCurListArg = pHeadArg;
    ok = _CreateActionsArgsToList(pArgGroup, &pCurListArg);
    if (!ok)
    {
        return FALSE;
    }

    pGroupArg = CreateGroupArgFromList(groupType, &pHeadArg);
    if (!pGroupArg)
    {
        KFree(pHeadArg);
        return FALSE;
    }

    ok = AppendArgumentToList(pGroupArg, ppArgList);
    if (!ok)
    {
        return FALSE;
    }

    return TRUE;
}
VOID DbgPrintArgGroup(ULONG logLevel, _In_ OVS_ARGUMENT_GROUP* pGroup, int depth)
{
    char* padding = NULL;

    OVS_CHECK(pGroup);
    OVS_CHECK(depth >= 0);

    padding = KAlloc(depth + 1);
    if (!padding)
    {
        return;
    }

    memset(padding, '\t', depth);
    padding[depth] = 0;

    DEBUGP_ARG(logLevel, "%sgroup: count=0x%x; size=0x%x\n", padding, pGroup->count, pGroup->groupSize);

    for (UINT i = 0; i < pGroup->count; ++i)
    {
        DbgPrintArg(logLevel, pGroup->args + i, depth + 1, i);
    }

    DEBUGP_ARG(logLevel, "\n");

    KFree(padding);
}
Beispiel #12
0
static void FreeVirtualCode(KonohaContext *kctx, struct KVirtualCode *vcode)
{
	OPTHCODE *opTHCODE = (OPTHCODE *)(vcode - 1);
	if(opTHCODE->opcode == OPCODE_THCODE && opTHCODE->codesize > 0) {
		KFree(opTHCODE, opTHCODE->codesize);
	}
}
static void kKonohaFactory_Free(KonohaContext *kctx, kObject *o)
{
	struct kKonohaFactoryVar *f = (struct kKonohaFactoryVar *)o;
	if(f->factory != NULL) {
		KFree(f->factory, sizeof(KonohaFactory));
	}
}
VOID DestroyArgumentGroup(_In_ OVS_ARGUMENT_GROUP* pGroup)
{
    if (pGroup)
    {
        DestroyArguments(pGroup->args, pGroup->count);
        KFree(pGroup);
    }
}
VOID DestroyArgument(_In_ OVS_ARGUMENT* pArg)
{
    if (pArg)
    {
        DestroyArgumentData(pArg);
        KFree(pArg);
    }
}
Beispiel #16
0
static void SockAddr_Free(KonohaContext *kctx, kObject *o)
{
	struct _kSockAddr *sa = (struct _kSockAddr *)o;
	if(sa->sockaddr_in != NULL) {
		KFree(sa->sockaddr_in, sizeof(struct sockaddr_in));
		sa->sockaddr_in = NULL;
	}
}
Beispiel #17
0
static void kBytes_Free(KonohaContext *kctx, kObject *o)
{
	struct kBytesVar *ba = (struct kBytesVar *)o;
	if(ba->byteptr != NULL) {
		KFree(ba->buf, ba->bytesize);
		ba->byteptr = NULL;
		ba->bytesize = 0;
	}
}
Beispiel #18
0
static struct KGammaLocalData *kNameSpace_PopGamma(KonohaContext *kctx, kNameSpace *ns, struct KGammaLocalData *oldone, struct KGammaLocalData *checksum)
{
	struct KGammaLocalData *newone = ns->genv;
	assert(checksum == newone);
	ns->genv = oldone;
	if(newone->localScope.allocsize > 0) {
		KFree(newone->localScope.varItems, newone->localScope.allocsize);
	}
	return newone;
}
Beispiel #19
0
//## Bytes Bytes.new(int size);
static KMETHOD Bytes_new(KonohaContext *kctx, KonohaStack *sfp)
{
	kBytes *ba = sfp[0].asBytes;
	size_t size = (size_t)sfp[1].intValue;
	if(ba->byteptr == NULL)
		KFree(ba->buf, ba->bytesize);
	((struct kBytesVar *)ba)->byteptr  = (const char *)KCalloc(size, 1, NULL);
	((struct kBytesVar *)ba)->bytesize = size;
	KReturn(ba);
}
Beispiel #20
0
static void kResultSet_Free(KonohaContext *kctx, kObject *o)
{
	kResultSet *rs = (kResultSet *)o;
	if(rs->column_size > 0) {
		KFree(rs->column, sizeof(KColumn) * rs->column_size);
	}
	if(rs->qcur != NULL) {
		rs->driver->qcurfree(rs->qcur);
		rs->qcur = NULL;
	}
	rs->connectionNULL = NULL;
}
static BOOLEAN _SampleActionToList(const OVS_ARGUMENT_GROUP* pArgGroup, OVS_ARGUMENT_SLIST_ENTRY** ppArgList)
{
    BOOLEAN ok = TRUE;

    OVS_ARGUMENT_SLIST_ENTRY* pCurListArg = NULL, *pHeadArg = NULL;

    pHeadArg = KZAlloc(sizeof(OVS_ARGUMENT_SLIST_ENTRY));
    if (!pHeadArg)
    {
        return FALSE;
    }

    pCurListArg = pHeadArg;
    OVS_ARGUMENT* pGroupArg = NULL;

    for (UINT i = 0; i < pArgGroup->count; ++i)
    {
        const OVS_ARGUMENT* pArg = pArgGroup->args + i;
        OVS_ARGTYPE argType = pArg->type;

        switch (argType)
        {
        case OVS_ARGTYPE_ACTION_SAMPLE_PROBABILITY:
            if (!CreateArgInList_WithSize(OVS_ARGTYPE_ACTION_SAMPLE_PROBABILITY, pArg->data, pArg->length, &pCurListArg))
            {
                return FALSE;
            }

            break;

        case OVS_ARGTYPE_ACTION_SAMPLE_ACTIONS_GROUP:
            _CreateActionsGroupToList(OVS_ARGTYPE_ACTION_SAMPLE_ACTIONS_GROUP, pArg->data, &pCurListArg);
            break;
        }
    }

    pGroupArg = CreateGroupArgFromList(OVS_ARGTYPE_ACTION_SAMPLE_GROUP, &pHeadArg);
    if (!pGroupArg)
    {
        KFree(pHeadArg);
        return FALSE;
    }

    ok = AppendArgumentToList(pGroupArg, ppArgList);
    if (!ok)
    {
        DestroyArgument(pGroupArg);
    }

    return ok;
}
Beispiel #22
0
char *AllocPathname (char *src)
{
    char *buf;

    if ((buf = KMalloc (MAX_PATHNAME_SZ)) != NULL)
    {
        if (CopyInStr (current_process->user_as, buf, src, MAX_PATHNAME_SZ) == 0)
            return buf;
        else
            KFree (buf);
    }

    return NULL;
}
VOID DestroyArguments(_In_ OVS_ARGUMENT* argArray, UINT count)
{
    if (argArray != NULL && count > 0)
    {
        for (UINT i = 0; i < count; ++i)
        {
            OVS_ARGUMENT* pArg = argArray + i;

            DestroyArgumentData(pArg);
        }

        KFree(argArray);
    }
}
Beispiel #24
0
static void KonohaContext_Free(KonohaContext *kctx, KonohaContextVar *ctx)
{
	size_t i;
	for(i = 1; i < KRuntimeModel_MAXSIZE; i++) {   // 0 is LOGGER, free lately
		KModelContext *p = ctx->localContexts[i];
		if(p != NULL && p->free != NULL) {
			p->free(ctx, p);
		}
	}
	KRuntimeContext_Free(kctx, ctx);
	if(IS_RootKonohaContext(ctx)){  // share
		PLATAPI ExecutionEngineModule.DeleteExecutionEngine(ctx);
		KonohaLibVar *kklib = (KonohaLibVar *)ctx - 1;
		for(i = 0; i < KRuntimeModel_MAXSIZE; i++) {
			KRuntimeModel *p = ctx->runtimeModels[i];
			if(p == NULL) continue;
			if(p->allocSize > 0) {
				KFree(p, p->allocSize);
			}
			else if(p->freeModel != NULL) {
				p->freeModel(kctx, p);
			}
		}
		PLATAPI GCModule.DeleteGcContext(ctx);
		PLATAPI JsonModule.DeleteJsonContext(ctx);
		KRuntime_Free(kctx, ctx);
		free(kctx->localContexts);
		free(kctx->runtimeModels);
		free(kklib/*, sizeof(KonohaLib) + sizeof(KonohaContextVar)*/);
	}
	else {
		PLATAPI GCModule.DeleteGcContext(ctx);
		PLATAPI JsonModule.DeleteJsonContext(ctx);
		KFree(ctx->localContexts, sizeof(KModelContext *) * KRuntimeModel_MAXSIZE);
		KFree(ctx, sizeof(KonohaContextVar));
	}
}
Beispiel #25
0
void CDFreeNode (struct CDSB *cdsb, struct CDNode *node)
{
	node->reference_cnt--;

		
	if (node == &cdsb->root_node)
	{
		return;
	}
	
	if (node->reference_cnt == 0)
	{	
		LIST_REM_ENTRY (&cdsb->node_list, node, node_entry);
		KFree (node);
	}
}
Beispiel #26
0
void FreeNode (struct FatSB *fsb, struct FatNode *node)
{
	node->reference_cnt--;
	
	if (node == &fsb->root_node)
	{
		return;
	}
	
	FlushDirent (fsb, node);
	
	if (node->reference_cnt == 0)
	{	
		LIST_REM_ENTRY (&fsb->node_list, node, node_entry);
		KFree (node);
	}
}
VOID DestroyArgumentData(_In_ OVS_ARGUMENT* pArg)
{
    OVS_CHECK(pArg);

    if (IsArgTypeGroup(pArg->type))
    {
        OVS_ARGUMENT_GROUP* pGroup = pArg->data;

        DestroyArgumentGroup(pGroup);
    }
    else
    {
        //free arg data
        if (pArg->freeData)
        {
            KFree(pArg->data);
        }
    }
}
Beispiel #28
0
int cd_closedevice (void *ioreq)
{
	struct FSReq *fsreq = ioreq;
	struct BlkReq blkreq;
	struct CDSB *cdsb;

	KPRINTF ("cd_closedevice()");
	
	cdsb = fsreq->unitp;

	RWWriteLock (&mountlist_rwlock);
	
	if (cdsb->reference_cnt == 0)
	{
		KSignal (cdsb->pid, SIG_TERM);
		WaitPid (cdsb->pid, NULL, 0);
		
		blkreq.device = cdsb->device;
		blkreq.unitp = cdsb->unitp;
		
		CloseDevice (&blkreq);
	
		cd_device.reference_cnt --;	
		RemMount (cdsb->device_mount);

		FreeBuf (cdsb->buf);
		KFree (cdsb);
		
		fsreq->error = 0;
		fsreq->rc = 0;
	}
	else
	{
		fsreq->error = EBUSY;
		fsreq->rc = -1;
	}
	
	RWUnlock (&mountlist_rwlock);
		
	KPRINTF ("cd_closedevice() +");
	
	return 0;
}
VOID Arp_DestroyTable()
{
    OVS_ARP_TABLE_ENTRY* pArpEntry = NULL;
    PLIST_ENTRY headList = NULL;
    LOCK_STATE_EX lockState = { 0 };

    NdisAcquireRWLockWrite(g_pArpRWLock, &lockState, 0);

    while (!IsListEmpty(&g_arpTable))
    {
        headList = RemoveHeadList(&g_arpTable);

        pArpEntry = CONTAINING_RECORD(headList, OVS_ARP_TABLE_ENTRY, listEntry);

        KFree(pArpEntry);
    }

    NdisReleaseRWLock(g_pArpRWLock, &lockState);
}
Beispiel #30
0
void AtaTaskInit (void)
{
	KPRINTF ("AtaTaskInit()");

	ata_pid = GetPID();
	
	if ((ata_buffer = KMalloc (ATA_BUFFER_SZ)) != NULL)
	{
		if ((ata_timer_signal = AllocSignal()) != -1)
		{
			if ((ata_alarm_signal = AllocSignal()) != -1)
			{
				if ((ata_msgport = CreateMsgPort()) != NULL)
				{
					if (AtaInitUnits() == 0)
					{
						ata_init_error = 0;
						KSignal (GetPPID(), SIG_INIT);
						return;
					}
					
					DeleteMsgPort (ata_msgport);
				}
				
				FreeSignal (ata_alarm_signal);
			}

			FreeSignal (ata_timer_signal);
		}
				
		KFree (ata_buffer);
	}
	
	ata_init_error = -1;	
	KSignal (GetPPID(), SIG_INIT);
	
	Exit(-1);
}