pastebin - collaborative debugging tool
rovema.kpaste.net RSS


[patch] msnfs41client_catdbgprintsubcmd_misc_20251209_001.tar.bz2
Posted by Anonymous on Wed 17th Dec 2025 10:25
raw | new post

  1. From 9bdb92f21e989243c67a4bf92cc023ae69c1da1b Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Tue, 9 Dec 2025 20:45:42 +0100
  4. Subject: [PATCH 1/2] cygwin,tests: Add subcmds to catdbgprint.exe to start,
  5.  print and stop tracing
  6.  
  7. Add subcmds to catdbgprint.exe to start, print and stop tracing.
  8.  
  9. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  10. ---
  11. cygwin/devel/msnfs41client.bash |   7 +-
  12.  tests/catdbgprint/catdbgprint.c | 193 +++++++++++++++++++++++---------
  13.  2 files changed, 145 insertions(+), 55 deletions(-)
  14.  
  15. diff --git a/cygwin/devel/msnfs41client.bash b/cygwin/devel/msnfs41client.bash
  16. index 4b769c7..c963e45 100755
  17. --- a/cygwin/devel/msnfs41client.bash
  18. +++ b/cygwin/devel/msnfs41client.bash
  19. @@ -942,9 +942,12 @@ function watch_kernel_debuglog
  20.  {
  21.         printf "# logging start...\n" 1>&2
  22.  
  23. -       catdbgprint
  24. +       trap 'catdbgprint stoptrace ; trap "" INT TERM EXIT ; printf "# logging done\n" 1>&2' INT TERM EXIT
  25. +
  26. +       catdbgprint starttrace
  27. +       catdbgprint processtrace
  28. +       # catdbgprint stoptrace
  29.  
  30. -       printf '# logging done\n' 1>&2
  31.         return 0
  32.  }
  33.  
  34. diff --git a/tests/catdbgprint/catdbgprint.c b/tests/catdbgprint/catdbgprint.c
  35. index 7f053e1..62c975d 100644
  36. --- a/tests/catdbgprint/catdbgprint.c
  37. +++ b/tests/catdbgprint/catdbgprint.c
  38. @@ -39,9 +39,14 @@
  39.  #include <evntcons.h>
  40.  #include <stdio.h>
  41.  #include <stdlib.h>
  42. +#include <string.h>
  43.  #include <stddef.h>
  44.  #include <ctype.h>
  45.  
  46. +#define KERNEL_LOGGER_NAME_A "NT Kernel Logger"
  47. +
  48. +#define EXIT_USAGE (2) /* Traditional UNIX exit code for usage */
  49. +
  50.  typedef struct _DBGPRINT_EVENT {
  51.      ULONG ComponentId;   /* DPFLTR_xxx_ID */
  52.      ULONG Level;         /* DPFLTR_LEVEL_xxx */
  53. @@ -62,13 +67,13 @@ void int_to_octal3(int value, unsigned char *restrict out)
  54.  }
  55.  
  56.  static
  57. -VOID WINAPI EventCallback(PEVENT_RECORD ev)
  58. +VOID WINAPI trace_eventcallback(PEVENT_RECORD ev)
  59.  {
  60.      unsigned char buffer[2048];
  61.      unsigned char *b = buffer;
  62.  
  63.      if (ev->UserDataLength >= offsetof(DBGPRINT_EVENT, Message)) {
  64. -        size_t i;
  65. +        ssize_t i;
  66.          unsigned char c;
  67.          const DBGPRINT_EVENT *dpe = (const DBGPRINT_EVENT *)ev->UserData;
  68.          const unsigned char *msg = (const unsigned char *)dpe->Message;
  69. @@ -136,70 +141,152 @@ VOID WINAPI EventCallback(PEVENT_RECORD ev)
  70.      }
  71.  }
  72.  
  73. -int main(int ac, char *av[])
  74. -{
  75. -    TRACEHANDLE hSession = 0;
  76. -    TRACEHANDLE hTrace = 0;
  77. -    ULONG status;
  78. -    int retval = EXIT_SUCCESS;
  79.  
  80. -    (void)ac;
  81. +static
  82. +int do_starttrace(const char *progname)
  83. +{
  84. +    ULONG status = 0;
  85.  
  86.      size_t propsSize = sizeof(EVENT_TRACE_PROPERTIES) + 1024;
  87.      EVENT_TRACE_PROPERTIES *props = (EVENT_TRACE_PROPERTIES*)calloc(1, propsSize);
  88. -    if (props == NULL) {
  89. -        (void)fprintf(stderr, "%s: Malloc failed\n", av[0]);
  90. -        retval = EXIT_FAILURE;
  91. -        goto done;
  92. +    if (!props) {
  93. +        (void)fprintf(stderr, "%s:[!] malloc() EVENT_TRACE_PROPERTIES failed\n",
  94. +            progname);
  95. +        return EXIT_FAILURE;
  96.      }
  97.  
  98. -    props->Wnode.BufferSize = (ULONG)propsSize;
  99. -    props->Wnode.Flags = WNODE_FLAG_TRACED_GUID;
  100. -    props->LogFileMode = EVENT_TRACE_REAL_TIME_MODE;
  101. -    props->EnableFlags = EVENT_TRACE_FLAG_DBGPRINT;
  102. -    props->LoggerNameOffset = sizeof(EVENT_TRACE_PROPERTIES);
  103. -#if 1
  104. -    /* Increase buffer size to 32MB */
  105. -    props->BufferSize = 64;             /* Buffer size in KB (64KB per buffer) */
  106. -    props->MinimumBuffers = 512;        /* Minimum buffers */
  107. -    props->MaximumBuffers = 512;        /* Maximum buffers */
  108. -#endif
  109. -
  110. -    status = StartTraceW(&hSession, KERNEL_LOGGER_NAME, props);
  111. +    *props = (EVENT_TRACE_PROPERTIES){
  112. +        .Wnode = (WNODE_HEADER){
  113. +            .BufferSize = (ULONG)propsSize,
  114. +            .Flags      = WNODE_FLAG_TRACED_GUID
  115. +        },
  116. +        .LogFileMode    = EVENT_TRACE_REAL_TIME_MODE,
  117. +        .EnableFlags    = EVENT_TRACE_FLAG_DBGPRINT,
  118. +        .BufferSize     = 64,   /* KB per buffer */
  119. +        .MinimumBuffers = 512,  /* 64KB * 512 = 32MB */
  120. +        .MaximumBuffers = 512
  121. +    };
  122. +
  123. +    TRACEHANDLE hSession = 0;
  124. +    status = StartTraceA(&hSession, KERNEL_LOGGER_NAME_A, props);
  125.      if (status == ERROR_ALREADY_EXISTS) {
  126. -        (void)fprintf(stderr,
  127. -            "#### Kernel Logger already running, attaching...\n");
  128. -        hSession = 0;
  129. -    } else if (status != ERROR_SUCCESS) {
  130. -        (void)fprintf(stderr, "%s: StartTraceA() failed with error=%d\n",
  131. -            av[0], (int)status);
  132. -        retval = EXIT_FAILURE;
  133. -        goto done;
  134. -    } else {
  135. -        (void)fprintf(stderr,
  136. -            "#### Started Kernel Logger session.\n");
  137. +        (void)fprintf(stderr, "#### Kernel Logger already running\n");
  138. +        free(props);
  139. +        return EXIT_SUCCESS;
  140. +    }
  141. +    else if (status != ERROR_SUCCESS) {
  142. +        (void)fprintf(stderr, "%s: StartTraceA() failed, lasterr=%d\n",
  143. +            progname,
  144. +            (int)status);
  145. +        free(props);
  146. +        return EXIT_FAILURE;
  147. +    }
  148. +
  149. +    (void)fprintf(stderr, "#### Started Kernel Logger\n");
  150. +    free(props);
  151. +
  152. +    return EXIT_SUCCESS;
  153. +}
  154. +
  155. +static TRACEHANDLE g_hTrace = 0;
  156. +
  157. +static
  158. +BOOL WINAPI processtrace_ctrlhandler(DWORD type)
  159. +{
  160. +    if ((type == CTRL_C_EVENT) ||
  161. +        (type == CTRL_BREAK_EVENT) ||
  162. +        (type == CTRL_CLOSE_EVENT)) {
  163. +
  164. +        (void)fprintf(stderr, "#### <CTRL-C>\n");
  165. +        if (g_hTrace) {
  166. +            (void)CloseTrace(g_hTrace);
  167. +            g_hTrace = 0;
  168. +        }
  169. +
  170. +        exit(EXIT_SUCCESS);
  171. +    }
  172. +
  173. +    return FALSE;
  174. +}
  175. +
  176. +static
  177. +int do_processtrace(const char *progname)
  178. +{
  179. +    ULONG status;
  180. +    EVENT_TRACE_LOGFILEA log = {
  181. +        .LoggerName        = (LPSTR)KERNEL_LOGGER_NAME_A,
  182. +        .ProcessTraceMode  = PROCESS_TRACE_MODE_REAL_TIME | PROCESS_TRACE_MODE_EVENT_RECORD,
  183. +        .EventRecordCallback = trace_eventcallback
  184. +    };
  185. +
  186. +    g_hTrace = OpenTraceA(&log);
  187. +    if (g_hTrace == INVALID_PROCESSTRACE_HANDLE) {
  188. +        (void)fprintf(stderr, "%s: OpenTraceA() failed, lasterr=%d\n",
  189. +            progname, (int)GetLastError());
  190. +        return EXIT_FAILURE;
  191.      }
  192.  
  193. -    EVENT_TRACE_LOGFILE log = {
  194. -        .LoggerName = KERNEL_LOGGER_NAME,
  195. -        .ProcessTraceMode =
  196. -            PROCESS_TRACE_MODE_REAL_TIME |
  197. -            PROCESS_TRACE_MODE_EVENT_RECORD,
  198. -        .EventRecordCallback = EventCallback
  199. +    (void)SetConsoleCtrlHandler(processtrace_ctrlhandler, TRUE);
  200. +
  201. +    status = ProcessTrace(&g_hTrace, 1, NULL, NULL);
  202. +    (void)fprintf(stderr, "#### ProcessTrace() returned, lasterr=%d\n",
  203. +        (int)status);
  204. +
  205. +    (void)CloseTrace(g_hTrace);
  206. +    g_hTrace = 0;
  207. +
  208. +    /* Treat non-zero status as failure */
  209. +    return (status == ERROR_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE;
  210. +}
  211. +
  212. +static
  213. +int do_stoptrace(const char *progname)
  214. +{
  215. +    EVENT_TRACE_PROPERTIES props = {
  216. +        .Wnode = (WNODE_HEADER){ .BufferSize = sizeof(EVENT_TRACE_PROPERTIES) }
  217.      };
  218. +    ULONG status = StopTraceA(0, KERNEL_LOGGER_NAME_A, &props);
  219.  
  220. -    hTrace = OpenTrace(&log);
  221. -    if (hTrace == INVALID_PROCESSTRACE_HANDLE) {
  222. -        (void)fprintf(stderr, "%s: OpenTrace() failed with error=%d\n",
  223. -            av[0], (int)GetLastError());
  224. -        retval = EXIT_FAILURE;
  225. -        goto done;
  226. +    if ((status != ERROR_SUCCESS) && (status != ERROR_MORE_DATA)) {
  227. +        (void)fprintf(stderr, "%s: StopTraceA() failed, lasterr=%d\n",
  228. +            progname, (int)status);
  229. +        return EXIT_FAILURE;
  230.      }
  231.  
  232. +    (void)fprintf(stderr, "#### Stopped Kernel Logger.\n");
  233. +
  234. +    return EXIT_SUCCESS;
  235. +}
  236. +
  237. +static
  238. +void usage(const char *progname)
  239. +{
  240.      (void)fprintf(stderr,
  241. -        "#### Listening for |DbgPrint*()| messages...\n");
  242. -    status = ProcessTrace(&hTrace, 1, NULL, NULL);
  243. +        "Usage:\n"
  244. +        "\t%s starttrace   - start NT Kernel Logger with DbgPrint capture\n"
  245. +        "\t%s processtrace - open and process DbgPrint events\n"
  246. +        "\t%s stoptrace    - stop NT Kernel Logger session\n",
  247. +        progname, progname, progname);
  248. +}
  249. +
  250. +int main(int argc, char *av[])
  251. +{
  252. +    if (argc < 2) {
  253. +        usage(av[0]);
  254. +        return EXIT_USAGE;
  255. +    }
  256.  
  257. -done:
  258. -    return retval;
  259. +    /*
  260. +     * Subcmd dispatcher
  261. +     */
  262. +    if (strcmp(av[1], "starttrace") == 0) {
  263. +        return do_starttrace(av[0]);
  264. +    } else if (strcmp(av[1], "processtrace") == 0) {
  265. +        return do_processtrace(av[0]);
  266. +    } else if (strcmp(av[1], "stoptrace") == 0) {
  267. +        return do_stoptrace(av[0]);
  268. +    } else {
  269. +        (void)fprintf(stderr, "%s: Unknown option '%s\n", av[0], av[1]);
  270. +        return EXIT_FAILURE;
  271. +    }
  272.  }
  273. --
  274. 2.51.0
  275.  
  276. From 86eeea6942359b44dc237fe9625a5b0e97e2e315 Mon Sep 17 00:00:00 2001
  277. From: Roland Mainz <roland.mainz@nrubsig.org>
  278. Date: Tue, 9 Dec 2025 20:56:45 +0100
  279. Subject: [PATCH 2/2] sys: |nfs41_Create()|/|nfs41_CollapseOpen()|: Clarify
  280.  that "RequestedClasses" debug output belongs to |QUERY_ON_CREATE_ECP_CONTEXT|
  281.  
  282. |nfs41_Create()|/|nfs41_CollapseOpen()|: Clarify that "RequestedClasses"
  283. debug output belongs to |QUERY_ON_CREATE_ECP_CONTEXT|.
  284.  
  285. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  286. ---
  287. sys/nfs41sys_openclose.c | 5 +++--
  288.  1 file changed, 3 insertions(+), 2 deletions(-)
  289.  
  290. diff --git a/sys/nfs41sys_openclose.c b/sys/nfs41sys_openclose.c
  291. index 885ec5e..27ea22f 100644
  292. --- a/sys/nfs41sys_openclose.c
  293. +++ b/sys/nfs41sys_openclose.c
  294. @@ -755,7 +755,8 @@ NTSTATUS nfs41_Create(
  295.      PQUERY_ON_CREATE_ECP_CONTEXT qocec =
  296.          get_queryoncreateecpcontext(RxContext->CurrentIrp);
  297.      if (qocec) {
  298. -        DbgP("nfs41_Create: RequestedClasses=0x%lx\n", qocec->RequestedClasses);
  299. +        DbgP("nfs41_Create: QUERY_ON_CREATE_ECP_CONTEXT.RequestedClasses=0x%lx\n",
  300. +            qocec->RequestedClasses);
  301.      }
  302.  
  303.  #ifdef NFS41_DRIVER_ALLOW_CREATEFILE_ACLS
  304. @@ -1445,7 +1446,7 @@ NTSTATUS nfs41_CollapseOpen(
  305.      PQUERY_ON_CREATE_ECP_CONTEXT qocec =
  306.          get_queryoncreateecpcontext(RxContext->CurrentIrp);
  307.      if (qocec) {
  308. -        DbgP("nfs41_CollapseOpen: RequestedClasses=0x%lx\n",
  309. +        DbgP("nfs41_CollapseOpen: QUERY_ON_CREATE_ECP_CONTEXT.RequestedClasses=0x%lx\n",
  310.              qocec->RequestedClasses);
  311.      }
  312.  
  313. --
  314. 2.51.0

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at