Esempio n. 1
0
int
tc_init (void)
{
    if (h != NULL) {
	return 0;
    }

    h = dlopen(DXTN_LIB, RTLD_NOW | RTLD_LOCAL);
    if (h == NULL) {
	return -1;
    }

    GET_PTR(TC_FETCHER, fxt1_decode_1);
    GET_PTR(TC_FETCHER, dxt1_rgb_decode_1);
    GET_PTR(TC_FETCHER, dxt1_rgba_decode_1);
    GET_PTR(TC_FETCHER, dxt3_rgba_decode_1);
    GET_PTR(TC_FETCHER, dxt5_rgba_decode_1);
    GET_PTR(TC_ENCODER, fxt1_encode);
    GET_PTR(TC_ENCODER, dxt1_rgb_encode);
    GET_PTR(TC_ENCODER, dxt1_rgba_encode);
    GET_PTR(TC_ENCODER, dxt3_rgba_encode);
    GET_PTR(TC_ENCODER, dxt5_rgba_encode);

    return 0;
}
Esempio n. 2
0
rfid_status	 mifare_classic_read (mifare_tag *tag, const mifare_classic_block_number block, mifare_classic_block data)
{
    MIFARE_CLASSIC_ACTIVE_ASSERT(tag);

    rfid_status status= RFID_ESUCCESS;
    switch (tag->reader_handler->reader_type) {
#if (READERS_SUPPORTED & READER_HF_READER_ICDREC)
    case RFID_READER_HF_READER_ICDREC:
        HF_READER_NEW_REQ_PACKAGE(req,1);
        GET_PTR(req)[sizeof(ihr_header)] = block;
        HF_READER_NEW_RESP_PACKAGE(resp,0);
        status = rfid_transceive_bytes(tag->reader_handler,GET_PTR(req),GET_LEN(req),GET_PTR(resp),GET_LEN(resp),&GET_SZ_RES(resp),5);
        switch (status) {
        case RFID_ESUCCESS:
        case RFID_EACK:

            break;

        default:
            break;
        }
        break;
#endif
    default:
        break;
    }
}
Esempio n. 3
0
bool psonLinkedListIsValid( psonLinkedList* pList,
                            psonLinkNode*   pUnknown )
{
   bool valid = false;
   
   psonLinkNode* pItem;

   PSO_PRE_CONDITION( pList != NULL );
   /* Test to see if the list is initialized */
   PSO_INV_CONDITION( pList->initialized == PSON_LIST_SIGNATURE );
   PSO_PRE_CONDITION( pUnknown   != NULL );

   pItem = &pList->head;
   
   GET_PTR( pItem, pItem->nextOffset, psonLinkNode );
   while ( pItem != &pList->head ) {
      if ( pItem == pUnknown ) {
         valid = true;
         break;
      }
      
      GET_PTR( pItem, pItem->nextOffset, psonLinkNode );
   }

   return valid;
}
Esempio n. 4
0
UINT CFrontEnd::uiInspectElements()
{
  for(UINT i = 0; i < OCL_HASH_TABLE_SIZE; ++i)
    {
      UINT uiMNRef      = pHashTable[i].uiNext;
      UINT uiNRef       = GET_PTR(uiMNRef);
      BOOL bNullFlag    = false;
      if(uiNRef)
	std::cout << "[" << i << "]";
      else
	bNullFlag = true;
      while(uiNRef)
	{
	  std::cout << "->[";
	  for(UINT j =0; j < OCL_WG_SIZE; ++j)
	    {
	      UINT uiKey = pNodePool[uiNRef].pE[j];
	      if(uiKey)
		std::cout << uiKey << "|";
	    }
	  std::cout << "]";

	  uiMNRef = pNodePool[uiNRef].uiNext;
	  uiNRef  = GET_PTR(uiMNRef);
	}
      if(!bNullFlag)
	std::cout << std::endl;
    }

  return HTS_OK;
}
Esempio n. 5
0
/*
Free a given structure.
Ptr must be NOT NULL *only* if type is not THR, TSK or SMO.
*/
void sfree(void *ptr, int id, int type)
{
	if(type == SALLOC_TSK || type == SALLOC_THR || type == SALLOC_SMO)
	{		
		switch(type)
		{
			case SALLOC_TSK:
				if(!TST_PTR(id,tsk)) return; // not allocated
				csfree(GET_PTR(id,tsk), SALLOC2CONT_TYPE(type));
				break;
			case SALLOC_THR:
				if(!TST_PTR(id,thr)) return;
				csfree(GET_PTR(id,thr), SALLOC2CONT_TYPE(type));
				break;
			case SALLOC_SMO:
				if(!TST_PTR(id,smo)) return;
				csfree(GET_PTR(id,smo), SALLOC2CONT_TYPE(type));
				break;
			default:
				break;		
		}
		
		index_free(id, ALLOC2IDX(type));
	}
	else
	{
		csfree(ptr, SALLOC2CONT_TYPE(type));
	}
	ammount[type]--;
}
Esempio n. 6
0
int mprPrintAllocBlocks(MprCtx ptr, int indent)
{
    MprBlk		*bp, *firstChild, *cp;
    const char	*location;
    int			subTotal, size, indentSpaces, code;

    subTotal = 0;

    bp = GET_HDR(ptr);

    if (! (bp->flags & ALLOC_FLAGS_REQUIRED)) {
        size = bp->size + HDR_SIZE;

        /*
         *	Take one level off because we don't trace app
         */
        indentSpaces = indent;

        if (bp->flags & ALLOC_FLAGS_REQUIRED) {
            code = 'R';
        } else if (bp->flags & ALLOC_FLAGS_IS_SLAB) {
            code = 'S';
        } else {
            code = ' ';
        }

#if BLD_FEATURE_ALLOC_LEAK_TRACK
        location = bp->location;
#else
        location = "";
#endif
        mprLog(bp->app, 0,
               "%c %.*s %-16s %.*s size %5d has %3d deps, total %6d", code,
               indentSpaces, "                   ",
               mprGetBaseName(location),
               8 - indent, "          ",
               size,
               mprGetAllocBlockCount(GET_PTR(bp)),
               mprGetAllocBlockMemory(GET_PTR(bp))
               /* (uint) bp */
              );

        subTotal += size;
    }

    if ((firstChild = bp->children) != 0) {
        cp = firstChild;
        do {
            subTotal += mprPrintAllocBlocks(GET_PTR(cp), indent + 2);
            cp = cp->next;
        } while (cp != firstChild);
    }

    return subTotal;
}
Esempio n. 7
0
		void Initialize()
		{
			c_settings_rasterizer::Register(Settings::Manager());

			Render::Initialize();
		
			// hook the calls to rasterizer_dispose
			Memory::WriteRelativeCall(&RasterizerDisposeHook, GET_FUNC_VPTR(RASTERIZER_DISPOSE_CALL_FROM_RASTERIZER));
			Memory::WriteRelativeCall(&RasterizerDisposeHook, GET_FUNC_VPTR(RASTERIZER_DISPOSE_CALL_FROM_SHELL));

			size_t address = CAST_PTR(size_t, Rasterizer::DebugOptions());
			for(const auto& rdt : k_rasterizer_debug_table)
			{
				// this is the only time we should be modifying the hs definitions
				// outside of the ScriptLibrary code, so do some cast magic
				Scripting::hs_global_definition* global_def = CAST_QUAL(Scripting::hs_global_definition*, 
					&(Scripting::HSExternalGlobals()[rdt.index]) );	// get the hs global definition we're about to fix up

				global_def->address = CAST_PTR(void*, address + rdt.field);// fix the global definition's address to point to the correct memory
			}
			
#if PLATFORM_VERSION <= 0x1090
			// update the resolution definition array length
			// definition count has been increased to 64 so that ridiculous amounts of resolutions in the future are accommodated
			GET_PTR(RESOLUTION_LIST_COUNT) = NUMBEROF(g_resolution_list);

			// redirect all resolution definition pointers to the new array
			for(auto ptr : K_RESOLUTION_LIST_X_REFERENCES)
				*ptr = &g_resolution_list[0].width;
			for(auto ptr : K_RESOLUTION_LIST_Y_REFERENCES)
				*ptr = &g_resolution_list[0].height;
			for(auto ptr : K_RESOLUTION_LIST_STRING_REFERENCES)
				*ptr = &g_resolution_list[0].resolution_string;

			*GET_PTR(RESOLUTION_LIST_STRING_NULL_REFERENCE) = &(g_resolution_list[0].resolution_string[15]);

			for(auto ptr : K_RESOLUTION_LIST_REFRESH_COUNT_REFERENCES)
				*ptr = &g_resolution_list[0].refresh_rate_count;
			for(auto ptr : K_RESOLUTION_LIST_REFRESH_RATE_REFERENCES)
				*ptr = &g_resolution_list[0].refresh_rates;

			// replace the original resolution populator with the new one
			Memory::WriteRelativeCall(&SetupResolutions, GET_FUNC_VPTR(RESOLUTION_LIST_SETUP_RESOLUTIONS_CALL), true);
#endif

			// make the screenshot function use a unique subfolder
			tag_string screenshots_folder;
			GetTimeStampStringForFile(screenshots_folder);
			strcat_s(g_screenshot_folder, sizeof(g_screenshot_folder), screenshots_folder);
			for(auto ptr : K_SCREENSHOT_FOLDER_REFERENCES)
				*ptr = &g_screenshot_folder[0];
		}
