Skip to content

Commit cd6cda5

Browse files
committed
Initial commit
0 parents  commit cd6cda5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+6840
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
DerivedData
3+
xcuserdata
4+
project.xcworkspace
5+
build
6+
xcshareddata
7+
/MacKernelSDK

MacHyperVSupport.xcodeproj/project.pbxproj

+509
Large diffs are not rendered by default.

MacHyperVSupport/Info.plist

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>$(MARKETING_VERSION)</string>
19+
<key>CFBundleVersion</key>
20+
<string>$(CURRENT_PROJECT_VERSION)</string>
21+
<key>IOKitPersonalities</key>
22+
<dict>
23+
<key>HyperVHeartbeat</key>
24+
<dict>
25+
<key>CFBundleIdentifier</key>
26+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
27+
<key>IOClass</key>
28+
<string>HyperVHeartbeat</string>
29+
<key>IOPropertyMatch</key>
30+
<dict>
31+
<key>HVType</key>
32+
<string>57164f39-9115-4e78-ab55-382f3bd5422d</string>
33+
</dict>
34+
<key>IOProviderClass</key>
35+
<string>HyperVVMBusDevice</string>
36+
</dict>
37+
<key>HyperVKeyboard</key>
38+
<dict>
39+
<key>CFBundleIdentifier</key>
40+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
41+
<key>IOClass</key>
42+
<string>HyperVKeyboard</string>
43+
<key>IOPropertyMatch</key>
44+
<dict>
45+
<key>HVType</key>
46+
<string>f912ad6d-2b17-48ea-bd65-f927a61c7684</string>
47+
</dict>
48+
<key>IOProviderClass</key>
49+
<string>HyperVVMBusDevice</string>
50+
</dict>
51+
<key>HyperVMouse</key>
52+
<dict>
53+
<key>CFBundleIdentifier</key>
54+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
55+
<key>IOClass</key>
56+
<string>HyperVMouse</string>
57+
<key>IOPropertyMatch</key>
58+
<dict>
59+
<key>HVType</key>
60+
<string>cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a</string>
61+
</dict>
62+
<key>IOProviderClass</key>
63+
<string>HyperVVMBusDevice</string>
64+
</dict>
65+
<key>HyperVShutdown</key>
66+
<dict>
67+
<key>CFBundleIdentifier</key>
68+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
69+
<key>IOClass</key>
70+
<string>HyperVShutdown</string>
71+
<key>IOPropertyMatch</key>
72+
<dict>
73+
<key>DisabledHVType</key>
74+
<string>0e0b6031-5213-4934-818b-38d90ced39db</string>
75+
</dict>
76+
<key>IOProviderClass</key>
77+
<string>HyperVVMBusDevice</string>
78+
</dict>
79+
<key>HyperVStorage</key>
80+
<dict>
81+
<key>CFBundleIdentifier</key>
82+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
83+
<key>IOClass</key>
84+
<string>HyperVStorage</string>
85+
<key>IOPropertyMatch</key>
86+
<dict>
87+
<key>HVType</key>
88+
<string>ba6163d9-04a1-4d29-b605-72e2ffb1dc7f</string>
89+
</dict>
90+
<key>IOProviderClass</key>
91+
<string>HyperVVMBusDevice</string>
92+
<key>Protocol Characteristics</key>
93+
<dict>
94+
<key>Physical Interconnect</key>
95+
<string>SCSI Parallel Interface</string>
96+
<key>Physical Interconnect Location</key>
97+
<string>Internal</string>
98+
</dict>
99+
</dict>
100+
<key>HyperVVMBusController</key>
101+
<dict>
102+
<key>CFBundleIdentifier</key>
103+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
104+
<key>IOClass</key>
105+
<string>HyperVVMBusController</string>
106+
<key>IONameMatch</key>
107+
<string>VMBS</string>
108+
<key>IOProviderClass</key>
109+
<string>IOACPIPlatformDevice</string>
110+
</dict>
111+
</dict>
112+
<key>NSHumanReadableCopyright</key>
113+
<string>Copyright © 2021 Goldfish64. All rights reserved.</string>
114+
<key>OSBundleLibraries</key>
115+
<dict>
116+
<key>com.apple.iokit.IOHIDFamily</key>
117+
<string>1.1</string>
118+
<key>com.apple.iokit.IOSCSIParallelFamily</key>
119+
<string>2.0.1</string>
120+
<key>com.apple.kpi.bsd</key>
121+
<string>8.0.0</string>
122+
<key>com.apple.kpi.iokit</key>
123+
<string>8.0.0</string>
124+
<key>com.apple.kpi.libkern</key>
125+
<string>8.0.0</string>
126+
<key>com.apple.kpi.mach</key>
127+
<string>8.0.0</string>
128+
<key>com.apple.kpi.unsupported</key>
129+
<string>8.0.0</string>
130+
</dict>
131+
<key>OSBundleRequired</key>
132+
<string>Root</string>
133+
</dict>
134+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//
2+
// HyperVHeartbeat.cpp
3+
// Hyper-V heartbeat driver
4+
//
5+
// Copyright © 2021 Goldfish64. All rights reserved.
6+
//
7+
8+
#include "HyperVHeartbeat.hpp"
9+
10+
#include <IOKit/IOPlatformExpert.h>
11+
12+
#define super HyperVICService
13+
14+
#define SYSLOG(str, ...) SYSLOG_PRINT("HyperVHeartbeat", str, ## __VA_ARGS__)
15+
#define DBGLOG(str, ...) DBGLOG_PRINT("HyperVHeartbeat", str, ## __VA_ARGS__)
16+
17+
OSDefineMetaClassAndStructors(HyperVHeartbeat, super);
18+
19+
bool HyperVHeartbeat::start(IOService *provider) {
20+
DBGLOG("Initializing Hyper-V Heartbeat");
21+
return super::start(provider);
22+
}
23+
24+
void HyperVHeartbeat::processMessage() {
25+
VMBusICMessageHeartbeat heartbeatMsg;
26+
27+
HyperVVMBusDeviceRequest request = { 0 };
28+
request.responseData = &heartbeatMsg;
29+
request.responseDataLength = sizeof (heartbeatMsg);
30+
31+
//
32+
// Ignore errors and the acknowledgement interrupt (no data to read).
33+
//
34+
if (hvDevice->doRequest(&request) != kIOReturnSuccess || request.responseDataLength == 0) {
35+
return;
36+
}
37+
38+
switch (heartbeatMsg.header.type) {
39+
case kVMBusICMessageTypeNegotiate:
40+
firstHeartbeatReceived = false;
41+
createNegotiationResponse(&heartbeatMsg.negotiate, 3, 3);
42+
break;
43+
44+
case kVMBusICMessageTypeHeartbeat:
45+
//
46+
// Increment sequence.
47+
// Host will increment this further before sending a message back.
48+
//
49+
//DBGLOG("Got heartbeat, seq = %u", heartbeatMsg.heartbeat.sequence);
50+
heartbeatMsg.heartbeat.sequence++;
51+
52+
if (!firstHeartbeatReceived) {
53+
firstHeartbeatReceived = true;
54+
SYSLOG("Initialized Hyper-V Heartbeat");
55+
}
56+
break;
57+
58+
default:
59+
DBGLOG("Unknown IC message type %u", heartbeatMsg.header.type);
60+
heartbeatMsg.header.status = kHyperVStatusFail;
61+
break;
62+
}
63+
64+
heartbeatMsg.header.flags = kVMBusICFlagTransaction | kVMBusICFlagResponse;
65+
66+
UInt32 sendLength = request.responseDataLength;
67+
68+
request = { 0 };
69+
request.sendData = &heartbeatMsg;
70+
request.sendDataLength = sendLength;
71+
request.sendPacketType = kVMBusPacketTypeDataInband;
72+
73+
hvDevice->doRequest(&request);
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// HyperVHeartbeat.hpp
3+
// Hyper-V heartbeat driver
4+
//
5+
// Copyright © 2021 Goldfish64. All rights reserved.
6+
//
7+
8+
#ifndef HyperVHeartbeat_hpp
9+
#define HyperVHeartbeat_hpp
10+
11+
#include "HyperVICService.hpp"
12+
13+
class HyperVHeartbeat : public HyperVICService {
14+
OSDeclareDefaultStructors(HyperVHeartbeat);
15+
16+
private:
17+
bool firstHeartbeatReceived;
18+
19+
protected:
20+
void processMessage() APPLE_KEXT_OVERRIDE;
21+
22+
public:
23+
//
24+
// IOService overrides.
25+
//
26+
virtual bool start(IOService *provider) APPLE_KEXT_OVERRIDE;
27+
};
28+
29+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//
2+
// HyperVIC.hpp
3+
// Hyper-V IC base class
4+
//
5+
// Copyright © 2021 Goldfish64. All rights reserved.
6+
//
7+
8+
#ifndef HyperVIC_h
9+
#define HyperVIC_h
10+
11+
//
12+
// Message types.
13+
//
14+
typedef enum : UInt16 {
15+
kVMBusICMessageTypeNegotiate = 0,
16+
kVMBusICMessageTypeHeartbeat = 1,
17+
kVMBusICMessageTypeKVPExchange = 2,
18+
kVMBusICMessageTypeShutdown = 3,
19+
kVMBusICMessageTypeTimeSync = 4,
20+
kVMBusICMessageTypeVSS = 5,
21+
kVMBusICMessageTypeFileCopy = 7
22+
} VMBusICMessageType;
23+
24+
#define kVMBusICFlagTransaction 1
25+
#define kVMBusICFlagRequest 2
26+
#define kVMBusICFlagResponse 4
27+
28+
typedef struct __attribute__((packed)) {
29+
UInt32 pipeFlags;
30+
UInt32 pipeMsgs;
31+
32+
UInt32 frameworkVersion;
33+
VMBusICMessageType type;
34+
UInt32 msgVersion;
35+
UInt16 dataSize;
36+
UInt32 status;
37+
UInt8 transactionId;
38+
UInt8 flags;
39+
UInt16 reserved;
40+
} VMBusICMessageHeader;
41+
42+
typedef struct __attribute__((packed)) {
43+
VMBusICMessageHeader header;
44+
45+
UInt16 frameworkVersionCount;
46+
UInt16 messageVersionCount;
47+
UInt32 reserved;
48+
UInt32 versions[];
49+
} VMBusICMessageNegotiate;
50+
51+
typedef struct __attribute__((packed)) {
52+
VMBusICMessageHeader header;
53+
54+
UInt64 sequence;
55+
UInt32 reserved[8];
56+
} VMBusICMessageHeartbeatSequence;
57+
58+
typedef struct __attribute__((packed)) {
59+
union {
60+
VMBusICMessageHeader header;
61+
VMBusICMessageNegotiate negotiate;
62+
VMBusICMessageHeartbeatSequence heartbeat;
63+
};
64+
} VMBusICMessageHeartbeat;
65+
66+
typedef struct __attribute__((packed)) {
67+
VMBusICMessageHeader header;
68+
69+
UInt32 reason;
70+
UInt32 timeoutSeconds;
71+
UInt32 flags;
72+
char displayMessage[2048];
73+
} VMBusICMessageShutdown;
74+
75+
#endif

0 commit comments

Comments
 (0)