<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 12/08/2022 16:13, Thomas Stüfe
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CAA-vtUxzg_pcFYQg8vYV2GxTqm6+9PtQhotKQWaS_RM+W6U9tw@mail.gmail.com">
      <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>
    </blockquote>
    VirtualAlloc (and other os specific routines) are using the
    PreserveLastError mechanism. I doubt the VM is causing this (in fact
    this works reliably w/o debugger).<br>
    <blockquote type="cite" cite="mid:CAA-vtUxzg_pcFYQg8vYV2GxTqm6+9PtQhotKQWaS_RM+W6U9tw@mail.gmail.com">
      <div><br>
      </div>
      <div>I would have thought that you need to treat GetLastError
        special. JNA seems to do this: <a href="https://urldefense.com/v3/__https://github.com/java-native-access/jna/blob/999c60a1fa0ab1154b07edffa3748ce46d8d3b89/src/com/sun/jna/NativeLibrary.java*L130__;Iw!!ACWV5N9M2RV99hQ!NWK1fBgnKORxT1DxxqZUDYS8q6cpWFtkYT-ZAvza_QQZhDy60oq-_IL3t5bN2z0NqpsM_5Bmhser_482CIZi2lkCeVarA68$" moz-do-not-send="true">https://github.com/java-native-access/jna/blob/999c60a1fa0ab1154b07edffa3748ce46d8d3b89/src/com/sun/jna/NativeLibrary.java#L130</a></div>
      <div> </div>
    </blockquote>
    <p>I see, JNA saves this value after the call:</p>
    <p><a class="moz-txt-link-freetext" href="https://github.com/java-native-access/jna/blob/master/native/dispatch.c#L681">https://github.com/java-native-access/jna/blob/master/native/dispatch.c#L681</a></p>
    <p>JNR seems to have something similar:</p>
    <p><a class="moz-txt-link-freetext" href="https://github.com/jnr/jffi/blob/39cfdaff1b7882823dd21f17a11ca68fbf974a92/jni/jffi/CallContext.h#L59">https://github.com/jnr/jffi/blob/39cfdaff1b7882823dd21f17a11ca68fbf974a92/jni/jffi/CallContext.h#L59</a></p>
    <p>That said, I'd expect JNI to still fail in a similar way (unless
      the call and the check occur in the same call).<br>
    </p>
    <p>Maurizio<br>
    </p>
    <p><br>
    </p>
    <p><br>
    </p>
  </body>
</html>