Skip to content

Commit

Permalink
UserClient: Support large message blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
flagersgit committed Oct 5, 2022
1 parent 79c3992 commit 4ac2471
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
32 changes: 20 additions & 12 deletions MacHyperVSupport/Controller/HyperVUserClient.cpp
Expand Up @@ -41,12 +41,12 @@ bool HyperVUserClient::start(IOService *provider) {
//
// Populate notification message info.
//
_notificationMsg.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
_notificationMsg.header.msgh_size = sizeof (_notificationMsg);
_notificationMsg.header.msgh_remote_port = MACH_PORT_NULL;
_notificationMsg.header.msgh_local_port = MACH_PORT_NULL;
_notificationMsg.header.msgh_reserved = 0;
_notificationMsg.header.msgh_id = 0;
_notificationMsg.standard.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
_notificationMsg.standard.header.msgh_size = sizeof (_notificationMsg.standard);
_notificationMsg.standard.header.msgh_remote_port = MACH_PORT_NULL;
_notificationMsg.standard.header.msgh_local_port = MACH_PORT_NULL;
_notificationMsg.standard.header.msgh_reserved = 0;
_notificationMsg.standard.header.msgh_id = 0;

HVDBGLOG("Initialized Hyper-V user client");
return true;
Expand Down Expand Up @@ -91,19 +91,27 @@ IOReturn HyperVUserClient::registerNotificationPort(mach_port_t port, UInt32 typ
}

HVDBGLOG("Registering notification port 0x%p", port);
_notificationMsg.header.msgh_remote_port = port;
_notificationMsg.standard.header.msgh_remote_port = port;
return kIOReturnSuccess;
}

IOReturn HyperVUserClient::notifyClientApplication(HyperVUserClientNotificationType type, void *data, UInt32 dataLength) {
if (dataLength > sizeof (_notificationMsg.data)) {
if (dataLength > sizeof (_notificationMsg.large.data)) {
return kIOReturnMessageTooLarge;
}

HVDBGLOG("Sending notification type %u with %u bytes of data", type, dataLength);
_notificationMsg.type = type;
memcpy(_notificationMsg.data, data, dataLength);
_notificationMsg.dataLength = dataLength;
_notificationMsg.standard.type = type;
memcpy(_notificationMsg.standard.data, data, dataLength);

if (dataLength > sizeof (_notificationMsg.standard.data)) {
_notificationMsg.standard.header.msgh_size = sizeof (_notificationMsg.large.data);
_notificationMsg.large.dataLength = dataLength;
} else {
_notificationMsg.standard.header.msgh_size = sizeof (_notificationMsg.standard.data);
_notificationMsg.standard.dataLength = dataLength;
}


return mach_msg_send_from_kernel(&_notificationMsg.header, _notificationMsg.header.msgh_size);
return mach_msg_send_from_kernel(&_notificationMsg.standard.header, _notificationMsg.standard.header.msgh_size);
}
28 changes: 21 additions & 7 deletions MacHyperVSupport/Controller/HyperVUserClient.h
Expand Up @@ -11,7 +11,8 @@
#include <libkern/OSTypes.h>
#include <mach/message.h>

#define kHyperVUserClientNotificationMessageDataLength 64
#define kHyperVUserClientNotificationMessageDataStandardLength 64
#define kHyperVUserClientNotificationMessageDataLargeLength (kHyperVUserClientNotificationMessageDataStandardLength + (6 * 1024))

typedef enum : UInt32 {
kHyperVUserClientNotificationTypePerformShutdown = 0x66697368,
Expand All @@ -24,15 +25,28 @@ typedef struct {
UInt32 microseconds;
} HyperVUserClientTimeData;

typedef struct {
mach_msg_header_t header;
HyperVUserClientNotificationType type;
UInt8 data[kHyperVUserClientNotificationMessageDataLength];
UInt32 dataLength;

typedef union {
struct {
mach_msg_header_t header;
HyperVUserClientNotificationType type;
UInt8 data[kHyperVUserClientNotificationMessageDataStandardLength];
UInt32 dataLength;

#ifndef KERNEL
mach_msg_trailer_t trailer;
#endif
} standard;
struct {
mach_msg_header_t header;
HyperVUserClientNotificationType type;
UInt8 data[kHyperVUserClientNotificationMessageDataLargeLength];
UInt32 dataLength;

#ifndef KERNEL
mach_msg_trailer_t trailer;
mach_msg_trailer_t trailer;
#endif
} large;
} HyperVUserClientNotificationMessage;

#endif

0 comments on commit 4ac2471

Please sign in to comment.