MCPcopy Create free account
hub / github.com/JRickey/BattleShip / stack_worker

Function stack_worker

port/coroutine_test.cpp:115–127  ·  view source on GitHub ↗

Stack hygiene: the worker writes a recognisable pattern to a chunk of * its own stack, yields, runs again. The data must survive across the * yield (i.e. the swap really restored the right sp). */

Source from the content-addressed store, hash-verified

113 * its own stack, yields, runs again. The data must survive across the
114 * yield (i.e. the swap really restored the right sp). */
115void stack_worker(void *arg) {
116 volatile uint64_t pattern[256];
117 uint64_t seed = (uint64_t)(intptr_t)arg;
118 for (int i = 0; i < 256; i++) pattern[i] = seed ^ (uint64_t)i;
119 port_coroutine_yield();
120 for (int i = 0; i < 256; i++) {
121 if (pattern[i] != (seed ^ (uint64_t)i)) {
122 fprintf(stderr, "FAIL: stack corrupted at %d (seed=%llx)\n",
123 i, (unsigned long long)seed);
124 std::exit(1);
125 }
126 }
127}
128
129void test_stack_preservation() {
130 PortCoroutine *a = port_coroutine_create(stack_worker, (void *)0xCAFEBABE, 128 * 1024);

Callers

nothing calls this directly

Calls 1

port_coroutine_yieldFunction · 0.70

Tested by

no test coverage detected