<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>It looks like <span class="pl-en">io_uring_wait_cqe [1] takes as
        second argument a pointer to a pointer, but you pass it an
        pointer to a struct.</span></p>
    <div>I think it s<span class="pl-en">hould be:</span><br>
    </div>
    <p>    // struct io_uring_cqe **<span class="pl-en">cqeRef =
        malloc(sizeof *cqeRef);</span><br>
      <span class="pl-en"><span class="pl-smi">    MemorySegment</span>
        cqeRef = <span class="pl-s1">MemorySegment</span>.<span class="pl-en">allocateNative</span>(C_POINTER, <span class="pl-s1">session</span>);<br>
      </span>    io_uring_wait_cqe(ring, <span class="pl-en">cqeRef</span>);<br>
          // struct io_uring_cqe *cqe = *cqeRef;<br>
          MemoryAddress cqe = <span class="pl-en">cqeRef.get(C_POINTER,
        0)</span><span class="pl-en">;</span><br>
    </p>
    <p>    MemoryAddress user_data = io_uring_cqe_get_data(cqe);<br>
          MemorySegment user_data_segment =
      MemorySegment.ofAddress(user_data, myStructLayout.byteSize(),
      session);</p>
    <div>Note that MemorySegment::asSlice doesn't perform any
      dereference, so it is not equivalent to `cqes[0]`.<br>
    </div>
    <div><br>
    </div>
    <div>Jorn<br>
    </div>
    <div><br>
    </div>
    <div>[1]:
      <a class="moz-txt-link-freetext" href="https://man.archlinux.org/man/extra/liburing/io_uring_wait_cqe.3.en">https://man.archlinux.org/man/extra/liburing/io_uring_wait_cqe.3.en</a><br>
    </div>
    <div><br>
    </div>
    <div class="moz-cite-prefix">On 23/09/2022 22:15, Gavin Ray wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CAFtvWZPEw=jAvgv19Z=wjyrNFtGa6HwyOcDvPkZu0R9D0YoCtg@mail.gmail.com">
      <div dir="ltr">
        <div dir="ltr">
          <div dir="ltr">
            <div dir="ltr">
              <div dir="ltr">Okay, it seems I've gotten the "hello
                world" almost working
                <div><br>
                </div>
                <div>The only problem left is that trying to read
                  the "user_data" pointer returned gives garbage.</div>
                <div>When I submit the event, I attach a struct to it,
                  like this:</div>
                <div><br>
                </div>
                <div>
                  <div>        MemorySegment myStruct =
                    MemorySegment.allocateNative(myStructLayout,
                    session);</div>
                  <div>        myStruct$foo.set(myStruct, 1);</div>
                  <div>        myStruct$bar.set(myStruct, 2);</div>
                  <div>        io_uring_sqe_set_data(sqePtr, myStruct);</div>
                </div>
                <div><br>
                </div>
                <div>Then when the results come back, I am doing this to
                  read the userdata pointer:</div>
                <div><br>
                </div>
                <div>
                  <div>        MemorySegment cqes =
                    io_uring_cqe.allocateArray(1, allocator);</div>
                  <div>        io_uring_wait_cqe(ring, cqes);</div>
                  <div>        // cqes[0]</div>
                  <div>        MemorySegment cqe = cqes.asSlice(0,
                    io_uring_cqe.$LAYOUT().byteSize());</div>
                  <div>        // cqes[0]->user_data</div>
                  <div>        MemoryAddress user_data =
                    MemoryAddress.ofLong(io_uring_cqe.user_data$get(cqe));</div>
                  <div>        MemorySegment user_data_segment =
                    MemorySegment.ofAddress(user_data,
                    myStructLayout.byteSize(), session);</div>
                </div>
                <div><br>
                </div>
                <div>I try to print it out, comparing the "foo" and
                  "bar" field against the original values of "1" and "2"</div>
                <div><br>
                </div>
                <div>
                  <div>        user_data->foo=1480561120</div>
                  <div>        user_data->bar=32545</div>
                </div>
                <div><br>
                </div>
                <div>Does anyone know/see what I am doing wrong here? 🤔</div>
                <div>
                  <div><a href="https://gist.github.com/GavinRay97/8ea0997693c00f8df61968a98ba30135#file-io_uring-java-L48-L55" moz-do-not-send="true" class="moz-txt-link-freetext">https://gist.github.com/GavinRay97/8ea0997693c00f8df61968a98ba30135#file-io_uring-java-L48-L55</a></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Wed, Sep 21, 2022 at 8:18
          PM Gavin Ray <<a href="mailto:ray.gavin97@gmail.com" moz-do-not-send="true" class="moz-txt-link-freetext">ray.gavin97@gmail.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 dir="ltr">
            <div dir="ltr">@Daniel, I didn't know the lwjgl folks were
              looking into this area, I've had a brief look but it's
              definitely something I want to check out more!
              <div><br>
              </div>
              <div>@Maurizio, the idea about defining a second library
                that depends on it is pretty clever.</div>
              <div><br>
              </div>
              <div>It turns out that you can pull liburing in with CMake
                without so much effort</div>
              <div>To set that scenario up was just the below code, this
                should work decently 👍</div>
              <div><br>
              </div>
              <div>=============================</div>
              <div>
                <div>ExternalProject_Add(</div>
                <div>        liburing_git</div>
                <div>        GIT_REPOSITORY <a href="http://github.com/axboe/liburing.git" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">http://github.com/axboe/liburing.git</a></div>
                <div>        GIT_TAG liburing-2.2</div>
                <div>        BUILD_IN_SOURCE 1</div>
                <div>        BUILD_BYPRODUCTS
                  "<SOURCE_DIR>/src/liburing.a"</div>
                <div>        BUILD_COMMAND make</div>
                <div>)</div>
                <div>ExternalProject_Get_Property(liburing_git
                  SOURCE_DIR)</div>
                <div>add_library(liburing INTERFACE)</div>
                <div>add_dependencies(liburing liburing_git)</div>
                <div>target_include_directories(liburing INTERFACE
                  ${SOURCE_DIR}/src/include)</div>
                <div>target_link_libraries(liburing INTERFACE
                  ${SOURCE_DIR}/src/liburing.a)</div>
                <div><br>
                </div>
                <div># NOW LINK IT TO SECOND LIBRARY</div>
                <div>add_library(liburing_extras SHARED
                  liburing_extras/main.c)</div>
                <div>target_link_libraries(liburing_extras liburing)</div>
                <div>add_dependencies(liburing_extras liburing)</div>
              </div>
              <div><br>
              </div>
            </div>
          </div>
          <br>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">On Wed, Sep 21, 2022 at
              7:24 PM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">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"><br>
              On 21/09/2022 23:39, Gavin Ray wrote:<br>
              > That makes sense -- I will look at patching liburing
              with a dirty <br>
              > one-liner that strips "static inline" from the
              definitions that have <br>
              > them then, ty =)<br>
              <br>
              Sorry, hit send too fast, and forgot to reply to this.<br>
              <br>
              There are few approaches that can be tried.<br>
              <br>
              First, you could define another shared library that
              depends on io_uring <br>
              - e.g. a C file which includes the io_uring header. This
              new file would <br>
              contain _new_ exported symbols for all the static inline
              functions, <br>
              whose implementation just delegates to the underlying
              static inline <br>
              functions (in the included io_uring header). Then you load
              up the <br>
              library with Panama and, if you have set up things
              correctly, you will <br>
              see both the static inlines and the exported symbols in IO
              uring. (in <br>
              fact, we do a similar trick to expose system library
              symbols like <br>
              "printf" on Windows, which implements them as macros).<br>
              <br>
              Another (more fun?) option would be to just keep the
              original library, <br>
              and implement the static inline functions in Java
              directly, using the <br>
              FFM API. Most of the functions I see have only 2-3 lines
              in them, so it <br>
              shouldn't be hard.<br>
              <br>
              Maurizio<br>
              <br>
            </blockquote>
          </div>
        </blockquote>
      </div>
    </blockquote>
  </body>
</html>