Skip to content

Commit

Permalink
feat(liburing): add liburing bindings
Browse files Browse the repository at this point in the history
This is a work-in-progress, even though the liburing/io_uring bindings
are complete. A lot more Linux APIs will be added in the future in order
for io_uring to be fully usable.
  • Loading branch information
Spasi committed Dec 20, 2021
1 parent 7481408 commit e48de92
Show file tree
Hide file tree
Showing 76 changed files with 23,348 additions and 3 deletions.
1 change: 1 addition & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@
<include name="org/lwjgl/demo/stb/**" if:set="test.stb"/>

<include name="org/lwjgl/demo/system/jawt/**" if:set="test.jawt"/>
<include name="org/lwjgl/demo/system/linux/liburing/**" if:set="platform.linux"/>

<include name="org/lwjgl/demo/util/*.java"/>
<include name="org/lwjgl/demo/util/lmdb/**" if:true="${binding.lmdb}"/>
Expand Down
17 changes: 14 additions & 3 deletions config/linux/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
<arg line="-c -std=gnu++11" if:set="cpp"/>
<arg line="-m64" if:set="build.arch.x64"/>
<arg line="-m32 -mfpmath=sse -msse -msse2" if:set="build.arch.x86"/>
<arg line="-O3 @{lto} -fPIC @{flags} -pthread -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -D_GNU_SOURCE -DNDEBUG -DLWJGL_LINUX -DLWJGL_${build.arch}"/>
<arg line="-O3 @{lto} -fPIC @{flags} -pthread -DNDEBUG -DLWJGL_LINUX -DLWJGL_${build.arch}"/>
<arg line="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -D_GNU_SOURCE"/>
<arg line="-D_FILE_OFFSET_BITS=64"/>

<arg value="-I${jni.headers}"/>
<arg value="-I${jni.headers}/linux"/>
Expand Down Expand Up @@ -162,13 +164,22 @@

<!-- CORE -->
<build module="core" flags="-Werror -Wfatal-errors -Wall -Wextra -pedantic">
<beforeCompile>
<compile>
<arg value="-I${src.main.rel}/${platform}/liburing"/>
<arg value="-I${src.main.rel}/${platform}/liburing/include"/>
<arg value="-DCONFIG_HAVE_MEMFD_CREATE"/>
<fileset dir="." includes="${src.main}/${platform}/liburing/*.c"/>
</compile>
</beforeCompile>
<source>
<arg value="-I${src.main.rel}/libffi"/>
<arg value="-I${src.main.rel}/libffi/aarch64" if:set="build.arch.arm64"/>
<arg value="-I${src.main.rel}/libffi/arm" if:set="build.arch.arm32"/>
<arg value="-I${src.main.rel}/libffi/x86" unless:set="build.arch.arm"/>
<!-- for libffi/x86/ffitarget.h -->
<arg value="-DX86_64" if:set="build.arch.x64"/>
<arg value="-DX86_64" if:set="build.arch.x64"/> <!-- for libffi/x86/ffitarget.h -->
<arg value="-I${src.main.rel}/${platform}/liburing"/>
<arg value="-I${src.main.rel}/${platform}/liburing/include"/>
<fileset dir=".">
<include name="${src.main}/*.c"/>
<include name="${src.generated}/*.c"/>
Expand Down
2 changes: 2 additions & 0 deletions doc/notes/3.3.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This build includes the following changes:

#### Bindings

