/*************************************************************************** * Função: Menu Cadastrar Peça * ****/ static void MenuCadastrarPeca(PAR_tppPartida ppPartida) { char *nome, *passos, *tipoMov; ISP_tpCondRet ispCondRet; MPEC_tpTipoMovimento tipoMovimento; LIS_tppLista pPassos; MEM_Alloc(sizeof(char)*20,(void**)&nome); MEM_Alloc(sizeof(char)*200,(void**)&passos); MEM_Alloc(sizeof(char)*4,(void**)&tipoMov); printf("Nome da peca (20 caracteres): "); scanf("%s",nome); printf("Movimentos ([n]coordenada_[n]coordenada): "); scanf("%s", passos); printf("Tipo de movimento(Anda | Voa): "); scanf("%s",tipoMov); ispCondRet = ISP_LerTipoMovimento(tipoMov,&tipoMovimento); if(ispCondRet != ISP_CondRetOK) { return Mensagem("Tipo de movimento invalido!"); } ISP_LerPassos(passos,&pPassos); PAR_CriarPeca(ppPartida, nome, pPassos, tipoMovimento); return Mensagem("Peca cadastrada com sucesso!"); }
/*************************************************************************** * Função: Menu Inserir Peça * ****/ static void MenuInserirPeca(PAR_tppPartida ppPartida, const PEC_tpTimePeca time) { char *nome, *nomeCasa; PAR_tpCondRet condRet; MEM_Alloc(sizeof(char)*20,(void**)&nome); MEM_Alloc(sizeof(char)*2,(void**)&nomeCasa); printf("Nome da peca (20 caracteres): "); scanf("%s", nome); printf("Nome da casa que deseja inserir a peca (2 caracteres - convenção do xadrez): "); scanf("%s", nomeCasa); nomeCasa[0] = toupper(nomeCasa[0]); condRet = PAR_IrCasa(ppPartida, nomeCasa); if(condRet != PAR_CondRetOK) { return Mensagem("Erro ao inserir - Casa nao existe!"); } condRet = PAR_InserirPeca(ppPartida,nome,time); if(condRet == PAR_CondRetPecaNaoEncontrada) { return Mensagem("Erro ao inserir - Peca nao encontrada!"); } return Mensagem("Peca inserida no time com sucesso!"); }
/*************************************************************************** * Função: Menu Remover Peça * ****/ static void MenuRemoverPeca(PAR_tppPartida ppPartida) { char *nomeDaCasa; PAR_tpCondRet condRet; MEM_Alloc(sizeof(char)*2,(void**)&nomeDaCasa); printf("Nome da casa onde esta a peca a ser removida: "); scanf("%s",nomeDaCasa); nomeDaCasa[0] = toupper(nomeDaCasa[0]); condRet = PAR_IrCasa(ppPartida,nomeDaCasa); if(condRet != PAR_CondRetOK) { return Mensagem("Erro ao remover - Casa nao existe!"); } condRet = PAR_RemoverPeca(ppPartida); if(condRet == PAR_CondRetPecaNaoEncontrada) { return Mensagem("Erro ao remover - casa esta vazia!"); } return Mensagem("Peca removida com sucesso!"); }
/*************************************************************************** * Função: Menu Inserir Rei * ****/ static void MenuInserirRei(PAR_tppPartida ppPartida) { char *nomeCasa; PAR_tpCondRet condRet; MEM_Alloc(sizeof(char)*2,(void**)&nomeCasa); printf("Nome da casa que deseja inserir o rei (2 caracteres - convenção do xadrez): "); scanf("%s", nomeCasa); nomeCasa[0] = toupper(nomeCasa[0]); condRet = PAR_IrCasa(ppPartida, nomeCasa); if(condRet != PAR_CondRetOK) { return Mensagem("Erro ao inserir - Casa nao existe!"); } condRet = PAR_InserirRei(ppPartida); if(condRet != PAR_CondRetOK) { return Mensagem("Erro ao inserir o rei!"); } return Mensagem("Rei inserido com sucesso!"); }
/* create a new chunk node, setting its cache index and ref count */ FT_EXPORT_DEF( FT_Error ) FTC_ChunkNode_Init( FTC_ChunkNode node, FTC_ChunkSet cset, FT_UInt index, FT_Bool alloc ) { FTC_Chunk_Cache cache = cset->cache; FTC_CacheNode_Data* data = FTC_CACHENODE_TO_DATA_P( &node->root ); FT_Error error = 0; data->cache_index = (FT_UShort)cache->root.cache_index; data->ref_count = (FT_Short) 0; node->cset = cset; node->cset_index = (FT_UShort)index; node->num_elements = ( index + 1 < cset->num_chunks ) ? cset->element_count : cset->element_max - cset->element_count*index; if ( alloc ) { /* allocate elements array */ FT_Memory memory; memory = cache->root.memory; error = MEM_Alloc( node->elements, cset->element_size * cset->element_count ); } return error; }
/** ============================================================================ * @func MEM_Calloc * * @desc Allocates the specified number of bytes and memory is set to zero. * * @modif None * ============================================================================ */ EXPORT_API DSP_STATUS MEM_Calloc (OUT Void ** ptr, IN Uint32 cBytes, IN OUT Pvoid arg) { DSP_STATUS status = DSP_SOK ; Uint32 i ; TRC_3ENTER ("MEM_Calloc", ptr, cBytes, arg) ; DBC_Require (ptr != NULL) ; DBC_Require (MEM_IsInitialized == TRUE) ; DBC_Require (cBytes != 0) ; status = MEM_Alloc (ptr, cBytes, arg) ; if (DSP_SUCCEEDED (status)) { for (i = 0 ; i < cBytes ; i++) { (*(Uint8 **) ptr)[i] = 0 ; } } DBC_Ensure ( ((ptr == NULL) && DSP_FAILED (status)) || ((ptr != NULL) && (*ptr != NULL) && DSP_SUCCEEDED (status)) || ((ptr != NULL) && (*ptr == NULL) && DSP_FAILED (status))) ; TRC_1LEAVE ("MEM_Calloc", status) ; return status ; }
/** * Free unused memory. */ void BITSET_Trim(BitSet * bs) { if (bs->alloc > bs->inuse) { if (bs->inuse == 0) { ASSERT(bs->storage.units); MEM_Free(bs->storage.units); bs->storage.units = NULL; bs->alloc = 0; } else { BitUnit * savebuf = bs->storage.units; size_t size = sizeof(BitUnit) * bs->inuse; #ifdef NO_REALLOC bs->storage.units = (BitUnit*)MEM_Alloc(size); if (bs->storage.units) { memcpy(bs->storage.units, savebuf, size); MEM_Free(bs->storage.units); } #else bs->storage.units = (BitUnit*)MEM_Realloc(savebuf, size); #endif /* NO_REALLOC */ if (bs->storage.units) { bs->alloc = bs->inuse; } else { bs->storage.units = savebuf; } } } }
/** * Creates and starts n worker thread */ WorkQueue * WKQ_CreatePool(int n) { size_t size = sizeof(WorkQueue) + sizeof(ThrID)*(MAX(n,1)-1); WorkQueue * q = MEM_Alloc(size); if (q) { ASSERT(WKQ.initcount > 0); if (WKQ.initcount == 0) WKQ_InitModule(); memset(q, 0, size); q->nthreads = n; if (MUTEX_Init(&q->mutex)) { if (EVENT_Init(&q->event)) { if (EVENT_Init(&q->stopEvent)) { if (EVENT_Reset(&q->stopEvent)) { int i; q->flags = WKQ_ACTIVE; QUEUE_Init(&q->items); QUEUE_Init(&q->submit); for (i=0; i<n; i++) { if (!THREAD_Create(q->threads+i, WKQ_Thread, q)) { WKQ_Delete(q); return NULL; } } return q; } EVENT_Destroy(&q->stopEvent); } EVENT_Destroy(&q->event); } MUTEX_Destroy(&q->mutex); } MEM_Free(q); } return NULL; }
/** * Initializes the input zlib context */ STATIC Bool ZipInitIn(Zip * zf) { /* allocate buffer */ zf->inbuf = (I8u*)MEM_Alloc(zf->bufsize); if (zf->inbuf) { /* allocate zlib context */ zf->in = MEM_New(z_stream); if (zf->in) { int bits = ((zf->zflags & ZIP_ZHDR) ? (-MAX_WBITS) : MAX_WBITS); /* tell zlib to use our memory allocation functions */ memset(zf->in, 0, sizeof(*zf->in)); zf->in->zalloc = ZipMemAlloc; zf->in->zfree = ZipMemFree; zf->in->next_in = zf->inbuf; if (inflateInit2(zf->in, bits) == Z_OK) { /* skip .gz header */ if (!(zf->zflags & ZIP_GZIP) || ZipSkipHeader(zf)) { return True; } inflateEnd(zf->in); } MEM_Free(zf->in); zf->in = NULL; } MEM_Free(zf->inbuf); zf->inbuf = NULL; } zf->zflags |= ZIP_IN_ERR; return False; }
static ELEMENT* psc_read_element (MEM *elemem, MEM *facmem, FILE *f) { FACE *fac, *tail; ELEMENT *ele; short j; int i; ERRMEM (ele = MEM_Alloc (elemem)); fread (&ele->type, sizeof (short), 1, f); fread (&ele->neighs, sizeof (short), 1, f); fread (&ele->volume, sizeof (int), 1, f); fread (ele->nodes, sizeof (int), ele->type, f); for (i = 0; i < ele->neighs; i ++) { fread (&j, sizeof (short), 1, f); ele->adj [i] = (void*) (long) j; } fread (&j, sizeof (short), 1, f); for (i = 0, tail = NULL; i < j; i ++) { fac = psc_read_face (facmem, f); fac->ele = ele; if (tail) tail->next = fac; else ele->faces = fac; tail = fac; } return ele; }
/* * ======== MGRWRAP_EnumProc_Info ======== */ u32 MGRWRAP_EnumProc_Info(union Trapped_Args *args, void *pr_ctxt) { u8 *pProcessorInfo; u32 uNumProcs; DSP_STATUS status = DSP_SOK; u32 size = args->ARGS_MGR_ENUMPROC_INFO.uProcessorInfoSize; GT_4trace(WCD_debugMask, GT_ENTER, "MGRWRAP_EnumProc_Info: entered args:\n" "0x%x uProcessor: 0x%x\tpProcessorInfo: 0x%x\t" "uProcessorInfoSize: 0x%x\tpuNumProcs \n", args->ARGS_MGR_ENUMPROC_INFO.uProcessor, args->ARGS_MGR_ENUMPROC_INFO.pProcessorInfo, args->ARGS_MGR_ENUMPROC_INFO.uProcessorInfoSize, args->ARGS_MGR_ENUMPROC_INFO.puNumProcs); pProcessorInfo = MEM_Alloc(size, MEM_NONPAGED); if (pProcessorInfo == NULL) status = DSP_EMEMORY; if (DSP_SUCCEEDED(status)) { status = MGR_EnumProcessorInfo(args-> ARGS_MGR_ENUMPROC_INFO.uProcessor, (struct DSP_PROCESSORINFO *)pProcessorInfo, size, &uNumProcs); } cp_to_usr(args->ARGS_MGR_ENUMPROC_INFO.pProcessorInfo, pProcessorInfo, status, size); cp_to_usr(args->ARGS_MGR_ENUMPROC_INFO.puNumProcs, &uNumProcs, status, 1); if (pProcessorInfo) MEM_Free(pProcessorInfo); return status; }
/*************************************************************************** * Função: GRA Inserir vertice ******/ GRA_tpCondRet GRA_InserirVertice(GRA_tppGrafo pGrafoParm, char *nomeVertice, void *pValor) { tpGrafo *pGrafo = (tpGrafo*) pGrafoParm; tpVertice *pVertice; if (pGrafo == NULL) { return GRA_CondRetGrafoNaoFoiCriado; } if (ExisteVertice(pGrafo, nomeVertice)) { return GRA_CondRetJaExiste; } MEM_Alloc(sizeof(tpVertice), (void **) &pVertice); if (pVertice == NULL) { return GRA_CondRetFaltouMemoria; } pVertice->nome = nomeVertice; pVertice->pValor = pValor; pVertice->destruirValor = pGrafo->destruirValor; LIS_CriarLista(&pVertice->pAntecessores, NULL, CompararVerticeENome); LIS_CriarLista(&pVertice->pSucessores, DestruirAresta, CompararArestaENome); pGrafo->pCorrente = pVertice; LIS_InserirElementoApos(pGrafo->pVertices, pVertice); return GRA_CondRetOK; }
/* * ======== MGRWRAP_EnumNode_Info ======== */ u32 MGRWRAP_EnumNode_Info(union Trapped_Args *args, void *pr_ctxt) { u8 *pNDBProps; u32 uNumNodes; DSP_STATUS status = DSP_SOK; u32 size = args->ARGS_MGR_ENUMNODE_INFO.uNDBPropsSize; GT_4trace(WCD_debugMask, GT_ENTER, "MGR_EnumNodeInfo: entered args:\n0x%x" " uNode: 0x%x\tpNDBProps: 0x%x\tuNDBPropsSize: " "0x%x\tpuNumNodes\n", args->ARGS_MGR_ENUMNODE_INFO.uNode, args->ARGS_MGR_ENUMNODE_INFO.pNDBProps, args->ARGS_MGR_ENUMNODE_INFO.uNDBPropsSize, args->ARGS_MGR_ENUMNODE_INFO.puNumNodes); pNDBProps = MEM_Alloc(size, MEM_NONPAGED); if (pNDBProps == NULL) status = DSP_EMEMORY; if (DSP_SUCCEEDED(status)) { status = MGR_EnumNodeInfo(args->ARGS_MGR_ENUMNODE_INFO.uNode, (struct DSP_NDBPROPS *)pNDBProps, size, &uNumNodes); } cp_to_usr(args->ARGS_MGR_ENUMNODE_INFO.pNDBProps, pNDBProps, status, size); cp_to_usr(args->ARGS_MGR_ENUMNODE_INFO.puNumNodes, &uNumNodes, status, 1); if (pNDBProps) MEM_Free(pNDBProps); return status; }
/* * ======== STRMWRAP_FreeBuffer ======== */ u32 STRMWRAP_FreeBuffer(union Trapped_Args *args, void *pr_ctxt) { DSP_STATUS status = DSP_SOK; u8 **apBuffer = NULL; u32 uNumBufs = args->ARGS_STRM_FREEBUFFER.uNumBufs; DBC_Require(uNumBufs <= MAX_BUFS); apBuffer = MEM_Alloc((uNumBufs * sizeof(u8 *)), MEM_NONPAGED); cp_fm_usr(apBuffer, args->ARGS_STRM_FREEBUFFER.apBuffer, status, uNumBufs); if (DSP_SUCCEEDED(status)) { mutex_lock(&((struct PROCESS_CONTEXT *)pr_ctxt)->strm_lock); status = STRM_FreeBuffer(args->ARGS_STRM_FREEBUFFER.hStream, apBuffer, uNumBufs, pr_ctxt); mutex_unlock(&((struct PROCESS_CONTEXT *)pr_ctxt)->strm_lock); } cp_to_usr(args->ARGS_STRM_FREEBUFFER.apBuffer, apBuffer, status, uNumBufs); if (apBuffer) MEM_Free(apBuffer); return status; }
/* * ======== NODEWRAP_GetUUIDProps ======== */ u32 NODEWRAP_GetUUIDProps(union Trapped_Args *args, void *pr_ctxt) { DSP_STATUS status = DSP_SOK; struct DSP_UUID nodeId; struct DSP_NDBPROPS *pnodeProps = NULL; GT_0trace(WCD_debugMask, GT_ENTER, "NODEWRAP_GetUUIDPropste: entered\n"); cp_fm_usr(&nodeId, args->ARGS_NODE_GETUUIDPROPS.pNodeID, status, 1); if (DSP_FAILED(status)) goto func_cont; pnodeProps = MEM_Alloc(sizeof(struct DSP_NDBPROPS), MEM_NONPAGED); if (pnodeProps != NULL) { status = NODE_GetUUIDProps(args-> ARGS_NODE_GETUUIDPROPS.hProcessor, &nodeId, pnodeProps); cp_to_usr(args->ARGS_NODE_GETUUIDPROPS.pNodeProps, pnodeProps, status, 1); } else status = DSP_EMEMORY; func_cont: if (pnodeProps) MEM_Free(pnodeProps); return status; }
static PList_Element Element_New( PEngine_Instance engine ) { PList_Element element; LOCK(); if ( FREE_Elements ) { element = (PList_Element)FREE_Elements; FREE_Elements = element->next; } else { if ( !MEM_Alloc( element, sizeof ( TList_Element ) ) ) { element->next = NULL; element->data = NULL; } } /* Note: in case of failure, Alloc sets the pointer to NULL */ UNLOCK(); return element; }
/****************************************************************************\ * * NT_QueryObjectName() * * DESCRIPTION: * * Queries the name of the object (such as a device or file object). * The caller must deallocate the return value with MEM_Free. The * returned string (if not NULL) is guaranteed to be NULL terminated. * * ARGUMENTS: * * obj - the object whose name to query * \****************************************************************************/ OBJECT_NAME_INFORMATION * NT_QueryObjectName(PVOID obj) { ULONG len = 0; NTSTATUS status = ObQueryNameString(obj, NULL, 0, &len); ASSERT(status != STATUS_SUCCESS); /* Unlike the rest of the system, ObQueryNameString returns * STATUS_INFO_LENGTH_MISMATCH instead of STATUS_BUFFER_TOO_SMALL * when passed too small a buffer. We expect to get this error here. * Anything else we can't handle. */ if (status == STATUS_INFO_LENGTH_MISMATCH && len > 0) { OBJECT_NAME_INFORMATION * name = MEM_Alloc(len + sizeof(WCHAR)); if (name) { /* NOTE: ObQueryNameString may return STATUS_SUCCESS and empty * string for unnamed objects */ status = ObQueryNameString(obj, name, len, &len); if (NT_SUCCESS(status) && name->Name.MaximumLength > 0) { /* make sure it's NULL terminated */ ULONG Last = name->Name.Length/sizeof(name->Name.Buffer[0]); name->Name.Buffer[Last] = 0; return name; } MEM_Free(name); } } return NULL; }
/*************************************************************************** * Função: GRA Inserir aresta ******/ GRA_tpCondRet GRA_InserirAresta(GRA_tppGrafo pGrafoParm, char *nomeAresta, char *nomeVerticeOrigem, char *nomeVerticeDestino) { tpGrafo *pGrafo = (tpGrafo*) pGrafoParm; tpAresta *pAresta; LIS_tpCondRet lisCondRet; GRA_tpCondRet graCondRet; tpVertice *pVerticeOrigem, *pVerticeDestino; if (pGrafo == NULL) { return GRA_CondRetGrafoNaoFoiCriado; } // Procura vértice origem graCondRet = ProcurarVertice(pGrafo, nomeVerticeOrigem, &pVerticeOrigem); if (graCondRet != GRA_CondRetOK) { return graCondRet; } // Procura vértice destino graCondRet = ProcurarVertice(pGrafo, nomeVerticeDestino, &pVerticeDestino); if (graCondRet != GRA_CondRetOK) { return graCondRet; } // Verifica se já existe uma aresta com este nome if (ExisteAresta(pVerticeOrigem, nomeAresta)) { return GRA_CondRetJaExiste; } MEM_Alloc(sizeof(tpAresta), (void **) &pAresta); if (pAresta == NULL) { return GRA_CondRetFaltouMemoria; } // Atualiza os antecessores do vértice destino lisCondRet = LIS_InserirElementoApos(pVerticeDestino->pAntecessores, pVerticeOrigem); if (lisCondRet == LIS_CondRetFaltouMemoria) { return GRA_CondRetFaltouMemoria; } // Atualiza os sucessores do vértice origem lisCondRet = LIS_InserirElementoApos(pVerticeOrigem->pSucessores, pAresta); if (lisCondRet == LIS_CondRetFaltouMemoria) { return GRA_CondRetFaltouMemoria; } pAresta->nome = nomeAresta; pAresta->pVertice = pVerticeDestino; return GRA_CondRetOK; }
/** * Initializes the output zlib context */ STATIC Bool ZipInitOut(Zip * zf) { /* allocate buffer */ zf->outbuf = (I8u*)MEM_Alloc(zf->bufsize); if (zf->outbuf) { /* allocate zlib context */ zf->out = MEM_New(z_stream); if (zf->out) { int zerr; int bits = ((zf->zflags & ZIP_ZHDR) ? (-MAX_WBITS) : MAX_WBITS); /* tell zlib to use our memory allocation functions */ memset(zf->out, 0, sizeof(*zf->out)); zf->out->zalloc = ZipMemAlloc; zf->out->zfree = ZipMemFree; /* windowBits is passed < 0 to suppress zlib header */ zerr = deflateInit2(zf->out, Z_BEST_COMPRESSION, Z_DEFLATED, bits, 8, Z_DEFAULT_STRATEGY); if (zerr == Z_OK) { if (zf->zflags & ZIP_GZIP) { /* write a very simple .gz header */ I8u hdr[10]; memset(hdr, 0, sizeof(hdr)); hdr[0] = (I8u)GzMagic[0]; hdr[1] = (I8u)GzMagic[1]; hdr[2] = Z_DEFLATED; hdr[9] = OS_CODE; if (FILE_Write(zf->f,hdr,sizeof(hdr)) == sizeof(hdr)) { FILE_Flush(zf->f); zf->out->next_out = zf->outbuf; zf->out->avail_out = zf->bufsize; return True; } } else { /* not writing the header */ zf->out->next_out = zf->outbuf; zf->out->avail_out = zf->bufsize; return True; } deflateEnd(zf->out); } MEM_Free(zf->out); zf->out = NULL; } MEM_Free(zf->outbuf); zf->outbuf = NULL; } zf->zflags |= ZIP_OUT_ERR; return False; }
int main(void) { void *p1, *p2, *p3; uSMARTX_Init(tsk_tbl); p1 = MEM_Alloc(&sys_mem, 15); p2 = MEM_Alloc(&sys_mem, 64); p3 = MEM_Alloc(&sys_mem, 100); MEM_Free(&sys_mem, p1); p3 = MEM_Alloc(&sys_mem, 100); MEM_Free(&sys_mem, p2); p3 = MEM_Alloc(&sys_mem, 100); while(1) { uSMARTX_Tick(); if(uSMARTX_Scheduler() == SYS_ERROR) break; } while(1); }
/** * Create a card deck. * * \b History: * \arg 02.04.94 ESF Created. * \arg 03.16.94 ESF Added code for returned card handling. */ Deck *DECK_Create(Int32 iNumCards) { Deck *pDeck = (Deck *)MEM_Alloc(sizeof(Deck)); Int32 i; /* Seed the random number generator */ srand(time(NULL)); /* Init the structure */ pDeck->iCardsLeft = pDeck->iTotalCards = iNumCards; pDeck->iCardsReturned = 0; pDeck->piCards = (Int32 *)MEM_Alloc(sizeof(Int32)*iNumCards); pDeck->piCardsReturned = (Int32 *)MEM_Alloc(sizeof(Int32)*iNumCards); /* Init all of the cards */ for(i=0; i!=iNumCards; i++) pDeck->piCards[i] = i; return(pDeck); }
/* * ======== NODEWRAP_Allocate ======== */ u32 NODEWRAP_Allocate(union Trapped_Args *args, void *pr_ctxt) { DSP_STATUS status = DSP_SOK; struct DSP_UUID nodeId; u32 cbDataSize = 0; u32 __user *pSize = (u32 __user *)args->ARGS_NODE_ALLOCATE.pArgs; u8 *pArgs = NULL; struct DSP_NODEATTRIN attrIn, *pAttrIn = NULL; struct NODE_OBJECT *hNode; GT_0trace(WCD_debugMask, GT_ENTER, "NODEWRAP_Allocate: entered\n"); /* Optional argument */ if (pSize) { if (get_user(cbDataSize, pSize)) status = DSP_EFAIL; cbDataSize += sizeof(u32); if (DSP_SUCCEEDED(status)) { pArgs = MEM_Alloc(cbDataSize, MEM_NONPAGED); if (pArgs == NULL) status = DSP_EMEMORY; } cp_fm_usr(pArgs, args->ARGS_NODE_ALLOCATE.pArgs, status, cbDataSize); } cp_fm_usr(&nodeId, args->ARGS_NODE_ALLOCATE.pNodeID, status, 1); if (DSP_FAILED(status)) goto func_cont; /* Optional argument */ if (args->ARGS_NODE_ALLOCATE.pAttrIn) { cp_fm_usr(&attrIn, args->ARGS_NODE_ALLOCATE.pAttrIn, status, 1); if (DSP_SUCCEEDED(status)) pAttrIn = &attrIn; else status = DSP_EMEMORY; } if (DSP_SUCCEEDED(status)) { mutex_lock(&((struct PROCESS_CONTEXT *)pr_ctxt)->node_lock); status = NODE_Allocate(args->ARGS_NODE_ALLOCATE.hProcessor, &nodeId, (struct DSP_CBDATA *)pArgs, pAttrIn, &hNode, pr_ctxt); mutex_unlock(&((struct PROCESS_CONTEXT *)pr_ctxt)->node_lock); } cp_to_usr(args->ARGS_NODE_ALLOCATE.phNode, &hNode, status, 1); func_cont: if (pArgs) MEM_Free(pArgs); return status; }
static TFileMap* Allocate_Map( void ) { TFileMap* result; if ( MEM_Alloc( result, sizeof ( TFileMap ) ) ) return NULL; result->refcount = 1; return result; }
/*************************************************************************** * Função: Menu Alterar Peça * ****/ static void MenuAlterarPeca(PAR_tppPartida ppPartida) { char *nomeAtual, *novoNome, *novosPassos, *movimento; ISP_tpCondRet ispCondRet; PAR_tpCondRet parCondRet; MPEC_tpTipoMovimento novoTipoMovimento; LIS_tppLista pPassos; MEM_Alloc(sizeof(char)*20,(void**)&nomeAtual); MEM_Alloc(sizeof(char)*20,(void**)&novoNome); MEM_Alloc(sizeof(char)*200,(void**)&novosPassos); MEM_Alloc(sizeof(char)*4,(void**)&movimento); printf("\nNome da peca que quer alterar (20 caracteres): "); scanf("%s", nomeAtual); printf("Novo nome (20 caracteres): "); scanf("%s", novoNome); printf("Novo movimento ([n]coordenada): "); scanf("%s", novosPassos); printf("Novo tipo de movimento (Anda | Voa): "); scanf("%s", movimento); ispCondRet = ISP_LerTipoMovimento(movimento,&novoTipoMovimento); if(ispCondRet != ISP_CondRetOK) { return Mensagem("Tipo de movimento invalido!"); } ISP_LerPassos(novosPassos,&pPassos); parCondRet = PAR_AlterarPeca(ppPartida,nomeAtual,novoNome,pPassos,novoTipoMovimento); if(parCondRet != PAR_CondRetOK) { return Mensagem("Erro ao alterar peca!"); } return Mensagem("Peca alterada com sucesso!"); }
static ELEMENT* create_element (MEM *elemem, int *element) { ELEMENT *ele; int n; ele = static_cast<ELEMENT*>(MEM_Alloc (elemem)); ele->type = element [0]; for (n = 1; n <= element [0]; n ++) ele->nodes [n-1] = element [n]; ele->material = element [n]; /* material number */ return ele; }
/* create new list item */ static ITEM* skip_item (LIST *list, void *key, void *data) { ITEM *item; if (!(item = MEM_Alloc (&list->mem))) return NULL; item->key = key; item->data = data; item->forward = (ITEM**) (item + 1); /* XXX: rather than this, length of 'forward' should vary depending on the number of stored items; XXX: 'forward' could be 'malloc'ed here and 'realloc'ated later, when the number of items exceeds XXX: consecutive powers of two; the drawback would be in greater memory fragmentation */ return item; }
static FACE* psc_read_face (MEM *facmem, FILE *f) { FACE *fac; ERRMEM (fac = MEM_Alloc (facmem)); fread (fac->normal, sizeof (double), 3, f); fread (&fac->type, sizeof (int), 1, f); fread (fac->nodes, sizeof (int), fac->type, f); fread (&fac->index, sizeof (int), 1, f); fread (&fac->surface, sizeof (int), 1, f); return fac; }
/* * ======== NODEWRAP_Connect ======== */ u32 NODEWRAP_Connect(union Trapped_Args *args, void *pr_ctxt) { DSP_STATUS status = DSP_SOK; struct DSP_STRMATTR attrs; struct DSP_STRMATTR *pAttrs = NULL; u32 cbDataSize; u32 __user *pSize = (u32 __user *)args->ARGS_NODE_CONNECT.pConnParam; u8 *pArgs = NULL; GT_0trace(WCD_debugMask, GT_ENTER, "NODEWRAP_Connect: entered\n"); /* Optional argument */ if (pSize) { if (get_user(cbDataSize, pSize)) status = DSP_EFAIL; cbDataSize += sizeof(u32); if (DSP_SUCCEEDED(status)) { pArgs = MEM_Alloc(cbDataSize, MEM_NONPAGED); if (pArgs == NULL) { status = DSP_EMEMORY; goto func_cont; } } cp_fm_usr(pArgs, args->ARGS_NODE_CONNECT.pConnParam, status, cbDataSize); if (DSP_FAILED(status)) goto func_cont; } if (args->ARGS_NODE_CONNECT.pAttrs) { /* Optional argument */ cp_fm_usr(&attrs, args->ARGS_NODE_CONNECT.pAttrs, status, 1); if (DSP_SUCCEEDED(status)) pAttrs = &attrs; } if (DSP_SUCCEEDED(status)) { status = NODE_Connect(args->ARGS_NODE_CONNECT.hNode, args->ARGS_NODE_CONNECT.uStream, args->ARGS_NODE_CONNECT.hOtherNode, args->ARGS_NODE_CONNECT.uOtherStream, pAttrs, (struct DSP_CBDATA *)pArgs); } func_cont: if (pArgs) MEM_Free(pArgs); return status; }
/*************************************************************************** * Função: GRA Criar grafo ******/ GRA_tpCondRet GRA_CriarGrafo(GRA_tppGrafo *ppGrafo, void (*destruirValor)(void *pValor)) { tpGrafo *pGrafo; MEM_Alloc(sizeof(tpGrafo), (void **) &pGrafo); pGrafo->pCorrente = NULL; pGrafo->destruirValor = destruirValor; LIS_CriarLista(&pGrafo->pOrigens, NULL, CompararVerticeENome); LIS_CriarLista(&pGrafo->pVertices, DestruirVertice, CompararVerticeENome); *ppGrafo = (GRA_tppGrafo) pGrafo; return GRA_CondRetOK; }
int THR_Create(Thread **thr, void (*fp)(void *), void *arg) { (*thr) = (Thread*)MEM_Alloc(sizeof(Thread)); if(!(*thr)) return -1; (*thr)->fp = fp; (*thr)->arg = arg; (*thr)->handle = (HANDLE)_beginthreadex(NULL, 0, ThreadWrapper, (*thr), 0, NULL); if((*thr)->handle == NULL){ LOG_ERROR("THR_Create: Failed to create thread! (%d)", errno); return -1; } return 0; }