Esempio n. 8
0
__export void get_derivative_info(union syslinux_derivative_info *di)
{
	di->pxe.filesystem = SYSLINUX_FS_PXELINUX;
	di->pxe.apiver = APIVer;
	di->pxe.pxenvptr = GET_PTR(StrucPtr);
	di->pxe.pxenv_offs = StrucPtr.offs;
	di->pxe.pxenv_seg = StrucPtr.seg;
	di->pxe.stack = GET_PTR(InitStack);
	di->pxe.stack_offs = InitStack.offs;
	di->pxe.stack_seg = InitStack.seg;
	di->pxe.ipinfo = &IPInfo;
	di->pxe.myip = IPInfo.myip;
}
Esempio n. 9
0
static rfid_status	icdrec_hf_reader_select_target(struct rfid_device * thiz, rfid_target * target)
{

	rfid_status status= RFID_ESUCCESS ;
#if 1
	HF_READER_NEW_REQ_PACKAGE(req,0);
	GET_SZ_BUILT(req) = icdrec_hf_reader_build_package(HF_READER_CMD_ANTICOLLISION,NULL,0,GET_PTR(req),GET_LEN(req));
	RFID_HEXDUMP(GET_PTR(req),GET_LEN(req),"pkg",0);
	HF_READER_NEW_RESP_PACKAGE(res,1+MIFARE_MAX_UID_LEN);
	status = icdrec_hf_reader_transceive_bytes(thiz,GET_PTR(req),GET_SZ_BUILT(req),GET_PTR(res),GET_LEN(res),&GET_SZ_RES(res),2);
	uint8_t uid_len;
	switch (status) {
	case RFID_ESUCCESS:
	case RFID_EACK:
//		hdr = (ihr_header_response*)GET_PTR(res);
		uid_len = GET_PTR(res)[sizeof(ihr_header_response)];
		if(uid_len && target){
			memcpy(target->uid,GET_PTR(res)+sizeof(ihr_header_response),uid_len);
			target->uid_len = uid_len;
			if(uid_len==4){
				target->type= MIFARE_CLASSIC_1K;
			}else	if(uid_len==7){
				target->type= MIFARE_DESFIRE_EV1;
			}
		}
		break;
#if 1
	case RFID_EIO:
		RFATAL("IO error\n");
		break;
	case RFID_ENAK:
		RFATAL("NAK error\n");
		break;
	case RFID_ETIMEOUT:
		RFATAL("Time out\n");
		break;
	case RFID_ERESP:
		RFATAL("Failed responding\n");
		break;
#endif
	default:
		RFATAL("Unknown error\n");
		break;
	}
	CLEAR_WARNING(req);
	return  status;
#else
	status = icdrec_hf_reader_generic_command(thiz,HF_READER_CMD_ANTICOLLISION,NULL,0,1+10);
#endif
}
Esempio n. 10
0
int psoFolderGetNext( PSO_HANDLE       objectHandle,
                      psoFolderEntry * pEntry )
{
   psoaFolder * pFolder;
   psonFolder * pMemFolder;
   int errcode = PSO_OK;
   psonObjectDescriptor * pDescriptor;
   bool ok;
   
   pFolder = (psoaFolder *) objectHandle;
   if ( pFolder == NULL ) return PSO_NULL_HANDLE;
   
   if ( pFolder->object.type != PSOA_FOLDER ) {
      return PSO_WRONG_TYPE_HANDLE;
   }
   
   if ( pEntry == NULL ) {
      errcode = PSO_NULL_POINTER;
      goto error_handler;
   }

   if ( pFolder->iterator.pHashItem == NULL ) {
      errcode = PSO_INVALID_ITERATOR;
      goto error_handler;
   }

   if ( pFolder->object.pSession->terminated ) {
      errcode = PSO_SESSION_IS_TERMINATED;
      goto error_handler;
   }
   
   pMemFolder = (psonFolder *) pFolder->object.pMyMemObject;

   ok = psonAPIFolderGetNext( pMemFolder,
                              &pFolder->iterator,
                              &pFolder->object.pSession->context );
   PSO_POST_CONDITION( ok == true || ok == false );
   if ( ! ok ) goto error_handler;
   
   memset( pEntry, 0, sizeof( psoFolderEntry ) );
   GET_PTR( pDescriptor, pFolder->iterator.pHashItem->dataOffset, 
                         psonObjectDescriptor );
   pEntry->type = pDescriptor->apiType;
   pEntry->status = pFolder->iterator.status;
   pEntry->nameLengthInBytes = pDescriptor->nameLengthInBytes;
   memcpy( pEntry->name, pDescriptor->originalName, pDescriptor->nameLengthInBytes );

   return PSO_OK;

error_handler:
   if ( errcode != PSO_OK ) {
      psocSetError( &pFolder->object.pSession->context.errorHandler, 
         g_psoErrorHandle, errcode );
   }
   else {
      errcode = psocGetLastError( &pFolder->object.pSession->context.errorHandler );
   }
   
   return errcode;
}
Esempio n. 11
0
void display (mutilist_t *node, int index) {
    int i;
    if (!node) {
        return;
    }
    for (i = 0; i < index; ++i) {
        printf ("   ");
    }
    printf ("%d\n",node->val);
    if (node->children.post) {
        display (GET_PTR(mutilist_t,sibling,node->children.post), index+1);
    }
    if (node->sibling.post) {
        display (GET_PTR(mutilist_t,sibling,node->sibling.post), index);
    }
}
Esempio n. 12
0
uint mprGetAllocBlockCount(MprCtx ptr)
{
    MprBlk	*bp, *firstChild, *cp;
    uint	count;

    mprAssert(VALID_BLK(ptr));

    if (ptr == 0) {
        return 0;
    }

    bp = GET_HDR(ptr);
    mprAssert(VALID_HDR(bp));

    /*
     *	Add one for itself
     */
    count = 1;
    if ((firstChild = bp->children) != 0) {
        cp = firstChild;
        do {
            count += mprGetAllocBlockCount(GET_PTR(cp));
            cp = cp->next;
        } while (cp != firstChild);
    }
    return count;
}
Esempio n. 13
0
void psonSeqSetRelease( psonSeqSet         * pSeqSet,
                        psonHashItem       * pHashItem,
                        psonSessionContext * pContext )
{
   psonTxStatus * txSeqSetStatus;
   
   PSO_PRE_CONDITION( pSeqSet   != NULL );
   PSO_PRE_CONDITION( pHashItem != NULL );
   PSO_PRE_CONDITION( pContext  != NULL );
   PSO_PRE_CONDITION( pSeqSet->memObject.objType == PSON_IDENT_MAP );
   PSO_TRACE_ENTER_NUCLEUS( pContext );

   GET_PTR(pContext->pBaseAddress, txSeqSetStatus, pSeqSet->nodeObject.txStatusOffset, psonTxStatus );

   txSeqSetStatus->usageCounter--;

   /*
    * Do we need to resize? We need both conditions here:
    *
    *   - txSeqSetStatus->usageCounter someone has a pointer to the data
    *
    *   - nodeObject.txCounter: offset to some of our data is part of a
    *                           transaction.
    *
    * Note: we do not check the return value of psonHashResize since the
    *       current function returns void. Let's someone else find that 
    *       we are getting low on memory...
    */
   if ( txSeqSetStatus->usageCounter == 0 ) {
      if ( pSeqSet->hashObj.enumResize != PSON_HASH_NO_RESIZE ) {
         psonHashResize( &pSeqSet->hashObj, pContext );
      }
   }
   PSO_TRACE_EXIT_NUCLEUS( pContext, true );
}
Esempio n. 14
0
static int growSlab(MPR_LOC_DEC(ctx, loc), MprSlab *slab, uint size, uint inc)
{
    MprBlk			*bp;
    MprSlabBlock	*sb;
    int				i, chunkSize, len;

    mprAssert(VALID_BLK(ctx));
    mprAssert(slab);
    mprAssert(size > 0);

    /*
     *	Take the maximum requested by anyone
     */
    slab->preAllocateIncr = max(slab->preAllocateIncr, inc);

    /*
     *	We allocate an array of blocks each of user "size" bytes.
     */
    chunkSize = HDR_SIZE + size;
    len = chunkSize * slab->preAllocateIncr;
    bp = mprAllocBlock(MPR_LOC_PASS(ctx, loc), len);

#if BLD_DEBUG
    memset(bp, 0xf1, len);
#endif

    if (bp == 0) {
        mprAssert(0);
        return MPR_ERR_MEMORY;
    }
    bp->flags |= ALLOC_FLAGS_IS_SLAB;

    /*
     *	We store the slab information in the user data portion
     */
    sb = (MprSlabBlock*) GET_PTR(bp);


    sb = (MprSlabBlock*) ((char*) sb + len - chunkSize);
    for (i = slab->preAllocateIncr - 1; i >= 0; i--) {
        sb->next = slab->next;
        slab->next = sb;
        sb = (MprSlabBlock*) ((char*) sb - chunkSize);
    }

#if BLD_FEATURE_ALLOC_STATS
    {
        MprSlabStats	*stats;
        stats = &slab->stats;
        stats->freeCount += slab->preAllocateIncr;
        if (stats->freeCount > stats->peakFreeCount) {
            stats->peakFreeCount = stats->freeCount;
        }
    }
#endif

    return 0;
}
Esempio n. 15
0
int psoHashMapDefinition( PSO_HANDLE            objectHandle,
                          psoObjectDefinition * definition,
                          psoUint32             length )
{
   psoaHashMap * pHashMap;
   psonHashMap * pMemHashMap;
   int errcode = 0;
   psonSessionContext * pContext;
   psoObjectDefinition * pMyDefinition = NULL;
   uint32_t myLength;
   
   pHashMap = (psoaHashMap *) objectHandle;
   if ( pHashMap == NULL ) return PSO_NULL_HANDLE;
   
   if ( pHashMap->object.type != PSOA_HASH_MAP ) return PSO_WRONG_TYPE_HANDLE;

   if ( pHashMap->object.pSession->terminated ) return PSO_SESSION_IS_TERMINATED;
   
   pContext = &pHashMap->object.pSession->context;
   pContext->indent = 0;
   PSO_TRACE_ENTER_API( pContext );

   if ( definition == NULL ) {
      errcode = PSO_NULL_POINTER;
      goto error_handler;
   }
   
   if ( length < sizeof(psoObjectDefinition) ) {
      errcode = PSO_INVALID_LENGTH;
      goto error_handler;
   }

   pMemHashMap = (psonHashMap *) pHashMap->object.pMyMemObject;

   GET_PTR( pHashMap->object.pSession->context.pBaseAddress, pMyDefinition, pMemHashMap->dataDefOffset, psoObjectDefinition );
   myLength = offsetof(psoObjectDefinition, dataDef) + 
      pMyDefinition->dataDefLength;
   if ( myLength >= length ) {
      // possibly truncated. This is ok
      memcpy( definition, pMyDefinition, length );
   }
   else {
      // Make sure that the "leftover" is zeroed
      memset( definition, 0, length );
      memcpy( definition, pMyDefinition, myLength );
   }
   
   PSO_TRACE_EXIT_API( pContext, true );
   return PSO_OK;

error_handler:

   psocSetError( &pContext->errorHandler, g_psoErrorHandle, errcode );
   
   PSO_TRACE_EXIT_API( pContext, false );
   return errcode;
}
Esempio n. 16
0
bool psonSeqSetGetFirst( psonSeqSet         * pSeqSet,
                         psonSeqSetItem     * pItem,
                         uint32_t             keyLength,
                         uint32_t             bufferLength,
                         psonSessionContext * pContext )
{
   psonHashItem * pHashItem = NULL;
   psonTxStatus * txSeqSetStatus;
   bool found;
   
   PSO_PRE_CONDITION( pSeqSet != NULL );
   PSO_PRE_CONDITION( pItem    != NULL )
   PSO_PRE_CONDITION( pContext != NULL );
   PSO_PRE_CONDITION( pSeqSet->memObject.objType == PSON_IDENT_MAP );
   PSO_TRACE_ENTER_NUCLEUS( pContext );

   GET_PTR(pContext->pBaseAddress, txSeqSetStatus, pSeqSet->nodeObject.txStatusOffset, psonTxStatus );

   if ( txSeqSetStatus->status & PSON_TXS_DESTROYED || 
      txSeqSetStatus->status & PSON_TXS_DESTROYED_COMMITTED ) {
      psocSetError( &pContext->errorHandler, g_psoErrorHandle, PSO_OBJECT_IS_DELETED );
      PSO_TRACE_EXIT_NUCLEUS( pContext, false );
      return false;
   }
   
   found = psonHashGetFirst( &pSeqSet->hashObj, 
                             &pHashItem );
   if ( ! found ) {
      psocSetError( &pContext->errorHandler, g_psoErrorHandle, PSO_IS_EMPTY );
      PSO_TRACE_EXIT_NUCLEUS( pContext, false );
      return false;
   }
   
   /*
    * These tests cannot be done in the API (before calling the 
    * current function) since we do not know the item size. They 
    * could be done after but this way makes the code faster.
    */
   if ( bufferLength < pHashItem->dataLength ) {
      psocSetError( &pContext->errorHandler, 
                    g_psoErrorHandle, PSO_INVALID_LENGTH );
      PSO_TRACE_EXIT_NUCLEUS( pContext, false );
      return false;
   }
   if ( keyLength < pHashItem->keyLength ) {
      psocSetError( &pContext->errorHandler, 
                    g_psoErrorHandle, PSO_INVALID_LENGTH );
      PSO_TRACE_EXIT_NUCLEUS( pContext, false );
      return false;
   }

   txSeqSetStatus->usageCounter++;
   pItem->pHashItem = pHashItem;

   PSO_TRACE_EXIT_NUCLEUS( pContext, true );
   return true;
}
Esempio n. 17
0
void psonSetStatus( psonSet            * pSet,
                    psoObjStatus       * pStatus,
                    psonSessionContext * pContext )
{
   psonSetItem * pSetItem = NULL;
   psonLinkNode * pNode = NULL;
   psonTxStatus  * txStatus;
   bool okList;
   psonTreeNode * pSetNode = NULL;
   
   PSO_PRE_CONDITION( pSet     != NULL );
   PSO_PRE_CONDITION( pStatus  != NULL );
   PSO_PRE_CONDITION( pContext != NULL );
   PSO_TRACE_ENTER_NUCLEUS( pContext );

   GET_PTR(pContext->pBaseAddress, pSetNode, pSet->nodeOffset, psonTreeNode );
   GET_PTR(pContext->pBaseAddress, txStatus, pSetNode->txStatusOffset, psonTxStatus );

   pStatus->status = txStatus->status;
   pStatus->numDataItem = pSet->listOfElements.currentSize;
   pStatus->maxDataLength = 0;
   pStatus->maxKeyLength  = 0;

   if ( pStatus->numDataItem > 0 ) {
      /* This call can only fail if the queue is empty. */
      okList = psonLinkedListPeakFirst( &pSet->listOfElements, 
                                        &pNode,
                                        pContext );

      while ( okList ) {
         pSetItem = (psonSetItem*)
            ((char*)pNode - offsetof( psonSetItem, node ));
         if ( pSetItem->dataLength > pStatus->maxDataLength ) {
            pStatus->maxDataLength = pSetItem->dataLength;
         }
      
         okList =  psonLinkedListPeakNext( &pSet->listOfElements, 
                                           pNode, 
                                           &pNode,
                                           pContext );
      }
   }
   PSO_TRACE_EXIT_NUCLEUS( pContext, true );
}
Esempio n. 18
0
int destroy_task(int id) 
{ 
	struct task *tsk;
	int x;
	int result;
  
	result = FAILURE;

	x = mk_enter(); /* enter critical block */
    
    /* check everything */
	if (0 <= id && id < MAX_TSK && TST_PTR(id,tsk)) 
	{        
		tsk = GET_PTR(id,tsk);
        
		if (tsk->thread_count == 0 && curr_task != id && tsk->state == ALIVE) 
		{
			result = SUCCESS;
			tsk->state = UNLOADING;
		}
        else
        {
            if(curr_task == id)
                set_error(SERR_SAME_TASK);
            else
                set_error(SERR_INVALID_TSK);
        }
	}
    else
    {
        if(0 > id || id >= MAX_TSK)
            set_error(SERR_INVALID_ID);
        else
            set_error(SERR_INVALID_TSK);
    }
    
	mk_leave(x); /* exit critical block */

	if (result == SUCCESS) 
	{
		result = arch_destroy_task(id); /* if cannot destroy, set result accordingly */
        
		if (result == SUCCESS) 
		{
			delete_task_smo(id);
			delete_task_ports(tsk);
#ifdef METRICS
            metrics.tasks--;
#endif			
			sfree(tsk, id, SALLOC_TSK);
            set_error(SERR_OK);
		}		
	}

	return result;
}
Esempio n. 19
0
int psoLifoDefinition( PSO_HANDLE            objectHandle, 
                       psoObjectDefinition * definition,
                       psoUint32             length )
{
   psoaLifo * pLifo;
   psonQueue * pMemLifo;
   int errcode = PSO_OK;
   psonSessionContext * pContext;
   psoObjectDefinition * pMyDefinition = NULL;
   uint32_t myLength;
   
   pLifo = (psoaLifo *) objectHandle;
   if ( pLifo == NULL ) return PSO_NULL_HANDLE;
   
   if ( pLifo->object.type != PSOA_LIFO ) return PSO_WRONG_TYPE_HANDLE;

   pContext = &pLifo->object.pSession->context;

   if ( definition == NULL ) {
      psocSetError( &pContext->errorHandler, g_psoErrorHandle, PSO_NULL_POINTER );
      return PSO_NULL_POINTER;
   }

   if ( length < sizeof(psoObjectDefinition) ) {
      psocSetError( &pContext->errorHandler, g_psoErrorHandle, PSO_INVALID_LENGTH );
      return PSO_INVALID_LENGTH;
   }

   if ( ! pLifo->object.pSession->terminated ) {
      pMemLifo = (psonQueue *) pLifo->object.pMyMemObject;
      
      GET_PTR( pLifo->object.pSession->context.pBaseAddress, pMyDefinition, pMemLifo->dataDefOffset, psoObjectDefinition );
      myLength = offsetof(psoObjectDefinition, dataDef) + 
         pMyDefinition->dataDefLength;
      if ( myLength >= length ) {
         // possibly truncated. This is ok
         memcpy( definition, pMyDefinition, length );
      }
      else {
         // Make sure that the "leftover" is zeroed
         memset( definition, 0, length );
         memcpy( definition, pMyDefinition, myLength );
      }
   }
   else {
      errcode = PSO_SESSION_IS_TERMINATED;
   }
   
   if ( errcode != PSO_OK ) {
      psocSetError( &pContext->errorHandler, g_psoErrorHandle, errcode );
   }
   
   return errcode;
}
Esempio n. 20
0
/*static */rfid_status	icdrec_hf_reader_generic_command(struct rfid_device * thiz, uint8_t cmd,uint8_t * pmeta,size_t metalen,size_t resp_metalen)
{
	if(!thiz || thiz->state != RFID_READER_AVAILABLE) {
		return RFID_EINARG;
	}
	rfid_status status= RFID_ESUCCESS ;
	//TODO: Test

	HF_READER_NEW_REQ_PACKAGE(req,metalen);
	GET_SZ_BUILT(req) = icdrec_hf_reader_build_package(cmd,pmeta,metalen,GET_PTR(req),GET_LEN(req));
	RDBG(" CMD: 0x%X\n",cmd);
	RFID_HEXDUMP(GET_PTR(req),GET_LEN(req),"pkg",0);
	HF_READER_NEW_RESP_PACKAGE(res,resp_metalen);
	status = icdrec_hf_reader_transceive_bytes(thiz,GET_PTR(req),GET_SZ_BUILT(req),GET_PTR(res),GET_LEN(res),&GET_SZ_RES(res),20);
	switch (status) {
	case RFID_ESUCCESS:
	case RFID_EACK:
		RDBG("Success\n");
		break;
#if 1
	case RFID_EIO:
		RFATAL("IO error\n");
		break;
	case RFID_ENAK:
		RFATAL("NAK error\n");
		break;
	case RFID_ETIMEOUT:
		RFATAL("Time out\n");
		break;
	case RFID_ERESP:
		RFATAL("Failed responding\n");
		break;

#endif
	default:
		RFATAL("Unknown error\n");
		break;
	}
	CLEAR_WARNING(req);
	return  status;
}
Esempio n. 21
0
/*
 * This version of the function is to be used when:
 *  - you know that the object is in use and should not/cannot be removed
 *  - the calling function holds the lock
 */
