Remove size_t from wire transfer structs

This makes the primitives in the serialized wire protocol
the same across platforms and architectures which is better
for both fuzzing and remoting Dawn.

Commands that used size_t are updated to use uint64_t, and
the server-side implementation checks if conversion to
size_t would narrow.

Bug: dawn:680
Change-Id: Icef9dc11a72699685ed7191c34d6a922b652c887
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/41582
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Austin Eng
2021-02-18 22:36:19 +00:00
committed by Commit Bot service account
parent f0f6d2f8e1
commit f104fea367
4 changed files with 54 additions and 26 deletions

View File

@@ -44,7 +44,7 @@ namespace dawn_wire { namespace server {
ObjectId bufferId,
uint64_t bufferOffset,
const uint8_t* data,
size_t size) {
uint64_t size) {
// The null object isn't valid as `self` or `buffer` so we can combine the check with the
// check that the ID is valid.
auto* queue = QueueObjects().Get(queueId);
@@ -53,14 +53,25 @@ namespace dawn_wire { namespace server {
return false;
}
mProcs.queueWriteBuffer(queue->handle, buffer->handle, bufferOffset, data, size);
if (size > std::numeric_limits<size_t>::max()) {
auto* device = DeviceObjects().Get(queue->deviceInfo->self.id);
if (device == nullptr) {
return false;
}
return DoDeviceInjectError(reinterpret_cast<WGPUDevice>(device),
WGPUErrorType_OutOfMemory,
"Data size too large for write texture.");
}
mProcs.queueWriteBuffer(queue->handle, buffer->handle, bufferOffset, data,
static_cast<size_t>(size));
return true;
}
bool Server::DoQueueWriteTextureInternal(ObjectId queueId,
const WGPUTextureCopyView* destination,
const uint8_t* data,
size_t dataSize,
uint64_t dataSize,
const WGPUTextureDataLayout* dataLayout,
const WGPUExtent3D* writeSize) {
// The null object isn't valid as `self` so we can combine the check with the
@@ -70,7 +81,18 @@ namespace dawn_wire { namespace server {
return false;
}
mProcs.queueWriteTexture(queue->handle, destination, data, dataSize, dataLayout, writeSize);
if (dataSize > std::numeric_limits<size_t>::max()) {
auto* device = DeviceObjects().Get(queue->deviceInfo->self.id);
if (device == nullptr) {
return false;
}
return DoDeviceInjectError(reinterpret_cast<WGPUDevice>(device),
WGPUErrorType_OutOfMemory,
"Data size too large for write texture.");
}
mProcs.queueWriteTexture(queue->handle, destination, data, static_cast<size_t>(dataSize),
dataLayout, writeSize);
return true;
}