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: tls.c |
8 | ** |
9 | ** Purpose: Test to ensure TlsGetValue, TlsSetValue and TlsFree |
10 | ** are not working with an invalid index |
11 | ** |
12 | ** Dependencies: PAL_Initialize |
13 | ** PAL_Terminate |
14 | ** LocalAlloc |
15 | ** LocalFree |
16 | ** |
17 | |
18 | ** |
19 | **===========================================================================*/ |
20 | #include <palsuite.h> |
21 | |
22 | DWORD dwTlsIndex; /* TLS index */ |
23 | |
24 | /** |
25 | * main |
26 | * |
27 | * executable entry point |
28 | */ |
29 | INT __cdecl main( INT argc, CHAR **argv ) |
30 | { |
31 | CHAR lpstrData[256] = "" ; |
32 | LPVOID lpvData = NULL; |
33 | BOOL bRet; |
34 | |
35 | /* PAL initialization */ |
36 | if( (PAL_Initialize(argc, argv)) != 0 ) |
37 | { |
38 | return FAIL; |
39 | } |
40 | |
41 | /* Invalid TLS index */ |
42 | dwTlsIndex = -1; |
43 | |
44 | /* |
45 | * Set some data in the invalid TLS index |
46 | *Should return 0 and an error |
47 | */ |
48 | bRet = TlsSetValue(dwTlsIndex, (LPVOID)lpstrData); |
49 | |
50 | if ( bRet != 0) |
51 | {/*ERROR */ |
52 | Fail("TlsSetValue(%d, %x) returned %d " |
53 | "when it should have returned 0 and an error\n" , |
54 | dwTlsIndex, |
55 | lpvData, |
56 | bRet); |
57 | } |
58 | |
59 | /* |
60 | * Get the data at the invalid index |
61 | * Should return 0 and an error |
62 | */ |
63 | lpvData = TlsGetValue(dwTlsIndex); |
64 | |
65 | if ( lpvData != 0 ) |
66 | {/* ERROR */ |
67 | Fail("TlsGetValue(%d) returned %d " |
68 | "when it should have returned 0 and an error\n" , |
69 | dwTlsIndex, |
70 | lpvData); |
71 | } |
72 | |
73 | /* |
74 | * Release the invalid TLS index |
75 | * Should return 0 and an error |
76 | */ |
77 | bRet = TlsFree( dwTlsIndex ); |
78 | |
79 | if( bRet != 0 ) |
80 | {/* ERROR */ |
81 | Fail("TlsFree() returned %d " |
82 | "when it should have returned 0 and an error\n" , |
83 | bRet); |
84 | } |
85 | |
86 | PAL_Terminate(); |
87 | return PASS; |
88 | } |
89 | |
90 | |
91 | |