static
void psonSetReleaseNoLock( psonSet            * pSet,
                           psonSetItem        * pSetItem,
                           psonSessionContext * pContext )
{
   psonTxStatus * txItemStatus, * txSetStatus;
   size_t len;
   psonTreeNode * pSetNode = NULL;
   
   PSO_PRE_CONDITION( pSet     != NULL );
   PSO_PRE_CONDITION( pSetItem != NULL );
   PSO_PRE_CONDITION( pContext != NULL );
   PSO_PRE_CONDITION( pSet->memObject.objType == PSON_IDENT_QUEUE );
   PSO_TRACE_ENTER_NUCLEUS( pContext );

   GET_PTR(pContext->pBaseAddress, pSetNode, pSet->nodeOffset, psonTreeNode );
   txItemStatus = &pSetItem->txStatus;
   GET_PTR(pContext->pBaseAddress, txSetStatus, pSetNode->txStatusOffset, psonTxStatus );
   
   txItemStatus->usageCounter--;
   txSetStatus->usageCounter--;

   if ( (txItemStatus->usageCounter == 0) && 
      psonTxStatusIsRemoveCommitted(txItemStatus, pContext) ) {
      /* Time to really delete the record! */
      psonLinkedListRemoveItem( &pSet->listOfElements, 
                                &pSetItem->node,
                                pContext );

      len =  pSetItem->dataLength + offsetof( psonSetItem, data );
      psonFree( &pSet->memObject, 
                (unsigned char *) pSetItem, 
                len, 
                pContext );

      pSetNode->txCounter--;
   }
   PSO_TRACE_EXIT_NUCLEUS( pContext, true );
}
Esempio n. 22
0
void test_pass( void ** state )
{
#if defined(PSO_UNIT_TESTS)
   bool ok;
   psonTreeNode * pDescriptor;
   psonTxStatus * txItemStatus;
   psoObjectDefinition def = { PSO_FOLDER, 0, 0 };
   
   GET_PTR(context.pBaseAddress, pDescriptor, item.pHashItem->dataOffset, psonTreeNode );
   GET_PTR(context.pBaseAddress, txItemStatus, pDescriptor->txStatusOffset, psonTxStatus );
   assert_true( txItemStatus->parentCounter == 1 );
   assert_true( status.usageCounter == 1 );
   
   ok = psonFolderRelease( pFolder, &item, &context );
   assert_true( ok );
   assert_true( txItemStatus->parentCounter == 0 );
   assert_true( status.usageCounter == 0 );
   assert_true( node.txCounter == 2 );
   
#endif
   return;
}
Esempio n. 23
0
static void install_int18_hack(void)
{
    static const uint8_t int18_hack[] =
    {
	0xcd, 0x18,			/* int $0x18 */
	0xea, 0xf0, 0xff, 0x00, 0xf0,	/* ljmpw $0xf000,$0xfff0 */
	0xf4				/* hlt */
    };
    uint16_t *retcode;

    retcode = GET_PTR(*(far_ptr_t *)((char *)GET_PTR(InitStack) + 44));

    /* Don't do this if the return already points to int $0x18 */
    if (*retcode != 0x18cd) {
	uint32_t efi_ptr;
	bool efi = false;

	for (efi_ptr = 0xe0000 ; efi_ptr < 0x100000 ; efi_ptr += 16) {
	    if (is_efi((const struct efi_struct *)efi_ptr)) {
		efi = true;
		break;
	    }
	}

	if (efi) {
	    uint8_t *src = GET_PTR(InitStack);
	    uint8_t *dst = src - sizeof int18_hack;

	    memmove(dst, src, 52);
	    memcpy(dst+52, int18_hack, sizeof int18_hack);
	    InitStack.offs -= sizeof int18_hack;

	    /* Clobber the return address */
	    *(uint16_t *)(dst+44) = OFFS_WRT(dst+52, InitStack.seg);
	    *(uint16_t *)(dst+46) = InitStack.seg;
	}
    }
}
Esempio n. 24
0
int mprValidateAllocTree(MprCtx ptr)
{
#if VALIDATE_ALLOC
    MprBlk			*bp, *cp, *firstChild;

    mprAssert(ptr);
    mprAssert(VALID_BLK(ptr));

    bp = GET_HDR(ptr);

    mprValidateBlock(GET_PTR(bp));

    if ((firstChild = bp->children) != 0) {
        cp = firstChild;
        do {
            mprValidateAllocTree(GET_PTR(cp));
            cp = cp->next;
        } while (cp != firstChild);
    }

#endif
    return 0;
}
Esempio n. 25
0
void mprSetRequiredAlloc(MprCtx ptr, bool recurse)
{
    MprBlk	*bp, *firstChild, *cp;

    bp = GET_HDR(ptr);

    bp->flags |= ALLOC_FLAGS_REQUIRED;

    if (recurse && (firstChild = bp->children) != 0) {
        cp = firstChild;
        do {
            mprSetRequiredAlloc(GET_PTR(cp), recurse);
            cp = cp->next;
        } while (cp != firstChild);
    }
}
Esempio n. 26
0
void *mprGetAllocParent(MprCtx ptr)
{
    MprBlk	*bp;

    mprAssert(VALID_BLK(ptr));

    if (ptr == 0) {
        return 0;
    }

    bp = GET_HDR(ptr);
    mprAssert(VALID_HDR(bp));

    CHECK_HDR(bp);

    return GET_PTR(bp->parent);
}
Esempio n. 27
0
File: free.c Progetto: Adpa18/malloc
void    *getFreeBlock(t_block *tmp, size_t size, size_t *max)
{
    void    *ptr;

    *max = 0;
    ptr = NULL;
    while (tmp->next)
    {
        if (tmp->isFree && tmp->size >= size)
        {
            tmp->isFree = false;
            ptr = GET_PTR(tmp);
        }
        else if (tmp->size > *max)
            *max = tmp->size;
        tmp = tmp->next;
    }
    return (ptr);
}
Esempio n. 28
0
int psoHashMapKeyDefLength( PSO_HANDLE   objectHandle,
                            psoUint32  * pLength )
{
   psoaHashMap * pHashMap;
   psonHashMap * pMemHashMap;
   int errcode = 0;
   psonSessionContext * pContext;
   psoKeyDefinition * pMyDefinition = NULL;
   
   pHashMap = (psoaHashMap *) objectHandle;
   if ( pHashMap == NULL ) return PSO_NULL_HANDLE;
   
   if ( pHashMap->object.type != PSOA_HASH_MAP ) return PSO_WRONG_TYPE_HANDLE;

   if ( pHashMap->object.pSession->terminated ) return PSO_SESSION_IS_TERMINATED;
   
   pContext = &pHashMap->object.pSession->context;
   pContext->indent = 0;
   PSO_TRACE_ENTER_API( pContext );

   if ( pLength == NULL ) {
      errcode = PSO_NULL_POINTER;
      goto error_handler;
   }
   *pLength = 0;

   pMemHashMap = (psonHashMap *) pHashMap->object.pMyMemObject;

   GET_PTR( pHashMap->object.pSession->context.pBaseAddress, pMyDefinition, pMemHashMap->keyDefOffset, psoKeyDefinition );
   *pLength = offsetof(psoKeyDefinition, definition) + 
      pMyDefinition->definitionLength;
   
   PSO_TRACE_EXIT_API( pContext, true );
   return PSO_OK;

error_handler:

   psocSetError( &pContext->errorHandler, g_psoErrorHandle, errcode );
   
   PSO_TRACE_EXIT_API( pContext, false );
   return errcode;
}
Esempio n. 29
0
void StringBuilder::append(Value v, bool raw) {
    void *ptr = GET_PTR(v);
    if (IS_STRING(v)) {
        if (!raw) { append('\''); }
        append(GET_CSTR(v), len(v));
        if (!raw) { append('\''); }
    } else if (IS_NUM(v)) {
        append(GET_NUM(v));
        return;
    } else if (IS_ARRAY(v)) {
        Array *a = (Array *) ptr;
        int size = a->size();
        append('[');
        for (int i = 0; i < size; ++i) {
            append(i ? ", " : "");
            append(a->getI(i));
        }
        append(']');
    } else if (IS_MAP(v)) {
        Map *m = (Map *) ptr;
        int size = m->size();
        append('{');
        Value *keys = m->keyBuf();
        Value *vals = m->valBuf();
        for (int i = 0; i < size; ++i) {
            append(i ? ", " : "");
            append(keys[i]);
            append(':');
            append(vals[i]);
        }
        append('}');
    } else if (IS_NIL(v)) {
        append("nil");
    } else {
        append('<');
        append(typeStr(v));
        append('>');
        char tmp[32];
        snprintf(tmp, sizeof(tmp), "%p", ptr);
        append(tmp);
    }
}
Esempio n. 30
0
static void slabFree(MprBlk *bp)
{
    MprSlab			*slab;
    MprApp			*app;
    void			*ptr;
    int				slabIndex;

    mprAssert(VALID_HDR(bp));

    slabIndex = GET_SLAB(bp->size);
    mprAssert(0 <= slabIndex && slabIndex < MPR_MAX_SLAB);

    if (0 <= slabIndex && slabIndex < MPR_MAX_SLAB) {
        mprLock(bp->app->allocLock);
        slab = &bp->app->alloc.slabs[slabIndex];
        app = bp->app;

#if BLD_DEBUG
        memset(bp, 0xfc, bp->size + HDR_SIZE);
#endif

        ptr = GET_PTR(bp);
        ((MprSlabBlock*) ptr)->next = slab->next;
        slab->next = ((MprSlabBlock*) ptr);

#if BLD_FEATURE_ALLOC_STATS
        {
            MprSlabStats	*slabStats;
            slabStats = &slab->stats;

            slabStats->freeCount++;
            slabStats->allocCount--;

            if (slabStats->freeCount >= slabStats->peakFreeCount) {
                slabStats->peakFreeCount = slabStats->freeCount;
            }
        }
#endif
        mprUnlock(app->allocLock);
    }
}