From: VMware, Inc <> Date: Fri, 12 Apr 2013 19:58:20 +0000 (-0700) Subject: HGFS: clean up the transport channel callbacks from the HGFS server X-Git-Tag: 2013.04.16-1098359~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=801a2326a8f531990da0f791007c0fbb4c34cd93;p=thirdparty%2Fopen-vm-tools.git HGFS: clean up the transport channel callbacks from the HGFS server The transport channel callbacks for the HGFS packet request-reply to read, write and release the memory use badly defined arguments. It uses character pointer and calls it a token. The type is simply just wrong and should be treated as an opaque type owned and manipulated only by the channel transport. Secondly, it is really a context although it is a token, it could be anything the channel chooses and could change in the future. This change fixes these issues to be a void *context. This shows that the type and meaning are not to be exposed beyond the owner of object which is the channel in this case. Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/lib/hgfsServer/hgfsServerPacketUtil.c b/open-vm-tools/lib/hgfsServer/hgfsServerPacketUtil.c index 925455b31..1993b6912 100644 --- a/open-vm-tools/lib/hgfsServer/hgfsServerPacketUtil.c +++ b/open-vm-tools/lib/hgfsServer/hgfsServerPacketUtil.c @@ -215,7 +215,8 @@ HSPU_GetBuf(HgfsPacket *packet, // IN/OUT: Hgfs Packet uint32 iovMapped = 0; int32 size = bufSize; int i; - void* (*func)(uint64, uint32, char **); + HgfsChannelMapVirtAddrFunc getVa; + ASSERT(buf); if (*buf) { @@ -230,14 +231,14 @@ HSPU_GetBuf(HgfsPacket *packet, // IN/OUT: Hgfs Packet if (mappingType == BUF_WRITEABLE || mappingType == BUF_READWRITEABLE) { - func = transportSession->channelCbTable->getWriteVa; + getVa = transportSession->channelCbTable->getWriteVa; } else { ASSERT(mappingType == BUF_READABLE); - func = transportSession->channelCbTable->getReadVa; + getVa = transportSession->channelCbTable->getReadVa; } /* Looks like we are in the middle of poweroff. */ - if (func == NULL) { + if (getVa == NULL) { return NULL; } @@ -245,15 +246,15 @@ HSPU_GetBuf(HgfsPacket *packet, // IN/OUT: Hgfs Packet for (iovCount = startIndex; iovCount < packet->iovCount && size > 0; iovCount++) { - packet->iov[iovCount].token = NULL; + packet->iov[iovCount].context = NULL; /* Debugging check: Iov in VMCI should never cross page boundary */ ASSERT_DEVEL(packet->iov[iovCount].len <= (PAGE_SIZE - PAGE_OFFSET(packet->iov[iovCount].pa))); - packet->iov[iovCount].va = func(packet->iov[iovCount].pa, - packet->iov[iovCount].len, - &packet->iov[iovCount].token); + packet->iov[iovCount].va = getVa(packet->iov[iovCount].pa, + packet->iov[iovCount].len, + &packet->iov[iovCount].context); ASSERT_DEVEL(packet->iov[iovCount].va); if (packet->iov[iovCount].va == NULL) { /* Guest probably passed us bad physical address */ @@ -302,7 +303,7 @@ HSPU_GetBuf(HgfsPacket *packet, // IN/OUT: Hgfs Packet freeMem: for (i = startIndex; i < iovCount; i++) { - transportSession->channelCbTable->putVa(&packet->iov[i].token); + transportSession->channelCbTable->putVa(&packet->iov[i].context); packet->iov[i].va = NULL; } @@ -436,8 +437,8 @@ HSPU_PutBuf(HgfsPacket *packet, // IN/OUT: Hgfs Packet for (iovCount = startIndex; iovCount < packet->iovCount && size > 0; iovCount++) { - ASSERT_DEVEL(packet->iov[iovCount].token); - transportSession->channelCbTable->putVa(&packet->iov[iovCount].token); + ASSERT_DEVEL(packet->iov[iovCount].context); + transportSession->channelCbTable->putVa(&packet->iov[iovCount].context); size -= packet->iov[iovCount].len; } LOG(10, ("%s: Hgfs bufSize = %d \n", __FUNCTION__, size)); @@ -542,19 +543,20 @@ HSPU_CopyBufToIovec(HgfsPacket *packet, // IN/OUT: Hgfs Packet copyAmount = remainingSize < packet->iov[iovCount].len ? remainingSize: packet->iov[iovCount].len; - packet->iov[iovCount].token = NULL; + packet->iov[iovCount].context = NULL; /* Debugging check: Iov in VMCI should never cross page boundary */ ASSERT_DEVEL(packet->iov[iovCount].len <= (PAGE_SIZE - PAGE_OFFSET(packet->iov[iovCount].pa))); - packet->iov[iovCount].va = transportSession->channelCbTable->getWriteVa(packet->iov[iovCount].pa, - packet->iov[iovCount].len, - &packet->iov[iovCount].token); + packet->iov[iovCount].va = + transportSession->channelCbTable->getWriteVa(packet->iov[iovCount].pa, + packet->iov[iovCount].len, + &packet->iov[iovCount].context); ASSERT_DEVEL(packet->iov[iovCount].va); if (packet->iov[iovCount].va != NULL) { memcpy(packet->iov[iovCount].va, (char *)buf + copiedAmount, copyAmount); - transportSession->channelCbTable->putVa(&packet->iov[iovCount].token); + transportSession->channelCbTable->putVa(&packet->iov[iovCount].context); remainingSize -= copyAmount; copiedAmount += copyAmount; } else { diff --git a/open-vm-tools/lib/include/hgfsServer.h b/open-vm-tools/lib/include/hgfsServer.h index 3b221c076..0786e133c 100644 --- a/open-vm-tools/lib/include/hgfsServer.h +++ b/open-vm-tools/lib/include/hgfsServer.h @@ -40,7 +40,7 @@ struct HgfsVmxIov { void *va; /* Virtual addr */ uint64 pa; /* Physical address passed by the guest */ uint32 len; /* length of data; should be <= PAGE_SIZE for VMCI; arbitrary for backdoor */ - char *token; /* Token for physMem_ APIs */ + void *context; /* Mapping context */ } HgfsVmxIov; typedef enum { @@ -116,11 +116,6 @@ typedef struct HgfsServerChannelData { uint32 maxPacketSize; }HgfsServerChannelData; -typedef Bool -HgfsSessionSendFunc(void *opaqueSession, // IN - char *buffer, // IN - size_t bufferLen, // IN - HgfsSendFlags flags); // IN /* Default maximum number of open nodes. */ #define HGFS_MAX_CACHED_FILENODES 30 @@ -137,12 +132,19 @@ typedef struct HgfsServerConfig { uint32 maxCachedOpenNodes; }HgfsServerConfig; +typedef Bool (*HgfsChannelSendFunc)(void *opaqueSession, + HgfsPacket *packet, + char *buffer, + size_t bufferLen, + HgfsSendFlags flags); +typedef void * (*HgfsChannelMapVirtAddrFunc)(uint64 pa, uint32 size, void **context); +typedef void (*HgfsChannelUnmapVirtAddrFunc)(void **context); + typedef struct HgfsServerChannelCallbacks { - void* (*getReadVa)(uint64 pa, uint32 size, char **token); - void* (*getWriteVa)(uint64 pa, uint32 size, char **token); - void (*putVa)(char **token); - Bool (*send)(void *opaqueSession, HgfsPacket *packet, char *buffer, - size_t bufferLen, HgfsSendFlags flags); + HgfsChannelMapVirtAddrFunc getReadVa; + HgfsChannelMapVirtAddrFunc getWriteVa; + HgfsChannelUnmapVirtAddrFunc putVa; + HgfsChannelSendFunc send; }HgfsServerChannelCallbacks; typedef struct HgfsServerSessionCallbacks {