| 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 TlsAlloc and TlsFree are working when we try |
| 10 | ** to allocate the guaranted minimum number of indicies. |
| 11 | ** |
| 12 | |
| 13 | ** |
| 14 | **===========================================================================*/ |
| 15 | #include <palsuite.h> |
| 16 | |
| 17 | #define NUM_OF_INDEX 64 |
| 18 | /* Minimum guaranteed is at least 64 for all systems.*/ |
| 19 | |
| 20 | /** |
| 21 | * main |
| 22 | * |
| 23 | * executable entry point |
| 24 | */ |
| 25 | INT __cdecl main( INT argc, CHAR **argv ) |
| 26 | { |
| 27 | DWORD dwIndexes[NUM_OF_INDEX]; |
| 28 | int i,j; |
| 29 | |
| 30 | /* PAL initialization */ |
| 31 | if( (PAL_Initialize(argc, argv)) != 0 ) |
| 32 | { |
| 33 | return FAIL; |
| 34 | } |
| 35 | |
| 36 | /* Allocate a bunch of TLS indexes. */ |
| 37 | for( i = 0; i < NUM_OF_INDEX; i++ ) |
| 38 | { |
| 39 | if( (dwIndexes[i] = TlsAlloc()) == TLS_OUT_OF_INDEXES ) |
| 40 | {/*ERROR */ |
| 41 | DWORD dwError = GetLastError(); |
| 42 | Fail("TlsAlloc() returned -1 with error %d" |
| 43 | "when trying to allocate %d index\n" , |
| 44 | dwError, |
| 45 | i); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /* Free the TLS indexes.*/ |
| 50 | for( j = 0; j < NUM_OF_INDEX; j++ ) |
| 51 | { |
| 52 | if( TlsFree(dwIndexes[j]) == 0 ) |
| 53 | {/* ERROR */ |
| 54 | DWORD dwError = GetLastError(); |
| 55 | Fail("TlsFree() returned 0 with error %d" |
| 56 | "when trying to free %d index\n" , |
| 57 | dwError, |
| 58 | i); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | PAL_Terminate(); |
| 63 | |
| 64 | return PASS; |
| 65 | } |
| 66 | |
| 67 | |