From 06c3257b4a58a4910e9f7e35061d0ac81336e5b0 Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Mon, 16 Sep 2019 18:58:24 -0700 Subject: [PATCH] Mach ports back to 32-bit ints --- .../src/com/sun/jna/platform/mac/IOKit.java | 21 +- .../com/sun/jna/platform/mac/IOKitUtil.java | 27 +-- .../src/com/sun/jna/platform/mac/SystemB.java | 215 +----------------- .../platform/mac/SystemBFunctionMapper.java | 45 ---- .../jna/platform/mac/DiskArbitrationTest.java | 11 +- .../com/sun/jna/platform/mac/IOKitTest.java | 20 +- .../com/sun/jna/platform/mac/SystemBTest.java | 39 ++-- 7 files changed, 61 insertions(+), 317 deletions(-) delete mode 100644 contrib/platform/src/com/sun/jna/platform/mac/SystemBFunctionMapper.java diff --git a/contrib/platform/src/com/sun/jna/platform/mac/IOKit.java b/contrib/platform/src/com/sun/jna/platform/mac/IOKit.java index 1fc7c5b796..a16013ce2f 100644 --- a/contrib/platform/src/com/sun/jna/platform/mac/IOKit.java +++ b/contrib/platform/src/com/sun/jna/platform/mac/IOKit.java @@ -34,8 +34,6 @@ import com.sun.jna.platform.mac.CoreFoundation.CFMutableDictionaryRef; import com.sun.jna.platform.mac.CoreFoundation.CFStringRef; import com.sun.jna.platform.mac.CoreFoundation.CFTypeRef; -import com.sun.jna.platform.mac.SystemB.MachPort; -import com.sun.jna.platform.mac.SystemB.TaskPort; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.LongByReference; import com.sun.jna.ptr.PointerByReference; @@ -159,16 +157,17 @@ public IOConnect(Pointer p) { * Returns the mach port used to initiate communication with IOKit. * * @param bootstrapPort - * Pass {@link SystemB#MACH_PORT_NULL} for the default. - * @param masterPort + * Pass 0 for the default. + * @param port * A pointer to the master port is returned. Multiple calls to * IOMasterPort will not result in leaking ports (each call to * IOMasterPort adds another send right to the port) but it is * considered good programming practice to deallocate the port when - * you are finished with it using {@link #IOObjectRelease} + * you are finished with it using + * {@link SystemB#mach_port_deallocate}. * @return 0 if successful, otherwise a {@code kern_return_t} error code. */ - int IOMasterPort(MachPort bootstrapPort, PointerByReference masterPort); + int IOMasterPort(int bootstrapPort, IntByReference port); /** * Create a matching dictionary that specifies an {@code IOService} class match. @@ -219,7 +218,7 @@ public IOConnect(Pointer p) { * otherwise it should be released with {@link CoreFoundation#CFRelease} * by the caller. */ - CFMutableDictionaryRef IOBSDNameMatching(MachPort masterPort, int options, String bsdName); + CFMutableDictionaryRef IOBSDNameMatching(int masterPort, int options, String bsdName); /** * Look up a registered IOService object that matches a matching dictionary. @@ -236,7 +235,7 @@ public IOConnect(Pointer p) { *

* The service must be released by the caller. */ - IOService IOServiceGetMatchingService(MachPort masterPort, CFDictionaryRef matchingDictionary); + IOService IOServiceGetMatchingService(int masterPort, CFDictionaryRef matchingDictionary); /** * Look up registered IOService objects that match a matching dictionary. @@ -254,7 +253,7 @@ public IOConnect(Pointer p) { * by the caller when the iteration is finished. * @return 0 if successful, otherwise a {@code kern_return_t} error code. */ - int IOServiceGetMatchingServices(MachPort masterPort, CFDictionaryRef matchingDictionary, + int IOServiceGetMatchingServices(int masterPort, CFDictionaryRef matchingDictionary, PointerByReference iterator); /** @@ -404,7 +403,7 @@ CFTypeRef IORegistryEntrySearchCFProperty(IORegistryEntry entry, String plane, C * @return A handle to the IORegistryEntry root instance, to be released with * {@link #IOObjectRelease} by the caller, or 0 on failure. */ - IORegistryEntry IORegistryGetRootEntry(MachPort masterPort); + IORegistryEntry IORegistryGetRootEntry(int masterPort); /** * Performs an OSDynamicCast operation on an IOKit object. @@ -444,7 +443,7 @@ CFTypeRef IORegistryEntrySearchCFProperty(IORegistryEntry entry, String plane, C * {@link IOServiceClose}. * @return A return code generated by {@code IOService::newUserClient}. */ - int IOServiceOpen(IOService service, TaskPort owningTask, int type, PointerByReference connect); + int IOServiceOpen(IOService service, int owningTask, int type, PointerByReference connect); /** * Returns the busyState of an IOService. diff --git a/contrib/platform/src/com/sun/jna/platform/mac/IOKitUtil.java b/contrib/platform/src/com/sun/jna/platform/mac/IOKitUtil.java index 8e050cd597..60ce834a9b 100644 --- a/contrib/platform/src/com/sun/jna/platform/mac/IOKitUtil.java +++ b/contrib/platform/src/com/sun/jna/platform/mac/IOKitUtil.java @@ -35,7 +35,7 @@ import com.sun.jna.platform.mac.IOKit.IOIterator; import com.sun.jna.platform.mac.IOKit.IORegistryEntry; import com.sun.jna.platform.mac.IOKit.IOService; -import com.sun.jna.platform.mac.SystemB.MachPort; +import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.PointerByReference; /** @@ -44,6 +44,7 @@ public class IOKitUtil { private static final IOKit IO = IOKit.INSTANCE; private static final CoreFoundation CF = CoreFoundation.INSTANCE; + private static final SystemB SYS = SystemB.INSTANCE; private IOKitUtil() { } @@ -59,10 +60,10 @@ private IOKitUtil() { * deallocate the port when you are finished with it, using * {@link SystemB#mach_port_deallocate}. */ - public static MachPort getMasterPort() { - PointerByReference port = new PointerByReference(); - IO.IOMasterPort(SystemB.MACH_PORT_NULL, port); - return new MachPort(port.getValue()); + public static int getMasterPort() { + IntByReference port = new IntByReference(); + IO.IOMasterPort(0, port); + return port.getValue(); } /** @@ -72,9 +73,9 @@ public static MachPort getMasterPort() { * {@link IOKit#IOObjectRelease}. */ public static IORegistryEntry getRoot() { - MachPort masterPort = getMasterPort(); + int masterPort = getMasterPort(); IORegistryEntry root = IO.IORegistryGetRootEntry(masterPort); - masterPort.deallocate(); + SYS.mach_port_deallocate(SYS.mach_task_self(), masterPort); return root; } @@ -106,9 +107,9 @@ public static IOService getMatchingService(String serviceName) { * {@link IOKit#IOObjectRelease}. */ public static IOService getMatchingService(CFDictionaryRef matchingDictionary) { - MachPort masterPort = getMasterPort(); + int masterPort = getMasterPort(); IOService service = IO.IOServiceGetMatchingService(masterPort, matchingDictionary); - masterPort.deallocate(); + SYS.mach_port_deallocate(SYS.mach_task_self(), masterPort); return service; } @@ -140,10 +141,10 @@ public static IOIterator getMatchingServices(String serviceName) { * {@link IOKit#IOObjectRelease}. */ public static IOIterator getMatchingServices(CFDictionaryRef matchingDictionary) { - MachPort masterPort = getMasterPort(); + int masterPort = getMasterPort(); PointerByReference serviceIterator = new PointerByReference(); int result = IO.IOServiceGetMatchingServices(masterPort, matchingDictionary, serviceIterator); - masterPort.deallocate(); + SYS.mach_port_deallocate(SYS.mach_task_self(), masterPort); if (result == 0 && serviceIterator.getValue() != null) { return new IOIterator(serviceIterator.getValue()); } @@ -159,9 +160,9 @@ public static IOIterator getMatchingServices(CFDictionaryRef matchingDictionary) * should release when finished, using {@link IOKit#IOObjectRelease}. */ public static CFMutableDictionaryRef getBSDNameMatchingDict(String bsdName) { - MachPort masterPort = getMasterPort(); + int masterPort = getMasterPort(); CFMutableDictionaryRef result = IO.IOBSDNameMatching(masterPort, 0, bsdName); - masterPort.deallocate(); + SYS.mach_port_deallocate(SYS.mach_task_self(), masterPort); return result; } diff --git a/contrib/platform/src/com/sun/jna/platform/mac/SystemB.java b/contrib/platform/src/com/sun/jna/platform/mac/SystemB.java index d32c6d806e..2fefff44f3 100644 --- a/contrib/platform/src/com/sun/jna/platform/mac/SystemB.java +++ b/contrib/platform/src/com/sun/jna/platform/mac/SystemB.java @@ -25,16 +25,10 @@ package com.sun.jna.platform.mac; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.sun.jna.IntegerType; import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.NativeLong; import com.sun.jna.Pointer; -import com.sun.jna.PointerType; import com.sun.jna.Structure; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.LongByReference; @@ -42,15 +36,7 @@ public interface SystemB extends Library { - Map OPTIONS = Collections.unmodifiableMap(new HashMap() { - private static final long serialVersionUID = 1L; // we're not serializing it - { - put(OPTION_FUNCTION_MAPPER, new SystemBFunctionMapper()); - } - }); - - SystemB INSTANCE = Native.load("System", SystemB.class, OPTIONS); - + SystemB INSTANCE = Native.load("System", SystemB.class); // host_statistics() int HOST_LOAD_INFO = 1;// System loading stats @@ -100,83 +86,6 @@ public interface SystemB extends Library { // resource.h int RUSAGE_INFO_V2 = 2; - MachPort MACH_PORT_NULL = new MachPort(); - - /** - * Mach ports are the endpoints to Mach-implemented communications channels - * (usually uni-directional message queues, but other types also exist). - *

- * Unique collections of these endpoints are maintained for each Mach task. Each - * Mach port in the task's collection is given a task-local name to identify it - * - and the the various "rights" held by the task for that specific endpoint. - */ - class MachPort extends PointerType { - public MachPort() { - super(); - } - - public MachPort(Pointer p) { - super(p); - } - - /** - * Casts the port's pointer value to its name. - * - * @return The port's {@link MachPortName}. - */ - public MachPortName castToName() { - return new MachPortName(Pointer.nativeValue(this.getPointer())); - } - - /** - * Convenience method for {@link SystemB#mach_port_deallocate} on this port. - * - * @return 0 if successful, a {@code kern_return_t} code otherwise. - */ - public int deallocate() { - return INSTANCE.mach_port_deallocate(INSTANCE.mach_task_self_ptr(), this.castToName()); - } - } - - /** - * Holds the port name of a host name port (or short: host port). Any task can - * get a send right to the name port of the host running the task using the - * mach_host_self system call. The name port can be used to query information - * about the host, for example the current time. - */ - class HostPort extends MachPort { - } - - /** - * Mach Tasks are units of resource ownership; each task consists of a virtual - * address space, a port right namespace, and one or more threads. (Similar to a - * process.) - */ - class TaskPort extends MachPort { - } - - /** - * The name is Mach port namespace specific. It is used to identify the rights - * held for that port by the task whose namespace is implied [or specifically - * provided]. - *

- * Use of this type usually implies just a name - no rights. - *

- * This is an unsigned 32-bit integer type. - */ - class MachPortName extends IntegerType { - private static final long serialVersionUID = 1L; - - /** Create a zero-valued MachPortName. */ - public MachPortName() { - this(0); - } - - /** Create a MachPortName with the given value. */ - public MachPortName(long value) { - super(4, value, true); - } - } @Structure.FieldOrder({ "cpu_ticks" }) public static class HostCpuLoadInfo extends Structure { public int cpu_ticks[] = new int[CPU_STATE_MAX]; @@ -638,18 +547,6 @@ class Timezone extends Structure { * * @return the host's name port */ - HostPort mach_host_self_ptr(); - - /** - * The mach_host_self system call returns the calling thread's host name port. - * It has an effect equivalent to receiving a send right for the host port. - * - * @return the host's name port - * - * @deprecated Using the 32-bit return type may corrupt the stack. Use - * {@link #mach_host_self_ptr} instead. - */ - @Deprecated int mach_host_self(); /** @@ -659,19 +556,6 @@ class Timezone extends Structure { * * @return the task's kernel port */ - TaskPort mach_task_self_ptr(); - - /** - * The mach_task_self system call returns the calling thread's task_self port. - * It has an effect equivalent to receiving a send right for the task's kernel - * port. - * - * @return the task's kernel port - * - * @deprecated Using the 32-bit return type may corrupt the stack. Use - * {@link #mach_task_self_ptr} instead. - */ - @Deprecated int mach_task_self(); /** @@ -683,7 +567,7 @@ class Timezone extends Structure { * The port's name for the right. * @return 0 if successful, a {@code kern_return_t} code otherwise. */ - int mach_port_deallocate(MachPort port, MachPortName name); + int mach_port_deallocate(int port, int name); /** * The host_page_size function returns the page size for the given host. @@ -695,23 +579,7 @@ class Timezone extends Structure { * The host's page size (in bytes), set on success. * @return 0 on success; sets errno on failure */ - int host_page_size(HostPort hostPort, LongByReference pPageSize); - - /** - * The host_page_size function returns the page size for the given host. - * - * @param machPort - * The name (or control) port for the host for which the page size is - * desired. - * @param pPageSize - * The host's page size (in bytes), set on success. - * @return 0 on success; sets errno on failure - * - * @deprecated Using the 32-bit port type argument may corrupt the stack. Use - * {@link #host_page_size(HostPort, LongByReference)} instead. - */ - @Deprecated - int host_page_size(int machPort, LongByReference pPageSize); + int host_page_size(int hostPort, LongByReference pPageSize); /** * The host_statistics function returns scheduling and virtual memory statistics @@ -730,31 +598,7 @@ class Timezone extends Structure { * returned (in natural-sized units). * @return 0 on success; sets errno on failure */ - int host_statistics(HostPort hostPort, int hostStat, Structure stats, IntByReference count); - - /** - * The host_statistics function returns scheduling and virtual memory statistics - * concerning the host as specified by hostStat. - * - * @param machPort - * The control port for the host for which information is to be - * obtained. - * @param hostStat - * The type of statistics desired ({@link #HOST_LOAD_INFO}, - * {@link #HOST_VM_INFO}, or {@link #HOST_CPU_LOAD_INFO}) - * @param stats - * Statistics about the specified host. - * @param count - * On input, the maximum size of the buffer; on output, the size - * returned (in natural-sized units). - * @return 0 on success; sets errno on failure - * - * @deprecated Using the 32-bit port type argument may corrupt the stack. Use - * {@link #host_statistics(HostPort, int, Structure, IntByReference)} - * instead. - */ - @Deprecated - int host_statistics(int machPort, int hostStat, Structure stats, IntByReference count); + int host_statistics(int hostPort, int hostStat, Structure stats, IntByReference count); /** * The host_statistics64 function returns 64-bit virtual memory statistics @@ -772,30 +616,7 @@ class Timezone extends Structure { * returned (in natural-sized units). * @return 0 on success; sets errno on failure */ - int host_statistics64(HostPort hostPort, int hostStat, Structure stats, IntByReference count); - - /** - * The host_statistics64 function returns 64-bit virtual memory statistics - * concerning the host as specified by hostStat. - * - * @param machPort - * The control port for the host for which information is to be - * obtained. - * @param hostStat - * The type of statistics desired ({@link #HOST_VM_INFO64}) - * @param stats - * Statistics about the specified host. - * @param count - * On input, the maximum size of the buffer; on output, the size - * returned (in natural-sized units). - * @return 0 on success; sets errno on failure - * - * @deprecated Using the 32-bit port type argument may corrupt the stack. Use - * {@link #host_statistics64(HostPort, int, Structure, IntByReference)} - * instead. - */ - @Deprecated - int host_statistics64(int machPort, int hostStat, Structure stats, IntByReference count); + int host_statistics64(int hostPort, int hostStat, Structure stats, IntByReference count); /** * The sysctl() function retrieves system information and allows processes with @@ -906,31 +727,7 @@ class Timezone extends Structure { * Pointer to number of elements in the returned structure * @return 0 on success; sets errno on failure */ - int host_processor_info(HostPort hostPort, int flavor, IntByReference procCount, PointerByReference procInfo, - IntByReference procInfoCount); - - /** - * The host_processor_info function returns information about processors. - * - * @param machPort - * The control port for the host for which information is to be - * obtained. - * @param flavor - * The type of information requested. - * @param procCount - * Pointer to the number of processors - * @param procInfo - * Pointer to the structure corresponding to the requested flavor - * @param procInfoCount - * Pointer to number of elements in the returned structure - * @return 0 on success; sets errno on failure - * - * @deprecated Using the 32-bit port type argument may corrupt the stack. Use - * {@link #host_processor_info(HostPort, int, IntByReference, PointerByReference, IntByReference)} - * instead. - */ - @Deprecated - int host_processor_info(int machPort, int flavor, IntByReference procCount, PointerByReference procInfo, + int host_processor_info(int hostPort, int flavor, IntByReference procCount, PointerByReference procInfo, IntByReference procInfoCount); /** diff --git a/contrib/platform/src/com/sun/jna/platform/mac/SystemBFunctionMapper.java b/contrib/platform/src/com/sun/jna/platform/mac/SystemBFunctionMapper.java deleted file mode 100644 index 0bc57f3ea8..0000000000 --- a/contrib/platform/src/com/sun/jna/platform/mac/SystemBFunctionMapper.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2019 Daniel Widdis - * - * The contents of this file is dual-licensed under 2 - * alternative Open Source/Free licenses: LGPL 2.1 or later and - * Apache License 2.0. (starting with JNA version 4.0.0). - * - * You can freely decide which license you want to apply to - * the project. - * - * You may obtain a copy of the LGPL License at: - * - * http://www.gnu.org/licenses/licenses.html - * - * A copy is also included in the downloadable source code package - * containing JNA, in file "LGPL2.1". - * - * You may obtain a copy of the Apache License at: - * - * http://www.apache.org/licenses/ - * - * A copy is also included in the downloadable source code package - * containing JNA, in file "AL2.0". - */ -package com.sun.jna.platform.mac; - -import java.lang.reflect.Method; - -import com.sun.jna.FunctionMapper; -import com.sun.jna.NativeLibrary; - -public class SystemBFunctionMapper implements FunctionMapper { - /** - * Removes the _ptr suffix from methods which return the properly sized pointer - * rather than 32-bit int. - */ - @Override - public String getFunctionName(NativeLibrary library, Method method) { - String name = method.getName(); - if (name.equals("mach_task_self_ptr") || name.equals("mach_host_self_ptr")) { - return name.substring(0, name.length() - 4); - } - return name; - } -} diff --git a/contrib/platform/test/com/sun/jna/platform/mac/DiskArbitrationTest.java b/contrib/platform/test/com/sun/jna/platform/mac/DiskArbitrationTest.java index 85792fee59..b4735543a2 100644 --- a/contrib/platform/test/com/sun/jna/platform/mac/DiskArbitrationTest.java +++ b/contrib/platform/test/com/sun/jna/platform/mac/DiskArbitrationTest.java @@ -46,7 +46,7 @@ import com.sun.jna.platform.mac.DiskArbitration.DASessionRef; import com.sun.jna.platform.mac.IOKit.IOIterator; import com.sun.jna.platform.mac.IOKit.IORegistryEntry; -import com.sun.jna.platform.mac.SystemB.MachPort; +import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.PointerByReference; public class DiskArbitrationTest { @@ -54,12 +54,13 @@ public class DiskArbitrationTest { private static final DiskArbitration DA = DiskArbitration.INSTANCE; private static final CoreFoundation CF = CoreFoundation.INSTANCE; private static final IOKit IO = IOKit.INSTANCE; + private static final SystemB SYS = SystemB.INSTANCE; @Test public void testDiskCreate() { - PointerByReference masterPortPtr = new PointerByReference(); - assertEquals(0, IO.IOMasterPort(SystemB.MACH_PORT_NULL, masterPortPtr)); - MachPort masterPort = new MachPort(masterPortPtr.getValue()); + IntByReference masterPortPtr = new IntByReference(); + assertEquals(0, IO.IOMasterPort(0, masterPortPtr)); + int masterPort = masterPortPtr.getValue(); // Create some keys we'll need CFStringRef daMediaBSDName = CFStringRef.createCFString("DAMediaBSDName"); @@ -146,6 +147,6 @@ public void testDiskCreate() { daMediaBlockSize.release(); session.release(); - assertEquals(0, masterPort.deallocate()); + assertEquals(0, SYS.mach_port_deallocate(SYS.mach_task_self(), masterPort)); } } diff --git a/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java b/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java index 1adb3b8ff2..bfa00016a2 100644 --- a/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java +++ b/contrib/platform/test/com/sun/jna/platform/mac/IOKitTest.java @@ -51,8 +51,6 @@ import com.sun.jna.platform.mac.IOKit.IOObject; import com.sun.jna.platform.mac.IOKit.IORegistryEntry; import com.sun.jna.platform.mac.IOKit.IOService; -import com.sun.jna.platform.mac.SystemB.MachPort; -import com.sun.jna.platform.mac.SystemB.TaskPort; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.LongByReference; import com.sun.jna.ptr.PointerByReference; @@ -61,10 +59,11 @@ public class IOKitTest { private static final CoreFoundation CF = CoreFoundation.INSTANCE; private static final IOKit IO = IOKit.INSTANCE; + private static final SystemB SYS = SystemB.INSTANCE; @Test public void testMatching() { - MachPort masterPort = IOKitUtil.getMasterPort(); + int masterPort = IOKitUtil.getMasterPort(); String match = "matching BSD Name"; CFMutableDictionaryRef dict = IO.IOBSDNameMatching(masterPort, 0, match); @@ -137,12 +136,13 @@ public void testMatching() { cfSerialAsType.release(); assertEquals(0, root.release()); - assertEquals(0, masterPort.deallocate()); + assertEquals(0, SYS.mach_port_deallocate(SystemB.INSTANCE.mach_task_self(), + masterPort)); } @Test public void testIteratorParentChild() { - MachPort masterPort = IOKitUtil.getMasterPort(); + int masterPort = IOKitUtil.getMasterPort(); Set uniqueEntryIdSet = new HashSet<>(); // Iterate over USB Controllers. All devices are children of one of @@ -212,18 +212,19 @@ public void testIteratorParentChild() { controllerDevice = iter.next(); } assertEquals(0, iter.release()); - assertEquals(0, masterPort.deallocate()); + assertEquals(0, SYS.mach_port_deallocate(SystemB.INSTANCE.mach_task_self(), + masterPort)); } @Test public void testIOConnect() { - MachPort masterPort = IOKitUtil.getMasterPort(); + int masterPort = IOKitUtil.getMasterPort(); IOService smcService = IOKitUtil.getMatchingService("AppleSMC"); assertNotNull(smcService); PointerByReference connPtr = new PointerByReference(); - TaskPort taskSelf = SystemB.INSTANCE.mach_task_self_ptr(); + int taskSelf = SYS.mach_task_self(); assertEquals(0, IO.IOServiceOpen(smcService, taskSelf, 0, connPtr)); IOConnect conn = new IOConnect(connPtr.getValue()); @@ -233,7 +234,8 @@ public void testIOConnect() { IO.IOServiceClose(conn); assertEquals(0, smcService.release()); - assertEquals(0, masterPort.deallocate()); + assertEquals(0, SYS.mach_port_deallocate(SystemB.INSTANCE.mach_task_self(), + masterPort)); } @Test diff --git a/contrib/platform/test/com/sun/jna/platform/mac/SystemBTest.java b/contrib/platform/test/com/sun/jna/platform/mac/SystemBTest.java index e12d7b33ed..f24040314f 100644 --- a/contrib/platform/test/com/sun/jna/platform/mac/SystemBTest.java +++ b/contrib/platform/test/com/sun/jna/platform/mac/SystemBTest.java @@ -23,6 +23,8 @@ */ package com.sun.jna.platform.mac; +import static org.junit.Assert.assertNotEquals; + import com.sun.jna.Memory; import com.sun.jna.Native; import com.sun.jna.Platform; @@ -30,14 +32,12 @@ import com.sun.jna.platform.mac.SystemB.Group; import com.sun.jna.platform.mac.SystemB.HostCpuLoadInfo; import com.sun.jna.platform.mac.SystemB.HostLoadInfo; -import com.sun.jna.platform.mac.SystemB.HostPort; import com.sun.jna.platform.mac.SystemB.IFmsgHdr; import com.sun.jna.platform.mac.SystemB.IFmsgHdr2; import com.sun.jna.platform.mac.SystemB.Passwd; import com.sun.jna.platform.mac.SystemB.ProcTaskAllInfo; import com.sun.jna.platform.mac.SystemB.RUsageInfoV2; import com.sun.jna.platform.mac.SystemB.Statfs; -import com.sun.jna.platform.mac.SystemB.TaskPort; import com.sun.jna.platform.mac.SystemB.Timeval; import com.sun.jna.platform.mac.SystemB.Timezone; import com.sun.jna.platform.mac.SystemB.VMMeter; @@ -54,10 +54,7 @@ /** * Exercise the {@link SystemB} class. - * - * @author widdis@gmail.com */ -// @SuppressWarnings("unused") public class SystemBTest extends TestCase { public void testSysctl() { @@ -95,8 +92,8 @@ public void testSysctl() { } public void testHostPageSize() { - HostPort hostPort = SystemB.INSTANCE.mach_host_self_ptr(); - assertNotNull(hostPort); + int hostPort = SystemB.INSTANCE.mach_host_self(); + assertNotEquals(0, hostPort); LongByReference pPageSize = new LongByReference(); int ret = SystemB.INSTANCE.host_page_size(hostPort, pPageSize); @@ -107,8 +104,8 @@ public void testHostPageSize() { } public void testVMInfo() { - HostPort hostPort = SystemB.INSTANCE.mach_host_self_ptr(); - assertNotNull(hostPort); + int hostPort = SystemB.INSTANCE.mach_host_self(); + assertNotEquals(0, hostPort); VMStatistics vmStats = new VMStatistics(); int ret = SystemB.INSTANCE.host_statistics(hostPort, SystemB.HOST_VM_INFO, vmStats, @@ -128,8 +125,8 @@ public void testVMInfo() { } public void testCpuLoad() { - HostPort hostPort = SystemB.INSTANCE.mach_host_self_ptr(); - assertNotNull(hostPort); + int hostPort = SystemB.INSTANCE.mach_host_self(); + assertNotEquals(0, hostPort); HostCpuLoadInfo cpuLoadInfo = new HostCpuLoadInfo(); int ret = SystemB.INSTANCE.host_statistics(hostPort, SystemB.HOST_CPU_LOAD_INFO, cpuLoadInfo, @@ -140,8 +137,8 @@ public void testCpuLoad() { } public void testHostLoad() { - HostPort hostPort = SystemB.INSTANCE.mach_host_self_ptr(); - assertNotNull(hostPort); + int hostPort = SystemB.INSTANCE.mach_host_self(); + assertNotEquals(0, hostPort); HostLoadInfo hostLoadInfo = new HostLoadInfo(); int ret = SystemB.INSTANCE.host_statistics(hostPort, SystemB.HOST_CPU_LOAD_INFO, hostLoadInfo, @@ -155,8 +152,8 @@ public void testHostLoad() { } public void testHostProcessorInfo() { - HostPort hostPort = SystemB.INSTANCE.mach_host_self_ptr(); - assertNotNull(hostPort); + int hostPort = SystemB.INSTANCE.mach_host_self(); + assertNotEquals(0, hostPort); IntByReference procCount = new IntByReference(); PointerByReference procCpuLoadInfo = new PointerByReference(); @@ -170,14 +167,6 @@ public void testHostProcessorInfo() { procInfoCount.getValue()); } - public void testMachPorts() { - HostPort hostPort = SystemB.INSTANCE.mach_host_self_ptr(); - assertNotNull(hostPort); - assertEquals(Pointer.nativeValue(hostPort.getPointer()) & 0xffffffff, hostPort.castToName().intValue()); - TaskPort taskPort = SystemB.INSTANCE.mach_task_self_ptr(); - assertNotNull(taskPort); - } - public void testGetLoadAvg() { double[] loadavg = new double[3]; int retval = SystemB.INSTANCE.getloadavg(loadavg, 3); @@ -206,8 +195,8 @@ public void testTimeofDay() { } public void testVMMeter() { - HostPort hostPort = SystemB.INSTANCE.mach_host_self_ptr(); - assertNotNull(hostPort); + int hostPort = SystemB.INSTANCE.mach_host_self(); + assertNotEquals(0, hostPort); VMMeter vmstats = new VMMeter(); assertEquals(0, SystemB.INSTANCE.host_statistics(hostPort, SystemB.HOST_VM_INFO, vmstats, new IntByReference(vmstats.size())));