<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Aug 12, 2022 at 5:02 PM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com">maurizio.cimadamore@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

  
  <div>
    <p><br>
    </p>
    <div>On 12/08/2022 15:55, Pedro Lamarão
      wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">
        <div dir="ltr">Em sex., 12 de ago. de 2022 às 11:50, Maurizio
          Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com" target="_blank">maurizio.cimadamore@oracle.com</a>>
          escreveu:<br>
        </div>
        <div class="gmail_quote">
          <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
            <div>
              <p><br>
              </p>
              <div>On 12/08/2022 15:43, Pedro Lamarão wrote:<br>
              </div>
              <blockquote type="cite">
                <div dir="ltr">
                  <div dir="ltr"><br>
                  </div>
                  <div class="gmail_quote">
                    <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
                      <div dir="ltr">
                        <div>
                          <div>
                            <div>This is incorrect. WriteFile()
                              indicates an error, but GetLastError()
                              returns 0 (= NO_ERROR). Could it be that
                              the debugger calls another Windows API
                              function between those two functions,
                              resetting the last error?</div>
                            <div><br>
                            </div>
                            <div>In my project that's a major issue.
                              Since the software behaves incorrectly
                              with the debugger, the software can no
                              longer be debugged. This doesn't just
                              affect it when debugging this particular
                              piece of code but anytime this code is run
                              in a debugging session.</div>
                          </div>
                        </div>
                      </div>
                    </blockquote>
                    <div><br>
                    </div>
                    <div><br>
                    </div>
                    <div>This would be a blocker for all applications of
                      Windows API functions via panama.</div>
                    <div>Windows Sockets has a similar mechanism called
                      WSAGetLastError.</div>
                  </div>
                </div>
              </blockquote>
              <p>And JNI - I doubt there's anything Panama specific here
                (unless proven otherwise).</p>
            </div>
          </blockquote>
          <div><br>
          </div>
          <div>Of course, this would disturb any interaction with
            Windows API, however it was activated.</div>
          <div>For some reason, such a debugger has been working with
            software for some time, and I presume it works with software
            that calls the system via JNI.</div>
          <div>Is there perhaps some kind of special "locking" when
            calling into JNI which the debugger might have learned to
            respect?</div>
        </div>
      </div>
    </blockquote>
    <p>I think what we need at this point is some more testing.</p>
    <p>E.g. can we reproduce the same issue with JNI? E.g. assume we
      have a JNI binding for Windows API we want to call and a
      _different_ JNI binding for checking LastError. Does that show the
      same problem?</p></div></blockquote><div>Stupid question, since those calls are embedded into java code, can this really be prevented? E.g. thread allocates object -> causes heap to expand -> needs commit -> calls VirtualAlloc?</div><div><br></div><div>I would have thought that you need to treat GetLastError special. JNA seems to do this: <a href="https://github.com/java-native-access/jna/blob/999c60a1fa0ab1154b07edffa3748ce46d8d3b89/src/com/sun/jna/NativeLibrary.java#L130">https://github.com/java-native-access/jna/blob/999c60a1fa0ab1154b07edffa3748ce46d8d3b89/src/com/sun/jna/NativeLibrary.java#L130</a></div><div> <br></div><div>Cheers, Thomas</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div dir="ltr">
          </div>
        </div>
      </div>
    </blockquote>
  </div>

</blockquote></div></div>