1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** FileX Component                                                       */
16 /**                                                                       */
17 /**   Trace                                                               */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #ifndef FX_SOURCE_CODE
23 #define FX_SOURCE_CODE
24 #endif
25 
26 #include "fx_api.h"
27 
28 #ifdef TX_ENABLE_EVENT_TRACE
29 
30 
31 /* Include necessary system files.  */
32 
33 #include "tx_trace.h"
34 
35 
36 
37 /**************************************************************************/
38 /*                                                                        */
39 /*  FUNCTION                                               RELEASE        */
40 /*                                                                        */
41 /*    _fx_trace_event_insert                              PORTABLE C      */
42 /*                                                           6.1          */
43 /*  AUTHOR                                                                */
44 /*                                                                        */
45 /*    William E. Lamie, Microsoft Corporation                             */
46 /*                                                                        */
47 /*  DESCRIPTION                                                           */
48 /*                                                                        */
49 /*    This function inserts a FileX event into the current trace buffer.  */
50 /*                                                                        */
51 /*  INPUT                                                                 */
52 /*                                                                        */
53 /*    event_id                              User Event ID                 */
54 /*    info_field_1                          First information field       */
55 /*    info_field_2                          First information field       */
56 /*    info_field_3                          First information field       */
57 /*    info_field_4                          First information field       */
58 /*    current_event                         Current event pointer for     */
59 /*                                            post event update           */
60 /*    current_timestamp                     Timestamp for post event      */
61 /*                                            update                      */
62 /*                                                                        */
63 /*  OUTPUT                                                                */
64 /*                                                                        */
65 /*    None                                                                */
66 /*                                                                        */
67 /*  CALLS                                                                 */
68 /*                                                                        */
69 /*    None                                                                */
70 /*                                                                        */
71 /*  CALLED BY                                                             */
72 /*                                                                        */
73 /*    Internal FileX Functions                                            */
74 /*                                                                        */
75 /*  RELEASE HISTORY                                                       */
76 /*                                                                        */
77 /*    DATE              NAME                      DESCRIPTION             */
78 /*                                                                        */
79 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
80 /*  09-30-2020     William E. Lamie         Modified comment(s),          */
81 /*                                            resulting in version 6.1    */
82 /*                                                                        */
83 /**************************************************************************/
_fx_trace_event_insert(ULONG event_id,ULONG info_field_1,ULONG info_field_2,ULONG info_field_3,ULONG info_field_4,ULONG filter,TX_TRACE_BUFFER_ENTRY ** current_event,ULONG * current_timestamp)84 VOID  _fx_trace_event_insert(ULONG event_id, ULONG info_field_1, ULONG info_field_2, ULONG info_field_3, ULONG info_field_4, ULONG filter, TX_TRACE_BUFFER_ENTRY **current_event, ULONG *current_timestamp)
85 {
86 
87 TX_INTERRUPT_SAVE_AREA
88 
89 TX_TRACE_BUFFER_ENTRY *event;
90 ULONG                  timestamp;
91 
92 
93     /* Disable interrupts.  */
94     TX_DISABLE
95 
96     /* Pickup the current event.  */
97     event =  _tx_trace_buffer_current_ptr;
98 
99     /* Insert this event into the trace buffer.  */
100     TX_TRACE_IN_LINE_INSERT(event_id, info_field_1, info_field_2, info_field_3, info_field_4, filter);
101 
102     /* Initialize the timestamp to 0.  */
103     timestamp =  0;
104 
105     /* Determine if the event was inserted.  */
106     if (event)
107     {
108 
109         /* Was the event inserted?  */
110         if (event -> tx_trace_buffer_entry_event_id == event_id)
111         {
112 
113             /* Yes, the event was inserted in the event trace so pickup the timestamp.  */
114             timestamp =  event -> tx_trace_buffer_entry_time_stamp;
115         }
116         else
117         {
118 
119             /* Event was not inserted, simply set the event pointer to NULL.  */
120             event =  FX_NULL;
121         }
122     }
123 
124     /* Now determine if the caller requested the current event.  */
125     if (current_event)
126     {
127 
128         /* Yes, return the event pointer of potential subsequent update.  */
129         *current_event =  event;
130     }
131 
132     /* Now determine if the current timestamp was requested.  */
133     if (current_timestamp)
134     {
135 
136         /* Yes, return the current timestamp.  */
137         *current_timestamp =  timestamp;
138     }
139 
140     /* Restore interrupts.  */
141     TX_RESTORE
142 }
143 
144 #endif /* TX_ENABLE_EVENT_TRACE */
145 
146