Skip to content
Browse files
8257620: Do not use objc_msgSend_stret to get macOS version
Backport-of: d4c7db5
  • Loading branch information
Vladimir Kempik committed Jul 28, 2021
1 parent 6e60332 commit 0e2d915d26688d27a7dd91a179f0a746b19a6749
Showing with 9 additions and 4 deletions.
  1. +9 −4 src/java.base/macosx/native/libjava/java_props_macosx.c
@@ -256,11 +256,16 @@ void setOSNameAndVersion(java_props_t *sprops) {

char* osVersionCStr = NULL;
// Mac OS 10.9 includes the [NSProcessInfo operatingSystemVersion] function,
// but it's not in the 10.9 SDK. So, call it via objc_msgSend_stret.
// but it's not in the 10.9 SDK. So, call it via NSInvocation.
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
OSVerStruct (*procInfoFn)(id rec, SEL sel) = (OSVerStruct(*)(id, SEL))objc_msgSend_stret;
OSVerStruct osVer = procInfoFn([NSProcessInfo processInfo],
OSVerStruct osVer;
NSMethodSignature *sig = [[NSProcessInfo processInfo] methodSignatureForSelector:
NSInvocation *invoke = [NSInvocation invocationWithMethodSignature:sig];
invoke.selector = @selector(operatingSystemVersion);
[invoke invokeWithTarget:[NSProcessInfo processInfo]];
[invoke getReturnValue:&osVer];

NSString *nsVerStr;
// Copy out the char* if running on version other than 10.16 Mac OS (10.16 == 11.x)
// or explicitly requesting version compatibility

1 comment on commit 0e2d915


This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 0e2d915 Jul 28, 2021

Please sign in to comment.