Skip to content

Commit d4c7db5

Browse files
AntonKozlovVladimir Kempik
authored andcommitted
8257620: Do not use objc_msgSend_stret to get macOS version
Reviewed-by: ihse, rriggs
1 parent 8e42efa commit d4c7db5

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/java.base/macosx/native/libjava/java_props_macosx.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,16 @@ void setOSNameAndVersion(java_props_t *sprops) {
236236

237237
char* osVersionCStr = NULL;
238238
// Mac OS 10.9 includes the [NSProcessInfo operatingSystemVersion] function,
239-
// but it's not in the 10.9 SDK. So, call it via objc_msgSend_stret.
239+
// but it's not in the 10.9 SDK. So, call it via NSInvocation.
240240
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
241-
OSVerStruct (*procInfoFn)(id rec, SEL sel) = (OSVerStruct(*)(id, SEL))objc_msgSend_stret;
242-
OSVerStruct osVer = procInfoFn([NSProcessInfo processInfo],
243-
@selector(operatingSystemVersion));
241+
OSVerStruct osVer;
242+
NSMethodSignature *sig = [[NSProcessInfo processInfo] methodSignatureForSelector:
243+
@selector(operatingSystemVersion)];
244+
NSInvocation *invoke = [NSInvocation invocationWithMethodSignature:sig];
245+
invoke.selector = @selector(operatingSystemVersion);
246+
[invoke invokeWithTarget:[NSProcessInfo processInfo]];
247+
[invoke getReturnValue:&osVer];
248+
244249
NSString *nsVerStr;
245250
if (osVer.patchVersion == 0) { // Omit trailing ".0"
246251
nsVerStr = [NSString stringWithFormat:@"%ld.%ld",

0 commit comments

Comments
 (0)