pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


Dr Memory upcall buffers experiment
Posted by Anonymous on Thu 16th May 2024 13:58
raw | new post

  1. diff --git a/cygwin/devel/msnfs41client.bash b/cygwin/devel/msnfs41client.bash
  2. index cf4c516..2a74a44 100644
  3. --- a/cygwin/devel/msnfs41client.bash
  4. +++ b/cygwin/devel/msnfs41client.bash
  5. @@ -212,7 +212,7 @@ function nfsclient_rundeamon
  6.                         "${nfsd_args[@]:1}"
  7.                 )
  8.                 "${nfsd_args[@]}"
  9. -       elif false ; then
  10. +       elif true ; then
  11.                 #
  12.                 # test nfsd_debug.exe with Dr. Memory (version 2.6.0 -- build 0)
  13.                 #
  14. @@ -323,7 +323,7 @@ function nfsclient_system_rundeamon
  15.                 )
  16.  
  17.                 "${nfsd_args[@]}"
  18. -       elif false ; then
  19. +       elif true ; then
  20.                 #
  21.                 # test nfsd_debug.exe with Dr. Memory (version 2.6.0 -- build 0)
  22.                 #
  23. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  24. index 56a960e..b617334 100644
  25. --- a/daemon/nfs41_daemon.c
  26. +++ b/daemon/nfs41_daemon.c
  27. @@ -134,7 +134,8 @@ static unsigned int nfsd_worker_thread_main(void *args)
  28.      // if we ever need to handle non-cached IO, need to make it dynamic
  29.      unsigned char outbuf[UPCALL_BUF_SIZE], inbuf[UPCALL_BUF_SIZE];
  30.      DWORD inbuf_len = UPCALL_BUF_SIZE, outbuf_len;
  31. -    nfs41_upcall upcall;
  32. +    nfs41_upcall upcall_buf;
  33. +    nfs41_upcall *upcall;
  34.  
  35.      pipe = CreateFileA(NFS41_USER_DEVICE_NAME_A, GENERIC_READ | GENERIC_WRITE,
  36.          FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
  37. @@ -146,6 +147,13 @@ static unsigned int nfsd_worker_thread_main(void *args)
  38.      }
  39.  
  40.      while(1) {
  41. +#define DRMEMORY_INSTRUMENTATION 1
  42. +#ifdef DRMEMORY_INSTRUMENTATION
  43. +        upcall = malloc(sizeof(nfs41_upcall));
  44. +#else
  45. +        upcall = &upcall_buf;
  46. +#endif /* DRMEMORY_INSTRUMENTATION */
  47. +
  48.          status = DeviceIoControl(pipe, IOCTL_NFS41_READ, NULL, 0,
  49.              outbuf, UPCALL_BUF_SIZE, (LPDWORD)&outbuf_len, NULL);
  50.          if (!status) {
  51. @@ -153,16 +161,22 @@ static unsigned int nfsd_worker_thread_main(void *args)
  52.              continue;
  53.          }
  54.  
  55. -        status = upcall_parse(outbuf, (uint32_t)outbuf_len, &upcall);
  56. +#ifdef DRMEMORY_INSTRUMENTATION
  57. +        unsigned char *outbuf_malloced = malloc(outbuf_len);
  58. +        (void)memcpy(outbuf_malloced, outbuf, outbuf_len);
  59. +        status = upcall_parse(outbuf_malloced, (uint32_t)outbuf_len, upcall);
  60. +#else
  61. +        status = upcall_parse(outbuf, (uint32_t)outbuf_len, upcall);
  62. +#endif /* DRMEMORY_INSTRUMENTATION */
  63.          if (status) {
  64. -            upcall.status = status;
  65. +            upcall->status = status;
  66.              goto write_downcall;
  67.          }
  68.  
  69.          if (!OpenThreadToken(GetCurrentThread(),
  70.              TOKEN_QUERY/*|TOKEN_IMPERSONATE*/, FALSE,
  71. -            &upcall.currentthread_token)) {
  72. -            upcall.currentthread_token = INVALID_HANDLE_VALUE;
  73. +            &upcall->currentthread_token)) {
  74. +            upcall->currentthread_token = INVALID_HANDLE_VALUE;
  75.              DPRINTF(0, ("nfsd_worker_thread_main: "
  76.                  "OpenThreadToken() failed, lasterr=%d.\n",
  77.                  (int)GetLastError()));
  78. @@ -173,45 +187,55 @@ static unsigned int nfsd_worker_thread_main(void *args)
  79.           * Each thread can handle a different user
  80.           */
  81.          status = map_current_user_to_ids(nfs41dg->idmapper,
  82. -            upcall.currentthread_token,
  83. -            &upcall.uid, &upcall.gid);
  84. +            upcall->currentthread_token,
  85. +            &upcall->uid, &upcall->gid);
  86.          if (status) {
  87. -            upcall.status = status;
  88. +            upcall->status = status;
  89.              goto write_downcall;
  90.          }
  91.  
  92. -        if (upcall.opcode == NFS41_SHUTDOWN) {
  93. +        if (upcall->opcode == NFS41_SHUTDOWN) {
  94.              printf("Shutting down...\n");
  95.              exit(0);
  96.          }
  97.  
  98. -        status = upcall_handle(&nfs41_dg, &upcall);
  99. +        status = upcall_handle(&nfs41_dg, upcall);
  100.  
  101.  write_downcall:
  102.          DPRINTF(1, ("writing downcall: xid=%lld opcode='%s' status=%d "
  103. -            "get_last_error=%d\n", upcall.xid, opcode2string(upcall.opcode),
  104. -            upcall.status, upcall.last_error));
  105. +            "get_last_error=%d\n", upcall->xid,
  106. +            opcode2string(upcall->opcode), upcall->status,
  107. +            upcall->last_error));
  108.  
  109. -        upcall_marshall(&upcall, inbuf, (uint32_t)inbuf_len, (uint32_t*)&outbuf_len);
  110. +        upcall_marshall(upcall, inbuf, (uint32_t)inbuf_len, (uint32_t*)&outbuf_len);
  111.  
  112.          /*
  113.           * Note: Caller impersonation ends with |IOCTL_NFS41_WRITE| -
  114.           * nfs41_driver.sys |IOCTL_NFS41_WRITE| calls
  115.           * |SeStopImpersonatingClient()|
  116.           */
  117. -        (void)CloseHandle(upcall.currentthread_token);
  118. -        upcall.currentthread_token = INVALID_HANDLE_VALUE;
  119. +        (void)CloseHandle(upcall->currentthread_token);
  120. +        upcall->currentthread_token = INVALID_HANDLE_VALUE;
  121.  
  122.          DPRINTF(2, ("making a downcall: outbuf_len %ld\n\n", outbuf_len));
  123.          status = DeviceIoControl(pipe, IOCTL_NFS41_WRITE,
  124.              inbuf, inbuf_len, NULL, 0, (LPDWORD)&outbuf_len, NULL);
  125.          if (!status) {
  126. -            eprintf("IOCTL_NFS41_WRITE failed with %d xid=%lld opcode='%s'\n",
  127. -                GetLastError(), upcall.xid, opcode2string(upcall.opcode));
  128. -            upcall_cancel(&upcall);
  129. -        }
  130. -        if (upcall.status != NFSD_VERSION_MISMATCH)
  131. -            upcall_cleanup(&upcall);
  132. +            eprintf("IOCTL_NFS41_WRITE failed "
  133. +                "with %d xid=%lld opcode='%s'\n",
  134. +                GetLastError(), upcall->xid,
  135. +                opcode2string(upcall->opcode));
  136. +            upcall_cancel(upcall);
  137. +        }
  138. +        if (upcall->status != NFSD_VERSION_MISMATCH)
  139. +            upcall_cleanup(upcall);
  140. +        
  141. +#ifdef DRMEMORY_INSTRUMENTATION
  142. +        free(outbuf_malloced);
  143. +        outbuf_malloced = NULL;
  144. +        free(upcall);
  145. +        upcall = NULL;
  146. +#endif /* DRMEMORY_INSTRUMENTATION */
  147.      }
  148.      CloseHandle(pipe);
  149.  
  150. diff --git a/daemon/setattr.c b/daemon/setattr.c
  151. index 5540d87..03e9ff1 100644
  152. --- a/daemon/setattr.c
  153. +++ b/daemon/setattr.c
  154. @@ -353,6 +353,13 @@ static int handle_nfs41_set_size(void *daemon_context, setattr_upcall_args *args
  155.      nfs41_open_state *state = args->state;
  156.      int status;
  157.  
  158. +    EASSERT_MSG(args->buf_len == sizeof(size->QuadPart),
  159. +        ("args->buf_len=%ld\n", (long)args->buf_len));
  160. +
  161. +    DPRINTF(0,
  162. +        ("handle_nfs41_set_size: args->set_class=%d, new_file=%lld\n",
  163. +            (int)args->set_class, (long long)size->QuadPart));
  164. +
  165.      /* break read delegations before SETATTR */
  166.      nfs41_delegation_return(state->session, &state->file,
  167.          OPEN_DELEGATE_READ, FALSE);
  168. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  169. index f35793d..3400cf0 100644
  170. --- a/sys/nfs41_driver.c
  171. +++ b/sys/nfs41_driver.c
  172. @@ -5896,6 +5896,7 @@ NTSTATUS nfs41_SetFileInformation(
  173.              status = STATUS_SUCCESS;
  174.              goto out;
  175.          }
  176. +//    case FileAllocationInformation:
  177.      case FileEndOfFileInformation:
  178.          {
  179.              PFILE_END_OF_FILE_INFORMATION info =

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