Skip to content

Commit 114fca1

Browse files
committed
Mach ports back to 32-bit ints
1 parent 6c9a8c0 commit 114fca1

File tree

7 files changed

+62
-318
lines changed

7 files changed

+62
-318
lines changed

contrib/platform/src/com/sun/jna/platform/mac/IOKit.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
import com.sun.jna.platform.mac.CoreFoundation.CFMutableDictionaryRef;
3535
import com.sun.jna.platform.mac.CoreFoundation.CFStringRef;
3636
import com.sun.jna.platform.mac.CoreFoundation.CFTypeRef;
37-
import com.sun.jna.platform.mac.SystemB.MachPort;
38-
import com.sun.jna.platform.mac.SystemB.TaskPort;
3937
import com.sun.jna.ptr.IntByReference;
4038
import com.sun.jna.ptr.LongByReference;
4139
import com.sun.jna.ptr.PointerByReference;
@@ -159,16 +157,17 @@ public IOConnect(Pointer p) {
159157
* Returns the mach port used to initiate communication with IOKit.
160158
*
161159
* @param bootstrapPort
162-
* Pass {@link SystemB#MACH_PORT_NULL} for the default.
163-
* @param masterPort
160+
* Pass 0 for the default.
161+
* @param port
164162
* A pointer to the master port is returned. Multiple calls to
165163
* IOMasterPort will not result in leaking ports (each call to
166164
* IOMasterPort adds another send right to the port) but it is
167165
* considered good programming practice to deallocate the port when
168-
* you are finished with it using {@link #IOObjectRelease}
166+
* you are finished with it using
167+
* {@link SystemB#mach_port_deallocate}.
169168
* @return 0 if successful, otherwise a {@code kern_return_t} error code.
170169
*/
171-
int IOMasterPort(MachPort bootstrapPort, PointerByReference masterPort);
170+
int IOMasterPort(int bootstrapPort, IntByReference port);
172171

173172
/**
174173
* Create a matching dictionary that specifies an {@code IOService} class match.
@@ -219,7 +218,7 @@ public IOConnect(Pointer p) {
219218
* otherwise it should be released with {@link CoreFoundation#CFRelease}
220219
* by the caller.
221220
*/
222-
CFMutableDictionaryRef IOBSDNameMatching(MachPort masterPort, int options, String bsdName);
221+
CFMutableDictionaryRef IOBSDNameMatching(int masterPort, int options, String bsdName);
223222

224223
/**
225224
* Look up a registered IOService object that matches a matching dictionary.
@@ -236,7 +235,7 @@ public IOConnect(Pointer p) {
236235
* <p>
237236
* The service must be released by the caller.
238237
*/
239-
IOService IOServiceGetMatchingService(MachPort masterPort, CFDictionaryRef matchingDictionary);
238+
IOService IOServiceGetMatchingService(int masterPort, CFDictionaryRef matchingDictionary);
240239

241240
/**
242241
* Look up registered IOService objects that match a matching dictionary.
@@ -254,7 +253,7 @@ public IOConnect(Pointer p) {
254253
* by the caller when the iteration is finished.
255254
* @return 0 if successful, otherwise a {@code kern_return_t} error code.
256255
*/
257-
int IOServiceGetMatchingServices(MachPort masterPort, CFDictionaryRef matchingDictionary,
256+
int IOServiceGetMatchingServices(int masterPort, CFDictionaryRef matchingDictionary,
258257
PointerByReference iterator);
259258

260259
/**
@@ -404,7 +403,7 @@ CFTypeRef IORegistryEntrySearchCFProperty(IORegistryEntry entry, String plane, C
404403
* @return A handle to the IORegistryEntry root instance, to be released with
405404
* {@link #IOObjectRelease} by the caller, or 0 on failure.
406405
*/
407-
IORegistryEntry IORegistryGetRootEntry(MachPort masterPort);
406+
IORegistryEntry IORegistryGetRootEntry(int masterPort);
408407

409408
/**
410409
* Performs an OSDynamicCast operation on an IOKit object.
@@ -444,7 +443,7 @@ CFTypeRef IORegistryEntrySearchCFProperty(IORegistryEntry entry, String plane, C
444443
* {@link IOServiceClose}.
445444
* @return A return code generated by {@code IOService::newUserClient}.
446445
*/
447-
int IOServiceOpen(IOService service, TaskPort owningTask, int type, PointerByReference connect);
446+
int IOServiceOpen(IOService service, int owningTask, int type, PointerByReference connect);
448447

449448
/**
450449
* Returns the busyState of an IOService.

contrib/platform/src/com/sun/jna/platform/mac/IOKitUtil.java

+15-14
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import com.sun.jna.platform.mac.IOKit.IOIterator;
3636
import com.sun.jna.platform.mac.IOKit.IORegistryEntry;
3737
import com.sun.jna.platform.mac.IOKit.IOService;
38-
import com.sun.jna.platform.mac.SystemB.MachPort;
38+
import com.sun.jna.ptr.IntByReference;
3939
import com.sun.jna.ptr.PointerByReference;
4040

4141
/**
@@ -44,6 +44,7 @@
4444
public class IOKitUtil {
4545
private static final IOKit IO = IOKit.INSTANCE;
4646
private static final CoreFoundation CF = CoreFoundation.INSTANCE;
47+
private static final SystemB SYS = SystemB.INSTANCE;
4748

4849
private IOKitUtil() {
4950
}
@@ -57,12 +58,12 @@ private IOKitUtil() {
5758
* ports (each call to {@link IOKit#IOMasterPort} adds another send
5859
* right to the port) but it is considered good programming practice to
5960
* deallocate the port when you are finished with it, using
60-
* {@link SystemB#mach_port_deallocate}.
61+
* {@link IOKit#IOObjectRelease}.
6162
*/
62-
public static MachPort getMasterPort() {
63-
PointerByReference port = new PointerByReference();
64-
IO.IOMasterPort(SystemB.MACH_PORT_NULL, port);
65-
return new MachPort(port.getValue());
63+
public static int getMasterPort() {
64+
IntByReference port = new IntByReference();
65+
IO.IOMasterPort(0, port);
66+
return port.getValue();
6667
}
6768

6869
/**
@@ -72,9 +73,9 @@ public static MachPort getMasterPort() {
7273
* {@link IOKit#IOObjectRelease}.
7374
*/
7475
public static IORegistryEntry getRoot() {
75-
MachPort masterPort = getMasterPort();
76+
int masterPort = getMasterPort();
7677
IORegistryEntry root = IO.IORegistryGetRootEntry(masterPort);
77-
masterPort.deallocate();
78+
SYS.mach_port_deallocate(SYS.mach_task_self(), masterPort);
7879
return root;
7980
}
8081

@@ -106,9 +107,9 @@ public static IOService getMatchingService(String serviceName) {
106107
* {@link IOKit#IOObjectRelease}.
107108
*/
108109
public static IOService getMatchingService(CFDictionaryRef matchingDictionary) {
109-
MachPort masterPort = getMasterPort();
110+
int masterPort = getMasterPort();
110111
IOService service = IO.IOServiceGetMatchingService(masterPort, matchingDictionary);
111-
masterPort.deallocate();
112+
SYS.mach_port_deallocate(SYS.mach_task_self(), masterPort);
112113
return service;
113114
}
114115

@@ -140,10 +141,10 @@ public static IOIterator getMatchingServices(String serviceName) {
140141
* {@link IOKit#IOObjectRelease}.
141142
*/
142143
public static IOIterator getMatchingServices(CFDictionaryRef matchingDictionary) {
143-
MachPort masterPort = getMasterPort();
144+
int masterPort = getMasterPort();
144145
PointerByReference serviceIterator = new PointerByReference();
145146
int result = IO.IOServiceGetMatchingServices(masterPort, matchingDictionary, serviceIterator);
146-
masterPort.deallocate();
147+
SYS.mach_port_deallocate(SYS.mach_task_self(), masterPort);
147148
if (result == 0 && serviceIterator.getValue() != null) {
148149
return new IOIterator(serviceIterator.getValue());
149150
}
@@ -159,9 +160,9 @@ public static IOIterator getMatchingServices(CFDictionaryRef matchingDictionary)
159160
* should release when finished, using {@link IOKit#IOObjectRelease}.
160161
*/
161162
public static CFMutableDictionaryRef getBSDNameMatchingDict(String bsdName) {
162-
MachPort masterPort = getMasterPort();
163+
int masterPort = getMasterPort();
163164
CFMutableDictionaryRef result = IO.IOBSDNameMatching(masterPort, 0, bsdName);
164-
masterPort.deallocate();
165+
SYS.mach_port_deallocate(SYS.mach_task_self(), masterPort);
165166
return result;
166167
}
167168

0 commit comments

Comments
 (0)