Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add code to build on OpenBSD #469

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/build-definitions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ This script is included in /build.xml and /config/update-dependencies.xml.
<condition property="platform.freebsd">
<os name="FreeBSD"/>
</condition>
<condition property="platform.openbsd">
<os name="OpenBSD"/>
</condition>
<condition property="platform.solaris">
<os name="SunOS"/>
</condition>
Expand All @@ -106,10 +109,12 @@ This script is included in /build.xml and /config/update-dependencies.xml.
<property name="platform" value="windows" if:set="platform.windows"/>
<property name="platform" value="linux" if:set="platform.linux"/>
<property name="platform" value="freebsd" if:set="platform.freebsd"/>
<property name="platform" value="openbsd" if:set="platform.openbsd"/>
<property name="platform" value="solaris" if:set="platform.solaris"/>
<property name="platform" value="macos" if:set="platform.macos"/>

<property name="platform.remote" value="macosx" if:set="platform.macos"/>
<property name="platform.remote" value="linux" if:set="platform.openbsd"/>
<property name="platform.remote" value="${platform}"/>

<!-- JDK version -->
Expand Down
476 changes: 476 additions & 0 deletions config/openbsd/build.xml

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions config/openbsd/version.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
LWJGL {
# Expose symbols required by the JVM
global:
*org_lwjgl_*;
JNI_On*;
__wrap_memcpy;

# Hide everything else
local: *;
};
3 changes: 3 additions & 0 deletions modules/lwjgl/core/src/main/c/common_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#ifdef LWJGL_LINUX
#include "LinuxConfig.h"
#endif
#ifdef LWJGL_OPENBSD
#include "OpenBSDConfig.h"
#endif
#ifdef LWJGL_MACOS
#include "macOSConfig.h"
#endif
Expand Down
8 changes: 8 additions & 0 deletions modules/lwjgl/core/src/main/c/openbsd/LinuxLWJGL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
#pragma once

#include <X11/X.h>
#include <X11/Xlib.h>
14 changes: 14 additions & 0 deletions modules/lwjgl/core/src/main/c/openbsd/OpenBSDConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/

#include <stddef.h>
#include <inttypes.h>

#define DISABLE_WARNINGS()
#define ENABLE_WARNINGS()

// JNIEXPORT_CRITICAL & CRITICAL are used as a workaround for JDK-8167409 on applicable functions.
#define JNIEXPORT_CRITICAL static
#define CRITICAL(function) _JavaCritical_##function
9 changes: 9 additions & 0 deletions modules/lwjgl/core/src/main/c/openbsd/wrap_memcpy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <stddef.h>

void *old_memcpy(void *, const void *, size_t);

__asm__(".symver old_memcpy,memcpy@GLIBC_2.2.5");

void *__wrap_memcpy(void *dest, const void *src, size_t n) {
return old_memcpy(dest, src, n);
}
10 changes: 7 additions & 3 deletions modules/lwjgl/remotery/src/main/c/Remotery.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static rmtBool g_SettingsInitialized = RMT_FALSE;
#include <mach/mach.h>
#include <sys/time.h>
#else
#ifndef __FreeBSD__
#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
#include <malloc.h>
#endif
#endif
Expand Down Expand Up @@ -248,7 +248,7 @@ static rmtU32 msTimer_Get()
clock_t time = clock();

// CLOCKS_PER_SEC is 128 on FreeBSD, causing div/0
#ifdef __FreeBSD__
#if defined(__FreeBSD__) || defined(__OpenBSD__)
rmtU32 msTime = (rmtU32) (time * 1000 / CLOCKS_PER_SEC);
#else
rmtU32 msTime = (rmtU32) (time / (CLOCKS_PER_SEC / 1000));
Expand Down Expand Up @@ -322,7 +322,7 @@ static rmtU64 usTimer_Get(usTimer* timer)
rmtU64 curr_time = mach_absolute_time();
return (rmtU64)((curr_time - timer->counter_start) * timer->counter_scale);

#elif defined(RMT_PLATFORM_LINUX)
#elif defined(RMT_PLATFORM_LINUX) || defined(__OpenBSD__)

struct timespec tv;
clock_gettime(CLOCK_REALTIME, &tv);
Expand Down Expand Up @@ -4734,6 +4734,8 @@ static rmtError Remotery_ConsumeMessageQueue(Remotery* rmt)
error = Remotery_SendSampleTreeMessage(rmt, message);
rmt_EndCPUSample();
break;
default:
break;
}

// Consume the message before reacting to any errors
Expand Down Expand Up @@ -4771,6 +4773,8 @@ static void Remotery_FlushMessageQueue(Remotery* rmt)
FreeSampleTree(sample_tree->root_sample, sample_tree->allocator);
break;
}
default:
break;
}

rmtMessageQueue_ConsumeNextMessage(rmt->mq_to_rmt_thread, message);
Expand Down
2 changes: 2 additions & 0 deletions modules/lwjgl/remotery/src/main/c/Remotery.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ documented just below this comment.
#elif defined(__linux__) || defined(__FreeBSD__)
#define RMT_PLATFORM_LINUX
#define RMT_PLATFORM_POSIX
#elif defined(__OpenBSD__)
#define RMT_PLATFORM_POSIX
#elif defined(__APPLE__)
#define RMT_PLATFORM_MACOS
#define RMT_PLATFORM_POSIX
Expand Down