Skip to content

Commit

Permalink
test/self_oom: Remove const cast
Browse files Browse the repository at this point in the history
  • Loading branch information
lhmouse committed Nov 9, 2024
1 parent a6c8ccb commit 6e5fd79
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions test/self_oom.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@
* LICENSE.TXT as a whole. The GCC Runtime Library Exception applies
* to this file. */

#define __MCF_XGLOBALS_IMPORT
#define __MCF_XGLOBALS_INLINE __MCF_GNU_INLINE
#define __MCF_XGLOBALS_READONLY
#include "../mcfgthread/xglobals.h"
#include <assert.h>
#include <stdio.h>
#include <windows.h>

#if defined __CYGWIN__
int
main(void)
{
return 77;
}
#else // __CYGWIN__

#define NTHREADS 64U
static HANDLE threads[NTHREADS];

#if !defined __CYGWIN__
static
DWORD
__stdcall
Expand All @@ -26,20 +36,14 @@ thread_proc(void* arg)
fprintf(stderr, "thread %d quitting\n", _MCF_thread_self_tid());
return 0;
}
#endif

int
main(void)
{
#if defined __CYGWIN__
return 77;
#else
const uint32_t heap_capacity = 1048576; // 1 MB
volatile HANDLE* const heap = (volatile HANDLE*) &__MCF_crt_heap;

// replace global heap
*heap = HeapCreate(0, 0, heap_capacity);
assert(*heap);
const uint32_t heap_capacity = 1048576;
__MCF_crt_heap = HeapCreate(0, 0, heap_capacity);
assert(&__MCF_crt_heap);

// allocate until oom
for(uint32_t i = 0; i < heap_capacity / 16; ++i)
Expand All @@ -57,5 +61,6 @@ main(void)
CloseHandle(threads[k]);
fprintf(stderr, "main wait finished: %d\n", (int)k);
}
#endif
}

#endif // __CYGWIN__

0 comments on commit 6e5fd79

Please sign in to comment.