⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addmgr.c

📁 Next BIOS Source code : Extensible Firmware Interface
💻 C
📖 第 1 页 / 共 2 页
字号:
/*-----------------------------------------------------------------------------
 *      File:   addmgr.c
 *
Copyright (c)  1999 - 2002 Intel Corporation. All rights reserved
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.

 *-----------------------------------------------------------------------------
 */
/* 
 * INTEL CONFIDENTIAL 
 * This file, software, or program is supplied under the terms of a 
 * license agreement or nondisclosure agreement with Intel Corporation 
 * and may not be copied or disclosed except in accordance with the 
 * terms of that agreement. This file, software, or program contains 
 * copyrighted material and/or trade secret information of Intel 
 * Corporation, and must be treated as such. Intel reserves all rights 
 * in this material, except as the license agreement or nondisclosure 
 * agreement specifically indicate. 
 */ 
/* 
 * WARNING: EXPORT RESTRICTED. 
 * This software is subject to the U.S. Export Administration Regulations 
 * and other U.S. law, and may not be exported or re-exported to certain 
 * countries (currently Afghanistan (Taliban-controlled areas), Cuba, Iran, 
 * Iraq, Libya, North Korea, Serbia (except Kosovo), Sudan and Syria) or to 
 * persons or entities prohibited from receiving U.S. exports (including Denied 
 * Parties, Specially Designated Nationals, and entities on the Bureau of 
 * Export Administration Entity List or involved with missile technology or 
 * nuclear, chemical or biological weapons).
 */ 
/*
 * This file contains the code used to manage add-in modules.
 */
/*
 * The CSSM_BIS implementation of this code was inspected 8/19/98.
 */

#include "internal.h"

cssm_ATTACHED_MODULE_NODE_PTR ModuleListHead = NULL;

/*------------------------------------------------------------------------------
 *Name: cssm_GetHandle
 *
 *Description:
 * Return a 32 bit number for use as a handle, 
 *
 *Parameters: 
 * None
 *
 *Returns: 
 * a CSSM_HANDLE
 *
 *----------------------------------------------------------------------------*/
CSSM_HANDLE cssm_GetHandle ()
{
    static void * Value = (void *) 0xFF;
    Value = (void *) (& (((unsigned char *) Value)[1]));
    return (CSSM_HANDLE)Value;
}


/*------------------------------------------------------------------------------
 *Name: cssm_GetModuleRecord
 *
 *Description:
 * This function gets the module information record given the addin handle.
 * It returns a pointer to the record and, if requested, 
 * callback functions for the module.
 *
 *Parameters:
 * Handle      (input) - Handle of addin whose info is to be found
 * ServiceType (input) - Type of addin service to be retrieved
 * CallBack   (output) - Pointer to a structure pointer that will hold
 *                       the callback functions registered by the addin
 *
 *Returns:
 * NULL - In the case of failure.
 * not NULL - Pointer to the module information.
 *----------------------------------------------------------------------------*/
cssm_ATTACHED_MODULE_NODE_PTR cssm_GetModuleRecord (CSSM_HANDLE Handle,
                                                  CSSM_SERVICE_MASK ServiceType,
                                                  void **CallBack)
{
    cssm_ATTACHED_MODULE_NODE_PTR ModuleInfo;

    /* Make sure that app has done a CSSM_Init */
    if (cssm_CheckInit () == CSSM_FAIL)
        return NULL;

    /* Clear the error */
    CSSM_ClearError ();
	
    /* Iterate through the addin list looking for the handle */    
    ModuleInfo = ModuleListHead;
    while (ModuleInfo) {
        cssm_ATTACH_INFO_NODE_PTR HandleInfo = ModuleInfo->AttachInfo;

        while (HandleInfo) {          
            if (Handle == HandleInfo->Handle)
                break;
            HandleInfo = HandleInfo->Next;
        }
        if (HandleInfo) break;

        ModuleInfo = ModuleInfo->Next;
    }
	
    /* If the handle was not found, return failure */
    if (!ModuleInfo) {
        CSSM_SetError (&CssmGUID, CSSM_INVALID_ADDIN_HANDLE);
        return NULL;
    }

    /* If requested, get the callback function pointer for this addin */
    if (CallBack) {
        uint32 i;

        for (i=0; i<ModuleInfo->AddInJT->NumberOfServiceTables; i++) {
            if (ModuleInfo->AddInJT->Services[i].ServiceType == ServiceType) {
                *CallBack = 
                   ModuleInfo->AddInJT->Services[i].FunctionTable.ServiceFuncs;
                break;
            }
        }

        if (i == ModuleInfo->AddInJT->NumberOfServiceTables) {
            CSSM_SetError (&CssmGUID, CSSM_FUNCTION_NOT_IMPLEMENTED);
            return NULL;
        }
    }

    return ModuleInfo;
}


/*------------------------------------------------------------------------------
 *Name: cssm_GetModuleRecordByGUID
 *
 *Description:
 * This function gets the module information record given the addin GUID.
 * It returns a pointer to the record.
 *
 *Parameters:
 * GUID (input) - GUID of the addin whose info is to be found
 *
 *Returns:
 * NULL - If this GUID is not found.
 * not NULL - Pointer to the module information for this addin.
 *----------------------------------------------------------------------------*/
cssm_ATTACHED_MODULE_NODE_PTR cssm_GetModuleRecordByGUID 
                                               (const CSSM_GUID_PTR GUID)
{
    cssm_ATTACHED_MODULE_NODE_PTR ModuleInfo;

    /* Existence of GUID pointer is checked by calling function */
    /* Iterate through the addin list looking for the matching GUID */   
    ModuleInfo = ModuleListHead;
    while (ModuleInfo) {
        if (cssm_memcmp (GUID, &ModuleInfo->GUID, sizeof(CssmGUID)) == 0) 
            break;
        ModuleInfo = ModuleInfo->Next;
    }
    
    return ModuleInfo;
}


/*------------------------------------------------------------------------------
 *Name: cssm_NewModuleRecord
 *
 *Description:
 * Allocates, initializes and adds to the attached module list a node for 
 * the module identified by the input GUID. The presence of this empty node 
 * indicates that the addin with this GUID is about to be attached and 
 * register its services. This is performed separately from RegisterServices
 * to insure that applications cannot register as CSSM addins.
 *
 *Parameters:
 * GUID (input) - GUID of the addin 
 *
 *Returns:
 * CSSM_FAIL - Either an addin with this GUID is already loaded or
 *             insufficient memory was available.
 * CSSM_OK - Node successfully added.
 *----------------------------------------------------------------------------*/
CSSM_RETURN cssm_NewModuleRecord (const CSSM_GUID_PTR GUID)
{
    cssm_ATTACHED_MODULE_NODE_PTR ModuleInfo;
	
    /* Existence of GUID pointer is checked by calling function */
    /* Verify that a record for this GUID does not already exist */
    if (cssm_GetModuleRecordByGUID(GUID) != NULL) {
        CSSM_SetError (&CssmGUID, CSSM_INVALID_GUID);
        return CSSM_FAIL;
    }

    /* Allocate memory for the new node */
    ModuleInfo = cssm_calloc(1, sizeof(cssm_ATTACHED_MODULE_NODE), 0);
    if (!ModuleInfo) {
        CSSM_SetError (&CssmGUID, CSSM_MEMORY_ERROR);
        return CSSM_FAIL;
    }
	
    /* Initialize the new node */
    ModuleInfo->GUID = *GUID;
    
    /* Insert the new node into the addin list */
    ModuleInfo->Next = ModuleListHead;
    ModuleListHead = ModuleInfo;

    return CSSM_OK;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -