| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | /*============================================================ |
| 6 | ** |
| 7 | ** Source: test1.c |
| 8 | ** |
| 9 | ** Purpose: Tests that FlushInstructionCache returns the correct value for a |
| 10 | ** number of different inputs. |
| 11 | ** |
| 12 | ** |
| 13 | ** Note : |
| 14 | ** For this function, what constitutes "invalid parameters" will depend entirely |
| 15 | ** on the platform; because of this we can't simply test values on Windows and |
| 16 | ** then ask for the same results everywhere. Because of this, this test can |
| 17 | ** ensure that the function succeeds for some "obviously" valid values, but |
| 18 | ** can't make sure that it fails for invalid values. |
| 19 | ** |
| 20 | **=========================================================*/ |
| 21 | |
| 22 | #include <palsuite.h> |
| 23 | |
| 24 | void DoTest(void *Buffer, int Size, int Expected) |
| 25 | { |
| 26 | int ret; |
| 27 | |
| 28 | SetLastError(0); |
| 29 | ret = FlushInstructionCache(GetCurrentProcess(), Buffer, Size); |
| 30 | if (!ret && Expected) |
| 31 | { |
| 32 | Fail("Expected FlushInstructionCache to return non-zero, got zero!\n" |
| 33 | "region: %p, size: %d, GetLastError: %d\n" , Buffer, Size, |
| 34 | GetLastError()); |
| 35 | } |
| 36 | else if (ret && !Expected) |
| 37 | { |
| 38 | Fail("Expected FlushInstructionCache to return zero, got non-zero!\n" |
| 39 | "region: %p, size: %d, GetLastError: %d\n" , Buffer, Size, |
| 40 | GetLastError()); |
| 41 | } |
| 42 | |
| 43 | if (!Expected && ERROR_NOACCESS != GetLastError()) |
| 44 | { |
| 45 | Fail("FlushInstructionCache failed to set the last error to " |
| 46 | "ERROR_NOACCESS!\n" ); |
| 47 | } |
| 48 | |
| 49 | } |
| 50 | |
| 51 | int __cdecl main(int argc,char *argv[]) |
| 52 | { |
| 53 | char ValidPtr[256]; |
| 54 | |
| 55 | if(PAL_Initialize(argc, argv)) |
| 56 | { |
| 57 | return FAIL; |
| 58 | } |
| 59 | |
| 60 | /* with valid pointer, zero-size and valid size must succeed */ |
| 61 | DoTest(ValidPtr, 0, 1); |
| 62 | DoTest(ValidPtr, 42, 1); |
| 63 | |
| 64 | PAL_Terminate(); |
| 65 | return PASS; |
| 66 | } |
| 67 | |