Files
WoW-Hybrid-gateway/tests/closed_send_queue_discard_fixture.c
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

90 lines
4.7 KiB
C

#include <windows.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#define GW_CLOSED_SEND_FIXTURE 1
static void fixture_store_release(void *, void **, uint32_t *);
static unsigned char fixture_node_release(void *, const char *, int, unsigned int);
#define GW_CLOSED_SEND_STORE_RELEASE fixture_store_release
#define GW_CLOSED_SEND_NODE_RELEASE fixture_node_release
#define GW_CLOSED_SEND_SOURCE "closed-session-fixture"
#include "nohelper/closed_send_queue_discard.private.h"
static union { max_align_t align; unsigned char bytes[0x300]; } owner;
static struct gw_closed_send_node nodes[4];
static unsigned char payload[4][32];
static uint64_t holder;
static unsigned int stores, releases, freed[4], target_ready = 1;
static int in_range(const void *p, SIZE_T n, const void *base, SIZE_T size) {
uintptr_t a = (uintptr_t)p, b = (uintptr_t)base;
return a >= b && a + n >= a && a + n <= b + size;
}
static int gw_closed_send_readable(const void *p, SIZE_T n) {
return in_range(p,n,&owner,sizeof(owner)) || in_range(p,n,nodes,sizeof(nodes)) ||
in_range(p,n,payload,sizeof(payload)) || in_range(p,n,&holder,sizeof(holder));
}
static int gw_closed_send_targets_ready(void) { return (int)target_ready; }
static void fixture_store_release(void *store, void **data, uint32_t *capacity) {
struct gw_closed_send_store *s = store;
if (data != &s->data || capacity != &s->capacity) stores = 10000;
*data = NULL; *capacity = 0; ++stores;
}
static unsigned char fixture_node_release(void *p, const char *source, int line, unsigned int flags) {
struct gw_closed_send_node *n = p;
ptrdiff_t i = n - nodes;
if (i < 0 || i >= 4 || n->prev || n->next || n->buffer.data ||
n->buffer.capacity || !source || line != -2 || flags || freed[i]) return 0;
freed[i] = 1; ++releases; return 1;
}
static void reset(void) {
unsigned int q;
memset(&owner,0,sizeof(owner)); memset(nodes,0,sizeof(nodes)); memset(freed,0,sizeof(freed));
stores = releases = 0; target_ready = 1; holder = 0;
*(LONG *)(owner.bytes+0x98) = 2;
*(uint64_t *)(owner.bytes+0x228) = (uint64_t)(uintptr_t)&holder;
for (q=0;q<2;++q) {
void **h = (void **)(owner.bytes+0x1e8+q*0x18);
h[0] = h; h[1] = (void *)((uintptr_t)h|1);
}
}
static void append(unsigned int q, unsigned int i) {
void **h = (void **)(owner.bytes+0x1e8+q*0x18);
struct gw_closed_send_node *n = &nodes[i];
n->prev = h[0]; n->next = (void *)((uintptr_t)h|1); n->requested = (unsigned char)q;
n->buffer.table = 0x144c69b00ULL; n->buffer.data=payload[i];
n->buffer.capacity=32; n->buffer.length=24; n->buffer.cursor=16;
if (h[0]==h) h[1]=n; else ((struct gw_closed_send_node *)h[0])->next=n;
h[0]=n;
}
#define CHECK(x) do { if (!(x)) { printf("FAIL line %d\n",__LINE__); return 1; } } while (0)
int main(void) {
void **a=(void **)(owner.bytes+0x1e8), **b=(void **)(owner.bytes+0x200);
reset(); CHECK(!gw_closed_send_queues_discard(owner.bytes)); CHECK(!stores&&!releases);
append(0,0); append(0,1); append(1,2);
CHECK(!gw_closed_send_queues_discard(owner.bytes)); CHECK(stores==3&&releases==3);
CHECK(a[0]==a&&a[1]==(void *)((uintptr_t)a|1));
CHECK(b[0]==b&&b[1]==(void *)((uintptr_t)b|1));
CHECK(!gw_closed_send_queues_discard(owner.bytes)); CHECK(releases==3);
reset(); append(0,0); append(1,1); nodes[1].buffer.cursor=0;
CHECK(gw_closed_send_queues_discard(owner.bytes)==-81); CHECK(!stores&&!releases&&a[1]==&nodes[0]);
nodes[1].buffer.cursor=16; nodes[1].prev=NULL;
CHECK(gw_closed_send_queues_discard(owner.bytes)==-81); CHECK(!stores&&!releases);
reset(); append(1,0); nodes[0].next=NULL;
CHECK(gw_closed_send_queues_discard(owner.bytes)==-82); CHECK(!stores&&!releases);
reset(); append(1,0); target_ready=0;
CHECK(gw_closed_send_queues_discard(owner.bytes)==-83); CHECK(!stores&&!releases);
reset(); append(1,0); *(LONG *)(owner.bytes+0x98)=5;
CHECK(gw_closed_send_queues_discard(owner.bytes)==-80); CHECK(!stores&&!releases);
reset(); append(1,0); *(uint64_t *)(owner.bytes+0x1a0)=1;
CHECK(gw_closed_send_queues_discard(owner.bytes)==-80); CHECK(!stores&&!releases);
reset(); append(1,0); *(uint64_t *)(owner.bytes+0x1b0)=1;
CHECK(gw_closed_send_queues_discard(owner.bytes)==-80); CHECK(!stores&&!releases);
reset(); append(1,0); holder=1;
CHECK(gw_closed_send_queues_discard(owner.bytes)==-80); CHECK(!stores&&!releases);
reset(); a[0]=a[1]=NULL;
CHECK(gw_closed_send_queues_discard(owner.bytes)==-82); CHECK(!stores&&!releases);
puts("CLOSED_SEND_DISCARD PASS: both original lists, original allocation order, complete preflight, live/retained/invalid refusal; zero sends");
return 0;
}