コード例 #1
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
int query_DEHT ( DEHT *ht, const unsigned char *key, int keyLength, 
				 const unsigned char *data, int dataMaxAllowedLength)
{
	int ret = DEHT_STATUS_FAIL;

	byte_t * tempKeyBlock = NULL;
	DEHT_DISK_PTR keyBlockDiskOffset = 0;
	ulong_t keyIndex = 0;
	

	TRACE_FUNC_ENTRY();

	CHECK(NULL != ht);
	CHECK(NULL != key);
	CHECK(NULL != data);

	/* allocate a buffer for DEHT_queryEx */
	tempKeyBlock = malloc(KEY_FILE_BLOCK_SIZE(ht));
	CHECK_MSG("malloc", (NULL != tempKeyBlock));
	
	ret = DEHT_queryEx(ht, key, keyLength, data, dataMaxAllowedLength, tempKeyBlock, KEY_FILE_BLOCK_SIZE(ht), 
				  &keyBlockDiskOffset, &keyIndex);

	goto LBL_CLEANUP;	

LBL_ERROR:
	ret = DEHT_STATUS_FAIL;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	FREE(tempKeyBlock);

	TRACE_FUNC_EXIT();
	return ret;
}
コード例 #2
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
bool_t DEHT_removeFiles(const char * filenamePrefix)
{
	bool_t ret = FALSE;
	DEHT tempContainer;

	TRACE_FUNC_ENTRY();

	CHECK(NULL != filenamePrefix);

	memset(&tempContainer, 0, sizeof(tempContainer));

	DEHT_formatFilenames(&tempContainer, filenamePrefix);

	CHECK(DEHT_removeFilesInternal(&tempContainer));

	ret = TRUE;
	goto LBL_CLEANUP;

LBL_ERROR:
	ret = FALSE;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	TRACE_FUNC_EXIT();
	return ret;
}
コード例 #3
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
int DEHT_writeUserBytes(DEHT * ht)
{
	bool_t ret = DEHT_STATUS_FAIL;

	TRACE_FUNC_ENTRY();
	CHECK(NULL != ht);

	if ((NULL == ht->userBuf) || (0 == ht->header.numUnrelatedBytesSaved)) {
		ret = DEHT_STATUS_NOT_NEEDED;
		goto LBL_CLEANUP;
	}

	CHECK_MSG(ht->sDatafileName, (pfwrite(ht->dataFP, DATA_FILE_OFFSET_TO_USER_BYTES, ht->userBuf, ht->header.numUnrelatedBytesSaved)));

	/*! Note that unlink write_DEHT_pointers_table(), we DO NOT free the block here. Since this interface was
	    not dictated by the project spec, we chose what we found to be a more convenient interface for our use-case,
	    namely - only writing the data to disk, but not freeing the reference here !*/

	ret = DEHT_STATUS_SUCCESS;
	goto LBL_CLEANUP;

LBL_ERROR:
	ret = DEHT_STATUS_FAIL;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	TRACE_FUNC_EXIT();
	return ret;
}
コード例 #4
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
int read_DEHT_pointers_table(DEHT *ht)
{
	int ret = DEHT_STATUS_FAIL;

	TRACE_FUNC_ENTRY();

	CHECK(NULL != ht);

	if (NULL != ht->hashTableOfPointersImageInMemory) {
		return DEHT_STATUS_NOT_NEEDED;
	}

	/* alloc cache */
	ht->hashTableOfPointersImageInMemory = malloc(KEY_FILE_FIRST_BLOCK_PTRS_SIZE(ht));
	CHECK_MSG("malloc", (NULL != ht->hashTableOfPointersImageInMemory));

	/* read the offset table */
	CHECK_MSG(ht->sKeyfileName, (pfread(ht->keyFP, KEY_FILE_OFFSET_TO_FIRST_BLOCK_PTRS(ht), (byte_t *) ht->hashTableOfPointersImageInMemory, KEY_FILE_FIRST_BLOCK_PTRS_SIZE(ht))));

	ret = DEHT_STATUS_SUCCESS;
	goto LBL_CLEANUP;

LBL_ERROR:
	/* on error, free the buffer */
	FREE(ht->hashTableOfPointersImageInMemory);

	ret = DEHT_STATUS_FAIL;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	TRACE_FUNC_EXIT();
	return ret;
}
コード例 #5
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
static void DEHT_freeResources(DEHT * ht, bool_t removeFiles)
{
	TRACE_FUNC_ENTRY();

	CHECK (NULL != ht);

	(void) fflush(ht->keyFP);
	FCLOSE(ht->keyFP);
	(void) fflush(ht->dataFP);
	FCLOSE(ht->dataFP);

	/* free ht cache if present */
	FREE(ht->hashTableOfPointersImageInMemory);
	FREE(ht->hashPointersForLastBlockImageInMemory);
	FREE(ht->userBuf);

	if (removeFiles) {
		/* attempt to remove bad files. Errors are silenced */
		CHECK(DEHT_removeFilesInternal(ht));
	}

	/* finally, free the ht itself */
	FREE(ht);

	goto LBL_CLEANUP;

LBL_ERROR:
	/* do nothing special - just quit */
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	/* bye */
	TRACE_FUNC_EXIT();
	return;
}
コード例 #6
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
DEHT * load_DEHT_from_files(const char *prefix, hashKeyIntoTableFunctionPtr hashfun, hashKeyforEfficientComparisonFunctionPtr validfun)
{
	bool_t errorState = FALSE;

	DEHT * ht = NULL;

	TRACE_FUNC_ENTRY();

	ht = DEHT_initInstance(prefix, "r+b", hashfun, validfun);
	CHECK(NULL != ht);

	/* load dict settings from file */
	CHECK_MSG(ht->sKeyfileName, (1 == fread(&(ht->header), sizeof(ht->header), 1, ht->keyFP)));
	CHECK_MSG("corrupted key file", (DEHT_HEADER_MAGIC == ht->header.magic));


	goto LBL_CLEANUP;	

LBL_ERROR:
	errorState = TRUE;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	if (errorState) {
		if (NULL != ht) {
			DEHT_freeResources(ht, FALSE);
			ht = NULL;
		}
	}

	TRACE_FUNC_EXIT();

	return ht;
}
コード例 #7
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
static bool_t DEHT_readDataAtOffset(DEHT * ht, DEHT_DISK_PTR dataBlockOffset, 
			     byte_t * data, ulong_t dataMaxAllowedLength, ulong_t * bytesRead)
{
	bool_t ret = FALSE;

	byte_t dataLen = 0;

	TRACE_FUNC_ENTRY();

	CHECK(NULL != ht);
	CHECK(NULL != data);
	CHECK(NULL != bytesRead);
	*bytesRead = 0;

	CHECK_MSG(ht->sDatafileName, (pfread(ht->dataFP, dataBlockOffset, &dataLen, sizeof(dataLen))));

	TRACE_FPRINTF((stderr, "TRACE: %s:%d (%s): data size is %d\n", __FILE__, __LINE__, __FUNCTION__, dataLen));

	*bytesRead = fread(data, 1, MIN(dataMaxAllowedLength, dataLen), ht->dataFP);
	CHECK(0 <= *bytesRead);

	ret = TRUE;
	goto LBL_CLEANUP;
	
LBL_ERROR:
	*bytesRead = 0;
	ret = FALSE;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	TRACE_FUNC_EXIT();
	return ret;

}
コード例 #8
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
int write_DEHT_pointers_table(DEHT *ht)
{
	int ret = DEHT_STATUS_FAIL;

	TRACE_FUNC_ENTRY();

	CHECK(NULL != ht);

	if (NULL == ht->hashTableOfPointersImageInMemory) {
		return DEHT_STATUS_NOT_NEEDED;
	}

	/* write the offset table */
	CHECK_MSG(ht->sKeyfileName, (pfwrite(ht->keyFP, KEY_FILE_OFFSET_TO_FIRST_BLOCK_PTRS(ht), (byte_t *) ht->hashTableOfPointersImageInMemory, KEY_FILE_FIRST_BLOCK_PTRS_SIZE(ht))));

	/* free the cache (according to the spec) */
	FREE(ht->hashTableOfPointersImageInMemory);

	ret = DEHT_STATUS_SUCCESS;
	goto LBL_CLEANUP;

LBL_ERROR:
	ret = DEHT_STATUS_FAIL;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	TRACE_FUNC_EXIT();
	return ret;
}
コード例 #9
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
static bool_t DEHT_findLastBlockForBucket(DEHT * ht, ulong_t bucketIndex, DEHT_DISK_PTR * lastBlockOffset)
{
	bool_t ret = FALSE;

	TRACE_FUNC_ENTRY();

	CHECK(NULL != ht);
	CHECK(bucketIndex < ht->header.numEntriesInHashTable);

	if ((NULL == ht->hashPointersForLastBlockImageInMemory) ||
	    (0 == ht->hashPointersForLastBlockImageInMemory[bucketIndex]) ) {
		TRACE("scanning chain");

		CHECK(DEHT_findLastBlockForBucketDumb(ht, bucketIndex, lastBlockOffset));
	}
	else {
		TRACE("using cache");
		*lastBlockOffset = ht->hashPointersForLastBlockImageInMemory[bucketIndex];
	}

	ret = TRUE;
	goto LBL_CLEANUP;

LBL_ERROR:
	TRACE_FUNC_ERROR();
	*lastBlockOffset = 0;
	ret = FALSE;

LBL_CLEANUP:
	TRACE_FUNC_EXIT();
	return ret;
}
コード例 #10
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
static bool_t DEHT_findFirstBlockForBucket(DEHT * ht, ulong_t bucketIndex, DEHT_DISK_PTR * blockOffset)
{
	bool_t ret = FALSE;

	TRACE_FUNC_ENTRY();

	CHECK(NULL != ht);
	CHECK(NULL != blockOffset);

	CHECK(bucketIndex < ht->header.numEntriesInHashTable);

	if (NULL != ht->hashTableOfPointersImageInMemory) {
		*blockOffset = ht->hashTableOfPointersImageInMemory[bucketIndex];
	}
	else {
		CHECK_MSG(ht->sKeyfileName, (pfread(ht->keyFP, KEY_FILE_OFFSET_TO_FIRST_BLOCK_PTRS(ht) + bucketIndex * sizeof(DEHT_DISK_PTR), (byte_t *) blockOffset, sizeof(*blockOffset))));
	}

	ret = TRUE;
	goto LBL_CLEANUP;

LBL_ERROR:
	ret = FALSE;
	*blockOffset = 0;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	TRACE_FUNC_EXIT();
	return ret;
}
コード例 #11
0
VOID
Acpi_UnregisterNotificationCallback (
    _In_ PACPI_CONTEXT AcpiCtx
    )
{
    WDFDEVICE device;

    TRACE_FUNC_ENTRY(TRACE_FLAG_ACPI);

    if (AcpiCtx->RegisteredForNotifications == FALSE)
    {
        goto Exit;
    }

    device = Context_GetWdfDevice(AcpiCtx);

    AcpiCtx->AcpiInterface.UnregisterForDeviceNotifications(AcpiCtx->AcpiInterface.Context);
    AcpiCtx->RegisteredForNotifications = FALSE;

    TRACE_INFO(TRACE_FLAG_ACPI, "[Device: 0x%p] Unregistered ACPI notifications", device);

Exit:

    TRACE_FUNC_EXIT(TRACE_FLAG_ACPI);
}
コード例 #12
0
NTSTATUS
Acpi_UcsiDsmReceiveData (
    _In_ PACPI_CONTEXT AcpiCtx
    )
{
    NTSTATUS status;

    PAGED_CODE();

    TRACE_FUNC_ENTRY(TRACE_FLAG_ACPI);

    status = Acpi_EvaluateUcsiDsm(AcpiCtx,
                                  UCSI_DSM_FUNCTION_RECEIVE_DATA_INDEX,
                                  nullptr);
    if (!NT_SUCCESS(status))
    {
        goto Exit;
    }

Exit:

    TRACE_FUNC_EXIT(TRACE_FLAG_ACPI);

    return status;
}
コード例 #13
0
VOID
Acpi_ReleaseHardware (
    _In_ PACPI_CONTEXT AcpiCtx
    )
{
    WDFDEVICE device;

    PAGED_CODE();

    TRACE_FUNC_ENTRY(TRACE_FLAG_ACPI);

    if (AcpiCtx->Initialized == FALSE)
    {
        goto Exit;
    }

    device = Context_GetWdfDevice(AcpiCtx);

    AcpiCtx->AcpiInterface.InterfaceDereference(AcpiCtx->AcpiInterface.Context);
    RtlZeroMemory(&AcpiCtx->AcpiInterface, sizeof(AcpiCtx->AcpiInterface));

    AcpiCtx->Initialized = FALSE;

    TRACE_INFO(TRACE_FLAG_ACPI, "[Device: 0x%p] ACPI release hardware completed", device);

Exit:

    TRACE_FUNC_EXIT(TRACE_FLAG_ACPI);
}
コード例 #14
0
void
I2CClose(
    _In_ PDEVICE_CONTEXT DeviceContext
)
/*++

Routine Description:

    This routine closes a handle to the I2C controller.

Arguments:

    DeviceContext - a pointer to the device context.

--*/
{
    TRACE_FUNC_ENTRY(TRACE_I2C);

    PAGED_CODE();

    if (DeviceContext->I2CIoTarget != WDF_NO_HANDLE)
    {
        TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_I2C, "Closing handle to I2C target");
        WdfIoTargetClose(DeviceContext->I2CIoTarget);
    }

    TRACE_FUNC_EXIT(TRACE_I2C);
}
コード例 #15
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
bool_t DEHT_enumerate(DEHT * ht, 
		      DEHT_enumerationCallback_t callback, void * param)
{
	bool_t ret = FALSE;

	int bucketIndex = 0;
	byte_t * currBlock = NULL;

	TRACE_FUNC_ENTRY();
	CHECK(NULL != ht);
	CHECK(NULL != callback);

	/* A buffer to hold a single block */
	currBlock = malloc(KEY_FILE_BLOCK_SIZE(ht));
	CHECK_MSG("malloc", (NULL != currBlock));

	for (bucketIndex = 0; bucketIndex < ht->header.numEntriesInHashTable; ++bucketIndex) {
		CHECK(DEHT_enumerateBucket(ht, bucketIndex, currBlock, callback, param));
	}

	ret = TRUE;
	goto LBL_CLEANUP;

LBL_ERROR:
	TRACE_FUNC_ERROR();
	ret = FALSE;

LBL_CLEANUP:
	FREE(currBlock);

	TRACE_FUNC_EXIT();
	return ret;
}
コード例 #16
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
static DEHT_DISK_PTR DEHT_allocKeyBlock(DEHT * ht)
{
	DEHT_DISK_PTR newBlock  = 0;

	TRACE_FUNC_ENTRY();

	CHECK(NULL != ht);

	/* this is the first block - use the end of the file */
	(void) fflush(ht->keyFP);
	CHECK(0 == fseek(ht->keyFP, 0, SEEK_END));
	newBlock = ftell(ht->keyFP);
	
	/* alloc an empty block (init to NULLs) */
	CHECK(growFile(ht->keyFP, KEY_FILE_BLOCK_SIZE(ht)));

	TRACE_FPRINTF((stderr, "TRACE: %s:%d (%s): allocated a block at %#x\n", __FILE__, __LINE__, __FUNCTION__, (uint_t) newBlock));

	goto LBL_CLEANUP;

LBL_ERROR:
	newBlock = 0;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	TRACE_FUNC_EXIT();
	return newBlock;
}
コード例 #17
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
int add_DEHT ( DEHT *ht, const unsigned char *key, int keyLength, 
				 const unsigned char *data, int dataLength)
{
	int ret = DEHT_STATUS_FAIL;

	int hashTableIndex = 0;

	byte_t * blockContent = NULL;
	DEHT_DISK_PTR keyBlockOffset = 0;
	ulong_t freeIndex = 0;

	KeyFilePair_t * targetRec = NULL;

	TRACE_FUNC_ENTRY();

	CHECK(NULL != ht);
	CHECK(NULL != key);
	CHECK(NULL != data);

	/* calc hash for key */
	CHECK(NULL != ht->hashFunc);
	hashTableIndex = ht->hashFunc(key, keyLength, ht->header.numEntriesInHashTable);
	TRACE_FPRINTF((stderr, "TRACE: %s:%d (%s): bucket index=%#x\n", __FILE__, __LINE__, __FUNCTION__, hashTableIndex));

	blockContent = malloc(KEY_FILE_BLOCK_SIZE(ht));
	CHECK_MSG("malloc", (NULL != blockContent));
	CHECK(DEHT_allocEmptyLocationInBucket(ht, hashTableIndex, blockContent, KEY_FILE_BLOCK_SIZE(ht),
					     &keyBlockOffset, &freeIndex));

	TRACE_FPRINTF((stderr, "TRACE: %s:%d (%s): using block at %#x, index=%lu\n", __FILE__, __LINE__, __FUNCTION__, (uint_t) keyBlockOffset, freeIndex));

	targetRec = GET_N_REC_PTR_IN_BLOCK(ht, blockContent, freeIndex);

	/* calc validation key and fill in record */
	/*! Note: return value isn't checked since the spec does not include details regarding the key 
		  validation function interface */
	CHECK(NULL != ht->comparisonHashFunc);
	(void) ht->comparisonHashFunc(key, keyLength, targetRec->key);

	/* write payload to data file */
	CHECK(DEHT_addData(ht, data, dataLength, &(targetRec->dataOffset)));

	/* write updated block to disk */
	CHECK_MSG(ht->sKeyfileName, (pfwrite(ht->keyFP, keyBlockOffset, blockContent, KEY_FILE_BLOCK_SIZE(ht))));

	TRACE("block updated");

	ret = DEHT_STATUS_SUCCESS;
	goto LBL_CLEANUP;	

LBL_ERROR:
	ret = DEHT_STATUS_FAIL;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	FREE(blockContent);

	TRACE_FUNC_EXIT();
	return ret;
}
コード例 #18
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
static bool_t DEHT_enumerateBucket(DEHT * ht, int bucketIndex, 
			    byte_t * blockBuffer,
			    DEHT_enumerationCallback_t callback, void * param)
{
	bool_t ret = FALSE;
	DEHT_DISK_PTR blockOffset = 0;

	TRACE_FUNC_ENTRY();
	CHECK(NULL != ht);
	CHECK(NULL != blockBuffer);
	CHECK(NULL != callback);

	CHECK(DEHT_findFirstBlockForBucket(ht, bucketIndex, &blockOffset));

	while (0 != blockOffset) {
		CHECK_MSG(ht->sKeyfileName, (pfread(ht->keyFP, blockOffset, blockBuffer, KEY_FILE_BLOCK_SIZE(ht))));
		
		CHECK(DEHT_enumerateBlock(ht, blockBuffer, bucketIndex, callback, param));
		
		blockOffset = GET_NEXT_BLOCK_PTR(ht, blockBuffer);
	}

	ret = TRUE;
	goto LBL_CLEANUP;

LBL_ERROR:
	TRACE_FUNC_ERROR();
	ret = FALSE;

LBL_CLEANUP:
	TRACE_FUNC_EXIT();
	return ret;	
}
コード例 #19
0
VOID
Ucm_EvtSetDataRoleCompleted (
    _In_ UCSI_CONTROL Command,
    _In_ PVOID Context,
    _Inout_ PPPM_COMMAND_ACK_PARAMS CommandAckParams
)
/*++

Routine Description:

    Set data role command completion routine. Notifies UCM that the power direction has changed.

Arguments:

    Command - The UCSI command that was completed. In this case, it should be only SetUor.UsbOperationRole.

    Context - Platform policy manager context object.

    CommandAckParams - UCSI command acknowledge parameters.

--*/
{
    UCM_DATA_ROLE dataRole;
    PPPM_CONTEXT ppmCtx;
    WDFDEVICE device;
    PPPM_CONNECTOR connector;
    BOOLEAN success;

    UNREFERENCED_PARAMETER(CommandAckParams);

    PAGED_CODE();

    TRACE_FUNC_ENTRY(TRACE_FLAG_UCMNOTIFICATIONS);

    ppmCtx = (PPPM_CONTEXT)Context;
    device = Context_GetWdfDevice(ppmCtx);
    connector = Ppm_GetConnector(ppmCtx, Command.SetUor.ConnectorNumber);

    NT_VERIFY(Convert((UCSI_USB_OPERATION_ROLE)Command.SetUor.UsbOperationRole, dataRole));

    success = UCSI_CMD_SUCCEEDED(ppmCtx->UcsiDataBlock->CCI);

    if (success)
    {
        TRACE_INFO(TRACE_FLAG_UCMNOTIFICATIONS, "[Device: 0x%p] Data role successfully changed to %!UCM_DATA_ROLE!", device, dataRole);
    }
    else
    {
        TRACE_ERROR(TRACE_FLAG_UCMNOTIFICATIONS, "[Device: 0x%p] Data role change to %!UCM_DATA_ROLE! failed", device, dataRole);
    }

    //
    // Notify UCM that the data direction has changed.
    //

    UcmConnectorDataDirectionChanged(connector->Handle, success, dataRole);

    TRACE_FUNC_EXIT(TRACE_FLAG_UCMNOTIFICATIONS);
}
コード例 #20
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
DEHT * create_empty_DEHT(const char *prefix,
                        hashKeyIntoTableFunctionPtr hashfun, hashKeyforEfficientComparisonFunctionPtr validfun,
                        const char *dictName,
                        int numEntriesInHashTable, int nPairsPerBlock, int nBytesPerKey,
			int nUserBytes)
{
	bool_t errorState = FALSE;

	DEHT * ht = NULL;

	TRACE_FUNC_ENTRY();

	/* sanity */
	CHECK(0 != numEntriesInHashTable);
	CHECK(0 != nPairsPerBlock);
	CHECK(0 != nBytesPerKey);

	ht = DEHT_initInstance(prefix, "c+b", hashfun, validfun);
	CHECK(NULL != ht);

	/* Do extra inits */
	ht->header.magic = DEHT_HEADER_MAGIC;
	SAFE_STRNCPY(ht->header.sDictionaryName, dictName, sizeof(ht->header.sDictionaryName));
	ht->header.numEntriesInHashTable = numEntriesInHashTable;
	ht->header.nPairsPerBlock = nPairsPerBlock;
	ht->header.nBytesPerValidationKey = nBytesPerKey;
	ht->header.numUnrelatedBytesSaved = nUserBytes;

	/* write header to disk */
	CHECK_MSG(ht->sKeyfileName, (1 == fwrite(&(ht->header), sizeof(ht->header), 1, ht->keyFP)));

	/* write (empty) pointer table to disk */
	CHECK_MSG(ht->sKeyfileName, (growFile(ht->keyFP, sizeof(DEHT_DISK_PTR) * numEntriesInHashTable)));

	/* write (empty) user data to disk */
	CHECK_MSG(ht->sKeyfileName, (growFile(ht->dataFP, ht->header.numUnrelatedBytesSaved)));



	goto LBL_CLEANUP;	

LBL_ERROR:
	errorState = TRUE;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	if (errorState) {
		if (NULL != ht) {
			DEHT_freeResources(ht, TRUE);
			ht = NULL;
		}
	}

	TRACE_FUNC_EXIT();

	return ht;
}
コード例 #21
0
VOID
Ucm_ReportPowerDirectionChanged (
    _In_ PPPM_CONTEXT PpmCtx,
    _In_ PPPM_CONNECTOR Connector,
    _Inout_ PUCSI_GET_CONNECTOR_STATUS_IN ConnStatus,
    _Inout_ PPPM_COMMAND_ACK_PARAMS CommandAckParams
)
/*++

Routine Description:

    Report to UCM that the power direction has changed. This may be called
    after a role swap completes.

Arguments:

    PpmCtx - Platform policy manager context object.

    Connector - The connector for which to report the power direction change.

    ConnStatus - The connector status for the given connector.

    CommandAckParams - UCSI command acknowledge parameters.

--*/
{
    WDFDEVICE device;
    UCM_POWER_ROLE powerRole;

    UNREFERENCED_PARAMETER(CommandAckParams);

    PAGED_CODE();

    TRACE_FUNC_ENTRY(TRACE_FLAG_UCMNOTIFICATIONS);

    device = Context_GetWdfDevice(PpmCtx);

    if (!Convert((UCSI_POWER_DIRECTION)ConnStatus->PowerDirection, powerRole))
    {
        TRACE_ERROR(TRACE_FLAG_UCMNOTIFICATIONS, "[Device: 0x%p] Invalid power direction %u", device, ConnStatus->PowerDirection);
        goto Exit;
    }

    TRACE_INFO(TRACE_FLAG_UCMNOTIFICATIONS, "[Device: 0x%p] Reporting power role change to %!UCM_POWER_ROLE! on connector ID 0x%I64x", device, powerRole, Connector->Id);

    //
    // Notify UCM that the power direction has changed.
    //

    UcmConnectorPowerDirectionChanged(Connector->Handle, TRUE, powerRole);

    ConnStatus->ConnectorStatusChange.PowerDirectionChange = 0;

Exit:

    TRACE_FUNC_EXIT(TRACE_FLAG_UCMNOTIFICATIONS);
}
コード例 #22
0
ファイル: hash_funcs.c プロジェクト: itn0x2e/TestProj21218
int DEHT_keyToValidationKeyHasher128(const unsigned char * key,int keySize, unsigned char * resBuf)
{
	TRACE_FUNC_ENTRY();

	/* ignoring errors, since miniHash is very very unlikely to fail */
	(void) miniHash(resBuf, 16, (byte_t *) VALIDATION_SEED, sizeof(VALIDATION_SEED) - 1, key, keySize);

	TRACE_FUNC_EXIT();
	return 0;
}
コード例 #23
0
VOID
Ucm_ReportTypeCDetach (
    _In_ PPPM_CONTEXT PpmCtx,
    _In_ PPPM_CONNECTOR Connector,
    _Inout_ PUCSI_GET_CONNECTOR_STATUS_IN ConnStatus,
    _Inout_ PPPM_COMMAND_ACK_PARAMS CommandAckParams
)
/*++

Routine Description:

    Report a Type-C detach event to UCM.

Arguments:

    PpmCtx - Platform policy manager context object.

    Connector - The connector for which to report the detach.

    ConnStatus - The connector status for the given connector.

    CommandAckParams - UCSI command acknowledge parameters.

--*/
{
    WDFDEVICE device;
    NTSTATUS status;

    UNREFERENCED_PARAMETER(ConnStatus);
    UNREFERENCED_PARAMETER(CommandAckParams);

    PAGED_CODE();

    TRACE_FUNC_ENTRY(TRACE_FLAG_UCMNOTIFICATIONS);

    device = Context_GetWdfDevice(PpmCtx);

    TRACE_INFO(TRACE_FLAG_UCMNOTIFICATIONS, "[Device: 0x%p] Reporting Type-C detach on connector ID 0x%I64x", device, Connector->Id);

    //
    // Notify UCM that we have detected a detach event on the connector.
    //

    status = UcmConnectorTypeCDetach(Connector->Handle);
    if (!NT_SUCCESS(status))
    {
        TRACE_ERROR(TRACE_FLAG_UCMNOTIFICATIONS, "[Device: 0x%p] UcmConnectorTypeCDetach failed - %!STATUS!", device, status);
        goto Exit;
    }

Exit:

    TRACE_FUNC_EXIT(TRACE_FLAG_UCMNOTIFICATIONS);
}
コード例 #24
0
ファイル: hash_funcs.c プロジェクト: itn0x2e/TestProj21218
int DEHT_keyToTableIndexHasher(const unsigned char * key, int keySize, int tableSize)
{
	int cksum = 0;

	TRACE_FUNC_ENTRY();

	/* ignoring errors, since miniHash is very very unlikely to fail */
	(void) miniHash((byte_t *) &cksum, sizeof(cksum), (byte_t *) TABLE_INDEX_SEED, sizeof(TABLE_INDEX_SEED) - 1, key, keySize);

	/* ignore sign bit */
	cksum = cksum & INT_MAX_POSITIVE_VALUE;

	TRACE_FUNC_EXIT();
	return (cksum % tableSize);
}
コード例 #25
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
void lock_DEHT_files(DEHT *ht)
{

	TRACE_FUNC_ENTRY();

	/* If present, serialize pointer table to disk. Errors are ignored -
	   we try to do as much as we can in spite of error in the name of robustness */
	(void) write_DEHT_pointers_table(ht);

	/* If present, serialize user data to disk. Errors are ignored -
	   we try to do as much as we can in spite of error in the name of robustness */
	(void) DEHT_writeUserBytes(ht);

	DEHT_freeResources(ht, FALSE);
}
コード例 #26
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
int calc_DEHT_last_block_per_bucket(DEHT *ht)
{
	int ret = DEHT_STATUS_FAIL;
	size_t rawTableSize = 0;
	ulong_t bucketIndex = 0;
	int pointerTableLoadRes = 0;

	TRACE_FUNC_ENTRY();

	CHECK(NULL != ht);

	if (NULL != ht->hashPointersForLastBlockImageInMemory) {
		return DEHT_STATUS_NOT_NEEDED;
	}

	/* We will be scanning the entire bucket table. It would be wise to use the 
	  first block cache for this step */
	pointerTableLoadRes = read_DEHT_pointers_table(ht);

	/* alloc cache */
	rawTableSize = ht->header.numEntriesInHashTable * sizeof(DEHT_DISK_PTR);
	ht->hashPointersForLastBlockImageInMemory = malloc(rawTableSize);
	CHECK_MSG("malloc", (NULL != ht->hashPointersForLastBlockImageInMemory));

	for (bucketIndex = 0;  bucketIndex < ht->header.numEntriesInHashTable;  ++bucketIndex) {
		CHECK(DEHT_findLastBlockForBucketDumb(ht, bucketIndex, ht->hashPointersForLastBlockImageInMemory + bucketIndex));
	}

	ret = DEHT_STATUS_SUCCESS;
	goto LBL_CLEANUP;

LBL_ERROR:
	/* free on error */
	FREE(ht->hashPointersForLastBlockImageInMemory);

	ret = DEHT_STATUS_FAIL;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	/* If the first block pointer table wasn't loaded before us, we should unload it (errors are silenced) */
	if (DEHT_STATUS_SUCCESS == pointerTableLoadRes) {
		(void) write_DEHT_pointers_table(ht);
	}

	TRACE_FUNC_EXIT();
	return ret;
}
コード例 #27
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
static bool_t DEHT_findFirstBlockForBucketAndAlloc(DEHT * ht, ulong_t bucketIndex, DEHT_DISK_PTR * blockOffset)
{
	bool_t ret = FALSE;
	
	TRACE_FUNC_ENTRY();

	CHECK(NULL != ht);
	CHECK(NULL != blockOffset);
	CHECK(bucketIndex < ht->header.numEntriesInHashTable);


	CHECK(DEHT_findFirstBlockForBucket(ht, bucketIndex, blockOffset));

	/* if this is the very first block for this bucket, alloc a new one */
	if (0 == *blockOffset) {

		*blockOffset = DEHT_allocKeyBlock(ht);
		CHECK(0 != *blockOffset);

		/* if present, update first block cache */
		if (NULL != ht->hashTableOfPointersImageInMemory) {
			/* update cache ptr */
			ht->hashTableOfPointersImageInMemory[bucketIndex] = *blockOffset;
		}
		else {
			/* update on-disk ptr */
			CHECK_MSG(ht->sKeyfileName, (pfwrite(ht->keyFP, KEY_FILE_OFFSET_TO_FIRST_BLOCK_PTRS(ht) + bucketIndex * sizeof(DEHT_DISK_PTR), (byte_t *) blockOffset, sizeof(*blockOffset))));
		}

		/* if present, update last block cache */
		if (NULL != ht->hashPointersForLastBlockImageInMemory) {
			ht->hashPointersForLastBlockImageInMemory[bucketIndex] = *blockOffset;
		}
	}

	ret = TRUE;
	goto LBL_CLEANUP;

LBL_ERROR:
	*blockOffset = 0;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	TRACE_FUNC_EXIT();
	return ret;
}
コード例 #28
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
static bool_t DEHT_enumerateBlock(DEHT * ht, 
				byte_t * blockBuffer,
				int bucketIndex,
				DEHT_enumerationCallback_t callback, void * param)
{
	bool_t ret = FALSE;

	ulong_t recordIndex = 0;
	KeyFilePair_t * currPair = NULL;
	byte_t currData[DEHT_MAX_DATA_LEN + 1];
	ulong_t bytesRead = 0;

	TRACE_FUNC_ENTRY();
	
	CHECK(NULL != ht);
	CHECK(NULL != blockBuffer);
	CHECK(NULL != callback);


	for (recordIndex = 0; recordIndex < GET_USED_RECORD_COUNT(blockBuffer); ++recordIndex) {
		currPair = GET_N_REC_PTR_IN_BLOCK(ht, blockBuffer, recordIndex);

		CHECK(DEHT_readDataAtOffset(ht, currPair->dataOffset, currData, sizeof(currData), &bytesRead));
		
		/* terminate for sure */
		currData[MIN(bytesRead, sizeof(currData) - 1)] = 0x00;

		/* call user callback */
		callback(bucketIndex, 
		     currPair->key, ht->header.nBytesPerValidationKey,
		     currData, bytesRead,
		     param);		
		
	}

	ret = TRUE;
	goto LBL_CLEANUP;

LBL_ERROR:
	TRACE_FUNC_ERROR();
	ret = FALSE;

LBL_CLEANUP:
	TRACE_FUNC_EXIT();
	return ret;	
}
コード例 #29
0
NTSTATUS
Acpi_PrepareHardware (
    _In_ PACPI_CONTEXT AcpiCtx
    )
{
    NTSTATUS status;
    WDFDEVICE device;

    PAGED_CODE();

    TRACE_FUNC_ENTRY(TRACE_FLAG_ACPI);

    device = Context_GetWdfDevice(AcpiCtx);

    if (AcpiCtx->Initialized != FALSE)
    {
        status = STATUS_INVALID_DEVICE_STATE;
        TRACE_ERROR(TRACE_FLAG_ACPI, "[Device: 0x%p] ACPI already initialized", device);
        goto Exit;
    }

    status = WdfFdoQueryForInterface(device,
                                     &GUID_ACPI_INTERFACE_STANDARD2,
                                     (PINTERFACE) &AcpiCtx->AcpiInterface,
                                     sizeof(ACPI_INTERFACE_STANDARD2),
                                     1,
                                     NULL);

    if (!NT_SUCCESS(status))
    {
        TRACE_ERROR(TRACE_FLAG_ACPI, "[Device: 0x%p] WdfFdoQueryForInterface for ACPI_INTERFACE_STANDARD2 failed - %!STATUS!", device, status);
        goto Exit;
    }

    AcpiCtx->Initialized = TRUE;

    TRACE_INFO(TRACE_FLAG_ACPI, "[Device: 0x%p] ACPI prepare hardware completed", device);

Exit:

    TRACE_FUNC_EXIT(TRACE_FLAG_ACPI);

    return status;
}
コード例 #30
0
ファイル: DEHT.c プロジェクト: itn0x2e/TestProj21218
int DEHT_getUserBytes(DEHT * ht, byte_t * * bufPtr, ulong_t * bufSize)
{
	int ret = DEHT_STATUS_FAIL;

	TRACE_FUNC_ENTRY();
	CHECK(NULL != ht);
	CHECK(NULL != bufPtr);
	CHECK(NULL != bufSize);

	if (NULL != ht->userBuf) {
		*bufPtr = ht->userBuf;
		*bufSize = ht->header.numUnrelatedBytesSaved;
	
		ret = DEHT_STATUS_NOT_NEEDED;
		goto LBL_CLEANUP;
	}

	ht->userBuf = malloc(ht->header.numUnrelatedBytesSaved);
	CHECK_MSG("malloc", (NULL != ht->userBuf));

	CHECK_MSG(ht->sDatafileName, (pfread(ht->dataFP, DATA_FILE_OFFSET_TO_USER_BYTES, ht->userBuf, ht->header.numUnrelatedBytesSaved)));

	*bufSize = ht->header.numUnrelatedBytesSaved;
	*bufPtr = ht->userBuf;

	ret = DEHT_STATUS_SUCCESS;
	goto LBL_CLEANUP;

LBL_ERROR:
	ret = DEHT_STATUS_FAIL;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	if (DEHT_STATUS_FAIL == ret) {
		FREE(ht->userBuf);
	}

	TRACE_FUNC_EXIT();
	return ret;
}