Sample Code

Windows Driver Samples/ ObCallback Callback Registration Driver/ C++/ driver/ util.c/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*++
 
Module Name:
 
    util.c
 
Notice:
    Use this sample code at your own risk; there is no support from Microsoft for the sample code.
    In addition, this sample code is licensed to you under the terms of the Microsoft Public License
 
 
--*/
 
#include "pch.h"
#include "tdriver.h"
 
//
// TdSetCallContext
//
// Creates a call context object and stores a pointer to it
// in the supplied OB_PRE_OPERATION_INFORMATION structure.
//
// This function is called from a pre-notification. The created call context
// object then has to be freed in a corresponding post-notification using
// TdCheckAndFreeCallContext.
//
 
void TdSetCallContext (
    _Inout_ POB_PRE_OPERATION_INFORMATION PreInfo,
    _In_ PTD_CALLBACK_REGISTRATION CallbackRegistration
)
{
    PTD_CALL_CONTEXT CallContext;
 
    CallContext = (PTD_CALL_CONTEXT) ExAllocatePoolWithTag (
        PagedPool, sizeof(TD_CALL_CONTEXT), TD_CALL_CONTEXT_TAG
    );
 
    if (CallContext == NULL)
    {
        return;
    }
 
    RtlZeroMemory (CallContext, sizeof(TD_CALL_CONTEXT));
 
    CallContext->CallbackRegistration = CallbackRegistration;
    CallContext->Operation  = PreInfo->Operation;
    CallContext->Object     = PreInfo->Object;
    CallContext->ObjectType = PreInfo->ObjectType;
 
    PreInfo->CallContext = CallContext;
}
 
void TdCheckAndFreeCallContext (
    _Inout_ POB_POST_OPERATION_INFORMATION PostInfo,
    _In_ PTD_CALLBACK_REGISTRATION CallbackRegistration
)
{
    PTD_CALL_CONTEXT CallContext = (PTD_CALL_CONTEXT)PostInfo->CallContext;
 
    if (CallContext != NULL)
    {
        TD_ASSERT (CallContext->CallbackRegistration == CallbackRegistration);
 
        TD_ASSERT (CallContext->Operation  == PostInfo->Operation);
        TD_ASSERT (CallContext->Object     == PostInfo->Object);
        TD_ASSERT (CallContext->ObjectType == PostInfo->ObjectType);
 
        ExFreePoolWithTag (CallContext, TD_CALL_CONTEXT_TAG);
    }
}

Our Services

  • What our customers say about us?

© 2011-2025 All Rights Reserved. Joya Systems. 4425 South Mopac Building II Suite 101 Austin, TX 78735 Tel: 800-DEV-KERNEL

Privacy Policy. Terms of use. Valid XHTML & CSS