- Added [liburing](https://github.com/axboe/liburing) bindings.
* Can be found in the LWJGL core module (package `org.lwjgl.system.linux.liburing`).
- Assimp: Updated to 5.1.1 (up from 5.1.0)
- meshoptimizer: Updated to 0.17 (up from 0.16)
- Vulkan: Updated to 1.2.199 (up from 1.2.198)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ private fun CXComment.parse(doc: Documentation, builder: StringBuilder, context:
parseChildren(doc, builder, context)
builder.append("</h3>")
}
"pre" -> {
builder.append("Precondition: ")
parseChildren(doc, builder, context)
}
"return",
"returns",
"result" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ val unsigned_short = IntegerType("unsigned short", PrimitiveMapping.SHORT, unsig
val unsigned_int = IntegerType("unsigned int", PrimitiveMapping.INT, unsigned = true)
val unsigned_intb = PrimitiveType("unsigned int", PrimitiveMapping.BOOLEAN4)
val unsigned_long = IntegerType("unsigned long", PrimitiveMapping.CLONG, unsigned = true)
val unsigned_long_int = IntegerType("unsigned long int", PrimitiveMapping.CLONG, unsigned = true)
val unsigned_long_long = IntegerType("unsigned long long", PrimitiveMapping.LONG, unsigned = true)

// strings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ enum class Module(
"org.lwjgl.system.linux",
"Contains bindings to native APIs specific to the Linux operating system."
),
CORE_LINUX_LIBURING(
"core.linux.liburing",
"org.lwjgl.system.linux.liburing",
"Contains bindings to liburing." // TODO:
),
CORE_MACOS(
"core.macos",
"org.lwjgl.system.macosx",
Expand Down
7 changes: 7 additions & 0 deletions modules/lwjgl/core/liburing_license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2020 Jens Axboe

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
* MACHINE GENERATED FILE, DO NOT EDIT
*/
#include "common_tools.h"
#include <fcntl.h>
#include <errno.h>

EXTERN_C_ENTER

JNIEXPORT jint JNICALL Java_org_lwjgl_system_linux_FCNTL_nopen(JNIEnv *__env, jclass clazz, jlong pathnameAddress, jint flags, jint mode) {
char const *pathname = (char const *)(intptr_t)pathnameAddress;
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = (jint)open(pathname, flags, (mode_t)mode);
saveErrno();
return __result;
}

JNIEXPORT jint JNICALL Java_org_lwjgl_system_linux_FCNTL_nopenat(JNIEnv *__env, jclass clazz, jint dirfd, jlong pathnameAddress, jint flags, jint mode) {
char const *pathname = (char const *)(intptr_t)pathnameAddress;
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = (jint)openat(dirfd, pathname, flags, (mode_t)mode);
saveErrno();
return __result;
}

JNIEXPORT jint JNICALL Java_org_lwjgl_system_linux_FCNTL_ncreat(JNIEnv *__env, jclass clazz, jlong pathnameAddress, jint mode) {
char const *pathname = (char const *)(intptr_t)pathnameAddress;
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = (jint)creat(pathname, (mode_t)mode);
saveErrno();
return __result;
}

JNIEXPORT jint JNICALL Java_org_lwjgl_system_linux_FCNTL_fcntl(JNIEnv *__env, jclass clazz, jint fd, jint cmd) {
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = (jint)fcntl(fd, cmd);
saveErrno();
return __result;
}

JNIEXPORT jint JNICALL Java_org_lwjgl_system_linux_FCNTL_nfcntli(JNIEnv *__env, jclass clazz, jint fd, jint cmd, jint arg) {
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = (jint)fcntl(fd, cmd, arg);
saveErrno();
return __result;
}

JNIEXPORT jint JNICALL Java_org_lwjgl_system_linux_FCNTL_nfcntlp(JNIEnv *__env, jclass clazz, jint fd, jint cmd, jlong argAddress) {
void *arg = (void *)(intptr_t)argAddress;
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = (jint)fcntl(fd, cmd, arg);
saveErrno();
return __result;
}

EXTERN_C_EXIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
* MACHINE GENERATED FILE, DO NOT EDIT
*/
#include "common_tools.h"
#include <sys/mman.h>
#include <errno.h>

EXTERN_C_ENTER

JNIEXPORT jlong JNICALL Java_org_lwjgl_system_linux_MMAN_mmap(JNIEnv *__env, jclass clazz, jlong addrAddress, jlong length, jint prot, jint flags, jint fd, jlong offset) {
void *addr = (void *)(intptr_t)addrAddress;
jlong __result;
UNUSED_PARAMS(__env, clazz)
__result = (jlong)(intptr_t)mmap(addr, (size_t)length, prot, flags, fd, (off_t)offset);
saveErrno();
return __result;
}

JNIEXPORT jint JNICALL Java_org_lwjgl_system_linux_MMAN_nmunmap(JNIEnv *__env, jclass clazz, jlong addrAddress, jlong length) {
void *addr = (void *)(intptr_t)addrAddress;
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = (jint)munmap(addr, (size_t)length);
saveErrno();
return __result;
}

EXTERN_C_EXIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
* MACHINE GENERATED FILE, DO NOT EDIT
*/
#include "common_tools.h"
#include <sys/socket.h>
#include <errno.h>

EXTERN_C_ENTER

JNIEXPORT jint JNICALL Java_org_lwjgl_system_linux_Socket_socket(JNIEnv *__env, jclass clazz, jint __domain, jint __type, jint __protocol) {
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = (jint)socket(__domain, __type, __protocol);
saveErrno();
return __result;
}

EXTERN_C_EXIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
* MACHINE GENERATED FILE, DO NOT EDIT
*/
#include "common_tools.h"
#include <sys/stat.h>
#include <errno.h>

EXTERN_C_ENTER

JNIEXPORT jint JNICALL Java_org_lwjgl_system_linux_Stat_nstat(JNIEnv *__env, jclass clazz, jlong __fileAddress, jlong __bufAddress) {
char const *__file = (char const *)(intptr_t)__fileAddress;
struct stat *__buf = (struct stat *)(intptr_t)__bufAddress;
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = (jint)stat(__file, __buf);
saveErrno();
return __result;
}

JNIEXPORT jint JNICALL Java_org_lwjgl_system_linux_Stat_nfstat(JNIEnv *__env, jclass clazz, jint __fd, jlong __bufAddress) {
struct stat *__buf = (struct stat *)(intptr_t)__bufAddress;
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = (jint)fstat(__fd, __buf);
saveErrno();
return __result;
}

EXTERN_C_EXIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
* MACHINE GENERATED FILE, DO NOT EDIT
*/
#include "common_tools.h"
#include <sys/uio.h>
#include <errno.h>

EXTERN_C_ENTER

JNIEXPORT jlong JNICALL Java_org_lwjgl_system_linux_UIO_nreadv(JNIEnv *__env, jclass clazz, jint __fd, jlong __iovecAddress, jint __count) {
struct iovec const *__iovec = (struct iovec const *)(intptr_t)__iovecAddress;
jlong __result;
UNUSED_PARAMS(__env, clazz)
__result = (jlong)readv(__fd, __iovec, __count);
saveErrno();
return __result;
}

JNIEXPORT jlong JNICALL Java_org_lwjgl_system_linux_UIO_nwritev(JNIEnv *__env, jclass clazz, jint __fd, jlong __iovecAddress, jint __count) {
struct iovec const *__iovec = (struct iovec const *)(intptr_t)__iovecAddress;
jlong __result;
UNUSED_PARAMS(__env, clazz)
__result = (jlong)writev(__fd, __iovec, __count);
saveErrno();
return __result;
}

JNIEXPORT jlong JNICALL Java_org_lwjgl_system_linux_UIO_npreadv(JNIEnv *__env, jclass clazz, jint __fd, jlong __iovecAddress, jint __count, jlong __offset) {
struct iovec const *__iovec = (struct iovec const *)(intptr_t)__iovecAddress;
jlong __result;
UNUSED_PARAMS(__env, clazz)
__result = (jlong)preadv(__fd, __iovec, __count, (off_t)__offset);
saveErrno();
return __result;
}

JNIEXPORT jlong JNICALL Java_org_lwjgl_system_linux_UIO_npwritev(JNIEnv *__env, jclass clazz, jint __fd, jlong __iovecAddress, jint __count, jlong __offset) {
struct iovec const *__iovec = (struct iovec const *)(intptr_t)__iovecAddress;
jlong __result;
UNUSED_PARAMS(__env, clazz)
__result = (jlong)pwritev(__fd, __iovec, __count, (off_t)__offset);
saveErrno();
return __result;
}

JNIEXPORT jlong JNICALL Java_org_lwjgl_system_linux_UIO_npreadv2(JNIEnv *__env, jclass clazz, jint __fd, jlong __iovecAddress, jint __count, jlong __offset, jint __flags) {
struct iovec const *__iovec = (struct iovec const *)(intptr_t)__iovecAddress;
jlong __result;
UNUSED_PARAMS(__env, clazz)
__result = (jlong)preadv2(__fd, __iovec, __count, (off_t)__offset, __flags);
saveErrno();
return __result;
}

JNIEXPORT jlong JNICALL Java_org_lwjgl_system_linux_UIO_npwritev2(JNIEnv *__env, jclass clazz, jint __fd, jlong __iovecAddress, jint __count, jlong __offset, jint __flags) {
struct iovec const *__iovec = (struct iovec const *)(intptr_t)__iovecAddress;
jlong __result;
UNUSED_PARAMS(__env, clazz)
__result = (jlong)pwritev2(__fd, __iovec, __count, (off_t)__offset, __flags);
saveErrno();
return __result;
}

JNIEXPORT jlong JNICALL Java_org_lwjgl_system_linux_UIO_nprocess_1vm_1readv(JNIEnv *__env, jclass clazz, jint __pid, jlong __lvecAddress, jlong __liovcnt, jlong __rvecAddress, jlong __riovcnt, jlong __flags) {
struct iovec const *__lvec = (struct iovec const *)(intptr_t)__lvecAddress;
struct iovec const *__rvec = (struct iovec const *)(intptr_t)__rvecAddress;
jlong __result;
UNUSED_PARAMS(__env, clazz)
__result = (jlong)process_vm_readv((pid_t)__pid, __lvec, (unsigned long int)__liovcnt, __rvec, (unsigned long int)__riovcnt, (unsigned long int)__flags);
saveErrno();
return __result;
}

JNIEXPORT jlong JNICALL Java_org_lwjgl_system_linux_UIO_nprocess_1vm_1writev(JNIEnv *__env, jclass clazz, jint __pid, jlong __lvecAddress, jlong __liovcnt, jlong __rvecAddress, jlong __riovcnt, jlong __flags) {
struct iovec const *__lvec = (struct iovec const *)(intptr_t)__lvecAddress;
struct iovec const *__rvec = (struct iovec const *)(intptr_t)__rvecAddress;
jlong __result;
UNUSED_PARAMS(__env, clazz)
__result = (jlong)process_vm_writev((pid_t)__pid, __lvec, (unsigned long int)__liovcnt, __rvec, (unsigned long int)__riovcnt, (unsigned long int)__flags);
saveErrno();
return __result;
}

EXTERN_C_EXIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
* MACHINE GENERATED FILE, DO NOT EDIT
*/
#include "common_tools.h"
#include <unistd.h>
#include <errno.h>

EXTERN_C_ENTER

JNIEXPORT jint JNICALL Java_org_lwjgl_system_linux_UNISTD_close(JNIEnv *__env, jclass clazz, jint fd) {
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = (jint)close(fd);
saveErrno();
return __result;
}

JNIEXPORT jlong JNICALL Java_org_lwjgl_system_linux_UNISTD_sysconf(JNIEnv *__env, jclass clazz, jint name) {
jlong __result;
UNUSED_PARAMS(__env, clazz)
__result = (jlong)sysconf(name);
saveErrno();
return __result;
}

JNIEXPORT jlong JNICALL Java_org_lwjgl_system_linux_UNISTD_nread(JNIEnv *__env, jclass clazz, jint fd, jlong bufAddress, jlong count) {
void *buf = (void *)(intptr_t)bufAddress;
jlong __result;
UNUSED_PARAMS(__env, clazz)
__result = (jlong)read(fd, buf, (size_t)count);
saveErrno();
return __result;
}

EXTERN_C_EXIT
Loading

0 comments on commit e48de92

Please sign in to comment.