Skip to content

Commit b22f3f0

Browse files
Fix for handling incorrect patchSize in patchWithRequiredSize
This fix adds additional size control to patched memory Related-To: NEO-7760 Signed-off-by: Andrzej Koska <[email protected]>
1 parent 83e9a14 commit b22f3f0

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

opencl/test/unit_test/command_queue/enqueue_handler_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ HWTEST_F(EnqueueHandlerTest, givenKernelUsingSyncBufferWhenEnqueuingKernelThenSs
689689

690690
{
691691
MockKernelWithInternals kernelInternals{*pClDevice, context};
692-
kernelInternals.kernelInfo.setSyncBuffer(sizeof(uint8_t), 0, 0);
692+
kernelInternals.kernelInfo.setSyncBuffer(sizeof(uint32_t), 0, 0);
693693
constexpr auto bindingTableOffset = sizeof(RENDER_SURFACE_STATE);
694694
kernelInternals.kernelInfo.setBindingTable(bindingTableOffset, 1);
695695
kernelInternals.kernelInfo.heapInfo.SurfaceStateHeapSize = sizeof(RENDER_SURFACE_STATE) + sizeof(BINDING_TABLE_STATE);

opencl/test/unit_test/command_queue/sync_buffer_handler_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class SyncBufferHandlerTest : public SyncBufferEnqueueHandlerTest {
8888
}
8989

9090
void patchAllocateSyncBuffer() {
91-
kernelInternals->kernelInfo.setSyncBuffer(sizeof(uint8_t), 0, 0);
91+
kernelInternals->kernelInfo.setSyncBuffer(sizeof(uint32_t), 0, 0);
9292
}
9393

9494
MockSyncBufferHandler *getSyncBufferHandler() {

shared/source/helpers/ptr_math.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/*
2-
* Copyright (C) 2018-2022 Intel Corporation
2+
* Copyright (C) 2018-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
66
*/
77

88
#pragma once
9+
#include "shared/source/helpers/debug_helpers.h"
10+
911
#include <cstddef>
1012
#include <cstdint>
1113

@@ -58,9 +60,11 @@ inline void patchWithRequiredSize(void *memoryToBePatched, uint32_t patchSize, u
5860
if (patchSize == sizeof(uint64_t)) {
5961
uint64_t *curbeAddress = reinterpret_cast<uint64_t *>(memoryToBePatched);
6062
PatchStoreOperation{}(curbeAddress, patchValue);
61-
} else {
63+
} else if (patchSize == sizeof(uint32_t)) {
6264
uint32_t *curbeAddress = reinterpret_cast<uint32_t *>(memoryToBePatched);
6365
PatchStoreOperation{}(curbeAddress, static_cast<uint32_t>(patchValue));
66+
} else {
67+
UNRECOVERABLE_IF(patchSize != 0);
6468
}
6569
}
6670

shared/test/unit_test/helpers/ptr_math_tests.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -53,6 +53,17 @@ TEST(PtrMath, givenCastToUint64FunctionWhenConstPointerIsPassedItIsCalledThenPro
5353
EXPECT_EQ(uintAddress, expectedUint64Address);
5454
}
5555

56+
TEST(PtrMath, givenPatchWithRequiredSizeFunctionThenProperMemoryToBePatchedIsSet) {
57+
uint64_t memoryToBePatched = 0;
58+
patchWithRequiredSize(&memoryToBePatched, 8, 0xaaaaaaaaaaaaaaaa);
59+
EXPECT_EQ(memoryToBePatched, 0xaaaaaaaaaaaaaaaa);
60+
patchWithRequiredSize(&memoryToBePatched, 4, 0xbbbbbbbbbbbbbbbb);
61+
EXPECT_EQ(memoryToBePatched, 0xaaaaaaaabbbbbbbb);
62+
patchWithRequiredSize(&memoryToBePatched, 0, 0xcccccccccccccccc);
63+
EXPECT_EQ(memoryToBePatched, 0xaaaaaaaabbbbbbbb);
64+
EXPECT_THROW(patchWithRequiredSize(&memoryToBePatched, 1, 0xcccccccccccccccc), std::exception);
65+
}
66+
5667
TEST(ptrOffset, WhenGettingPtrOffsetThen64BitIsPreserved) {
5768
uint64_t ptrBefore = 0x800000000;
5869
size_t offset = 0x1234;

0 commit comments

Comments
 (0)