Skip to content
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
25 changes: 25 additions & 0 deletions bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "swt.h"
#include "os_structs.h"
#include "os_stats.h"
#include <mach-o/loader.h>
#include <crt_externs.h>

#define OS_NATIVE(func) Java_org_eclipse_swt_internal_cocoa_OS_##func

Expand Down Expand Up @@ -150,3 +152,26 @@ JNIEXPORT jlong JNICALL OS_NATIVE(beginSheetModalForWindow)
}
#endif

#ifndef NO_getMachOSDKVersion
JNIEXPORT jint JNICALL OS_NATIVE(getMachOSDKVersion)
(JNIEnv *env, jclass that)
{
jint rc = 0;
OS_NATIVE_ENTER(env, that, getMachOSDKVersion_FUNC);
const struct mach_header_64 *header = (const struct mach_header_64 *)_NSGetMachExecuteHeader();
const uint8_t *ptr = (const uint8_t *)header + sizeof(struct mach_header_64);
for (uint32_t i = 0; i < header->ncmds; i++) {
const struct load_command *lc = (const struct load_command *)ptr;
if (lc->cmd == LC_BUILD_VERSION) {
const struct build_version_command *bv = (const struct build_version_command *)ptr;
uint32_t sdk = bv->sdk;
rc = (jint)(((sdk >> 16) & 0xff) << 16) | (((sdk >> 8) & 0xff) << 8) | (sdk & 0xff);
break;
}
ptr += lc->cmdsize;
}
OS_NATIVE_EXIT(env, that, getMachOSDKVersion_FUNC);
return rc;
}
#endif

Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ typedef enum {
class_1getMethodImplementation_FUNC,
class_1getName_FUNC,
class_1getSuperclass_FUNC,
getMachOSDKVersion_FUNC,
getpid_FUNC,
instrumentObjcMessageSends_FUNC,
isFlipped_1CALLBACK_FUNC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ public static int VERSION (int major, int minor, int bugfix) {
return (major << 16) + (minor << 8) + bugfix;
}

public static int VERSION_MAJOR (int version) {
return (version >>> 16) & 0xFF;
}

public static int VERSION_MINOR (int version) {
return (version >>> 8) & 0xFF;
}

public static int VERSION_BUGFIX (int version) {
return version & 0xFF;
}

public static final boolean IS_X86_64 = System.getProperty("os.arch").equals("x86_64"); //$NON-NLS-1$

/*
Expand Down Expand Up @@ -336,6 +348,14 @@ public static boolean isSystemDarkAppearance() {

public static final native int getpid();

/**
* Returns the SDK version from LC_BUILD_VERSION in the main executable's
* Mach-O header, encoded as {@code (major << 16) + (minor << 8) + bugfix}.
* Returns 0 if LC_BUILD_VERSION is not found.
* @method flags=no_gen
*/
public static final native int getMachOSDKVersion();

public static final native void call(long proc, long id, long sel);

/** QuickDraw calls */
Expand Down
Loading