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

34 lines
3.0 KiB
C

#include "pipe_atomic.h"
#include <stddef.h>
#if defined(GW_SOURCE_ONLY_PROFILE) && (GW_SOURCE_ONLY_PROFILE == 2 || GW_SOURCE_ONLY_PROFILE == 3)
_Static_assert(sizeof(struct gw_pipe_control)==640,"saved pipe ABI mismatch");
_Static_assert(sizeof(struct gw_private_pipe_tables)==5136,"saved epoch table ABI mismatch");
_Static_assert(offsetof(struct gw_private_pipe_tables,methods)==16,"saved epoch table offset mismatch");
static const uint64_t original[9]={0x141e4ca60ULL,0x141e4d120ULL,0x1401d9200ULL,0x141e4e8e0ULL,0x14091e6e0ULL,0x1409e95f0ULL,0x141e4c8f0ULL,0x141e4c9e0ULL,0x141e4ca20ULL};
static bool valid(const struct gw_pipe_control*h,const struct gw_private_pipe_tables*t,const struct gw_private_pipe_prevalidated*p){
unsigned i;const uint64_t*row;
if(!h||!t||!p||!p->pipe_vptr||((uintptr_t)p->pipe_vptr%sizeof(uintptr_t)))return false;
if(h->abi!=1||h->size!=sizeof(*h)||h->stage!=1||h->error||h->closed||!h->owner||!h->pipe||!h->connection||!h->queue||h->reserved)return false;
if(h->original_table!=0x144e59fe8ULL||h->original_read!=original[1]||h->original_write!=original[0])return false;
if(t->abi!=1||t->size!=sizeof(*t)||t->count!=64||t->reserved||!p->generation||p->generation>64||p->generation!=p->active_generation)return false;
if((uintptr_t)p->pipe_vptr!=h->pipe||p->owner_global!=h->owner||p->queue_owner!=h->owner||p->pipe_owner!=h->owner||p->holder_pipe!=h->pipe||p->owner_connection!=h->connection||p->pipe_reserved)return false;
if(!p->owner_vtable||p->owner_vtable!=p->expected_owner_vtable||p->connection_vtable!=0x1450396b0ULL||!p->owner_listener||p->connection_listener!=p->owner_listener||p->listener_owner!=h->owner)return false;
if(p->owner_state!=4||!p->current_thread||p->current_thread!=p->primary_thread||!p->authenticated||!p->transport_prepared||!p->receiver_fresh)return false;
if(!p->callback_write||!p->callback_read)return false;
row=t->methods[p->generation-1];if(row[0]!=p->original_rtti||row[1]!=p->callback_write||row[2]!=p->callback_read)return false;
for(i=2;i<9;i++)if(row[i+1]!=original[i])return false;
return true;
}
static enum gw_private_pipe_result swap(struct gw_pipe_control*h,struct gw_private_pipe_tables*t,const struct gw_private_pipe_prevalidated*p,bool restore){
uintptr_t old,clone,expected,replacement;
if(!valid(h,t,p))return GW_PRIVATE_PIPE_REFUSED;
old=(uintptr_t)h->original_table;clone=(uintptr_t)&t->methods[p->generation-1][1];if(old==clone)return GW_PRIVATE_PIPE_REFUSED;
expected=restore?clone:old;replacement=restore?old:clone;
if(__atomic_compare_exchange_n(p->pipe_vptr,&expected,replacement,false,__ATOMIC_ACQ_REL,__ATOMIC_ACQUIRE))return GW_PRIVATE_PIPE_SWAPPED;
return GW_PRIVATE_PIPE_STALE;
}
enum gw_private_pipe_result gw_private_pipe_publish(struct gw_pipe_control*h,struct gw_private_pipe_tables*t,const struct gw_private_pipe_prevalidated*p){return swap(h,t,p,false);}
enum gw_private_pipe_result gw_private_pipe_restore(struct gw_pipe_control*h,struct gw_private_pipe_tables*t,const struct gw_private_pipe_prevalidated*p){return swap(h,t,p,true);}
#endif