Files
praxisandClaude Fable 5.2 8e02dccb86 In-client stack: transport, session lifecycle and engine bridge
175 files, from working commit b1a079a.

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

61 lines
3.5 KiB
C

/* One authenticated roster delivery experiment. The genuine queued receiver
* remains authoritative; no account flags or connection state are fabricated.
*/
#include "engine_poll_host.h"
struct PacketHost {
u32 abi,size;
volatile u32 ready,ack,proof_valid,payload_bytes,submitted,received;
volatile u32 last_opcode,observed_state,error,reserved;
u64 original_receive;
unsigned char payload[16384];
};
__declspec(dllexport) struct PacketHost gw_packet_host_data={1,sizeof(struct PacketHost)};
/* Separate export keeps PacketHost ABI 1 unchanged. Entries contain only a
* little-endian opcode (low 32 bits) and byte count (high 32 bits), never a
* packet body. The target counter survives ring wrap. Read after callbacks
* quiesce: concurrent writers may publish ring slots out of order. */
struct PacketHistory {
u32 abi,size,capacity,reserved;
volatile u64 total,roster_dispatches;
volatile u64 headers[128];
};
__declspec(dllexport) struct PacketHistory gw_packet_header_history={1,sizeof(struct PacketHistory),128,0};
typedef void (*Submit)(void *,u32,void *,void *,const void *,u32);
typedef int (*Receive)(void *,u32,u32,const unsigned char *,u32);
__declspec(dllexport) void gw_packet_poll_callback(void *owner) {
u32 sequence;
if(!gw_poll_host_data.original_poll)return;
if(record_poll(owner)){
sequence=__atomic_load_n(&gw_packet_host_data.ready,__ATOMIC_ACQUIRE);
if(sequence && sequence!=gw_packet_host_data.ack){
u32 bytes=gw_packet_host_data.payload_bytes;
void *queue=*(void **)((unsigned char *)owner+0xa0);
if(gw_packet_host_data.proof_valid!=1 || bytes<4 || bytes>sizeof(gw_packet_host_data.payload))__atomic_store_n(&gw_packet_host_data.error,1,__ATOMIC_RELEASE);
else if(!queue || *(void **)queue!=owner)__atomic_store_n(&gw_packet_host_data.error,2,__ATOMIC_RELEASE);
else{
((Submit)0x141e54190ULL)(queue,0x12,0,owner,gw_packet_host_data.payload,bytes);
__atomic_add_fetch(&gw_packet_host_data.submitted,1,__ATOMIC_RELEASE);
}
__atomic_store_n(&gw_packet_host_data.ack,sequence,__ATOMIC_RELEASE);
}
}
((PollFunction)gw_poll_host_data.original_poll)(owner);
}
__declspec(dllexport) int gw_packet_receive_callback(void *owner,u32 queued,u32 processing,const unsigned char *data,u32 bytes) {
if((u64)owner==gw_poll_host_data.owner && data && bytes>=4){
u32 opcode=(u32)data[0]|((u32)data[1]<<8)|((u32)data[2]<<16)|((u32)data[3]<<24);
u64 sequence=__atomic_fetch_add(&gw_packet_header_history.total,1,__ATOMIC_RELAXED);
__atomic_store_n(&gw_packet_header_history.headers[sequence%128],((u64)bytes<<32)|opcode,__ATOMIC_RELEASE);
if(opcode==0x470363)__atomic_add_fetch(&gw_packet_header_history.roster_dispatches,1,__ATOMIC_RELEASE);
gw_packet_host_data.last_opcode=opcode;
gw_packet_host_data.observed_state=*(u32 *)((unsigned char *)owner+0x98);
/* Public consumer markers only; never retain packet bodies. */
if(gw_packet_host_data.last_opcode==0x5e0000)
__atomic_or_fetch(&gw_packet_host_data.reserved,2,__ATOMIC_RELEASE);
if(gw_packet_host_data.last_opcode==0x5e0003)
__atomic_or_fetch(&gw_packet_host_data.reserved,1,__ATOMIC_RELEASE);
__atomic_add_fetch(&gw_packet_host_data.received,1,__ATOMIC_RELEASE);
}
return ((Receive)gw_packet_host_data.original_receive)(owner,queued,processing,data,bytes);
}