175 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
414 lines
20 KiB
C
414 lines
20 KiB
C
#ifndef GW_ENGINE_SPELL_LOCATOR_READY_H
|
|
#define GW_ENGINE_SPELL_LOCATOR_READY_H
|
|
|
|
/* Pure bounded 70334 Spell locator predicate. No process access.
|
|
*
|
|
* The owner MUST qualify original Main/header/fixed spans and its current
|
|
* owner/generation/connection before calling, and supply a callback that checks
|
|
* every readable span with the existing memory safety helper before copying.
|
|
* canonical_ids is the caller-qualified genuine Source canonical hotfix subset,
|
|
* not an arbitrary spell/FDI list. This helper never invokes base virtuals or
|
|
* original functions and never requests, loads, or proves materialized bodies.
|
|
*
|
|
* Stability is checked for each selected path and the whole-batch headers.
|
|
* It is not an atomic snapshot: inter-ID/ABA races remain possible. Owner scope
|
|
* must be rechecked before release. There is no TLS, heap, global mutable state,
|
|
* original-code write, execution, permission, or integrity/attestation action.
|
|
*/
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#define GW_SPELL_LOCATOR_MAX_IDS 4096u
|
|
#define GW_SPELL_LOCATOR_BUCKET_CAP 1048576u
|
|
#define GW_SPELL_LOCATOR_CHAIN_CAP 64u
|
|
#define GW_SPELL_LOCATOR_READ_CAP 1048576u
|
|
#define GW_SPELL_LOCATOR_WORK_CAP 65536u
|
|
#define GW_SPELL_LOCATOR_STORE_RVA UINT64_C(0x079c3d70)
|
|
#define GW_SPELL_LOCATOR_ASSERTED_RVA (GW_SPELL_LOCATOR_STORE_RVA + UINT64_C(0x20d))
|
|
#define GW_SPELL_LOCATOR_MAP_RVA (GW_SPELL_LOCATOR_STORE_RVA + UINT64_C(0x278))
|
|
#define GW_SPELL_LOCATOR_PROVIDER_RVA (GW_SPELL_LOCATOR_STORE_RVA + UINT64_C(0x268))
|
|
#define GW_SPELL_LOCATOR_PROVIDER_VTABLE_RVA UINT64_C(0x04cc56b8)
|
|
#define GW_SPELL_LOCATOR_PROVIDER_METHOD_RVA UINT64_C(0x00676a40)
|
|
#define GW_SPELL_LOCATOR_FALLBACK_CAP 1048576u
|
|
|
|
#define GW_SPELL_LOCATOR_REASON_READY 0u
|
|
#define GW_SPELL_LOCATOR_REASON_MISSING 1u
|
|
#define GW_SPELL_LOCATOR_REASON_ZERO 2u
|
|
#define GW_SPELL_LOCATOR_REASON_CHANGED 3u
|
|
#define GW_SPELL_LOCATOR_REASON_BUDGET 4u
|
|
#define GW_SPELL_LOCATOR_REASON_BAD_INPUT 5u
|
|
#define GW_SPELL_LOCATOR_REASON_BAD_MAIN_RANGE 6u
|
|
#define GW_SPELL_LOCATOR_REASON_UNSUPPORTED_PREREQUISITE 7u
|
|
#define GW_SPELL_LOCATOR_REASON_BAD_MAP 8u
|
|
#define GW_SPELL_LOCATOR_REASON_BAD_POINTER 9u
|
|
#define GW_SPELL_LOCATOR_REASON_CHAIN_LIMIT 10u
|
|
#define GW_SPELL_LOCATOR_REASON_CYCLE 11u
|
|
#define GW_SPELL_LOCATOR_REASON_UNREADABLE 12u
|
|
#define GW_SPELL_LOCATOR_REASON_PROVIDER_PENDING 13u
|
|
#define GW_SPELL_LOCATOR_REASON_BAD_PROVIDER 14u
|
|
|
|
typedef int (*gw_spell_locator_read_fn)(void *context, uintptr_t address,
|
|
void *output, size_t bytes);
|
|
typedef struct gw_spell_locator_diagnostics {
|
|
uint32_t reason, problem_spell_id, checked_ids, ready_ids;
|
|
uint32_t nodes_examined, read_calls, read_bytes, work_steps;
|
|
uint64_t bucket_count;
|
|
uint8_t asserted_prerequisite;
|
|
} gw_spell_locator_diagnostics;
|
|
|
|
struct gw_spell_locator_node_snapshot {
|
|
uintptr_t address;
|
|
unsigned char bytes[16];
|
|
};
|
|
struct gw_spell_locator_reader {
|
|
gw_spell_locator_read_fn read;
|
|
void *context;
|
|
gw_spell_locator_diagnostics *d;
|
|
};
|
|
|
|
static inline void gw_spell_locator_reset(gw_spell_locator_diagnostics *d)
|
|
{
|
|
d->reason=GW_SPELL_LOCATOR_REASON_READY; d->problem_spell_id=0;
|
|
d->checked_ids=0; d->ready_ids=0; d->nodes_examined=0;
|
|
d->read_calls=0; d->read_bytes=0; d->work_steps=0;
|
|
d->bucket_count=0; d->asserted_prerequisite=0;
|
|
}
|
|
static inline int gw_spell_locator_fail(gw_spell_locator_diagnostics *d,
|
|
uint32_t reason, uint32_t id, int result)
|
|
{
|
|
d->reason=reason; d->problem_spell_id=id; return result;
|
|
}
|
|
static inline uint32_t gw_spell_locator_u32(unsigned char const *p)
|
|
{
|
|
return (uint32_t)p[0] | ((uint32_t)p[1]<<8) |
|
|
((uint32_t)p[2]<<16) | ((uint32_t)p[3]<<24);
|
|
}
|
|
static inline uint64_t gw_spell_locator_u64(unsigned char const *p)
|
|
{
|
|
return (uint64_t)gw_spell_locator_u32(p) |
|
|
((uint64_t)gw_spell_locator_u32(p+4)<<32);
|
|
}
|
|
static inline int gw_spell_locator_equal(unsigned char const *a,
|
|
unsigned char const *b, size_t bytes)
|
|
{
|
|
size_t i;
|
|
for(i=0;i<bytes;++i) if(a[i]!=b[i]) return 0;
|
|
return 1;
|
|
}
|
|
static inline int gw_spell_locator_range(uintptr_t address, uint64_t bytes)
|
|
{
|
|
uint64_t at=(uint64_t)address;
|
|
uint64_t last=UINT64_C(0x00007fffffffffff);
|
|
return sizeof(uintptr_t)==8 && bytes && at>=UINT64_C(0x10000) &&
|
|
at<=last && bytes-1<=last-at;
|
|
}
|
|
static inline uint64_t gw_spell_locator_hash(uint32_t key)
|
|
{
|
|
uint64_t x=(uint64_t)key;
|
|
if(key&UINT32_C(0x80000000)) x|=UINT64_C(0xffffffff00000000);
|
|
x^=x>>33; x*=UINT64_C(0xff51afd7ed558ccd);
|
|
x^=x>>33; x*=UINT64_C(0xc4ceb9fe1a85ec53);
|
|
return x^(x>>33);
|
|
}
|
|
static inline int gw_spell_locator_work(struct gw_spell_locator_reader *r)
|
|
{
|
|
if(r->d->work_steps>=GW_SPELL_LOCATOR_WORK_CAP) {
|
|
r->d->reason=GW_SPELL_LOCATOR_REASON_BUDGET; return 0;
|
|
}
|
|
++r->d->work_steps; return 1;
|
|
}
|
|
/* 1 success, 0 bounded-work/read budget, -1 invalid span/unreadable. */
|
|
static inline int gw_spell_locator_read(struct gw_spell_locator_reader *r,
|
|
uintptr_t address, void *output, size_t bytes)
|
|
{
|
|
if(!gw_spell_locator_work(r)) return 0;
|
|
if(!gw_spell_locator_range(address,(uint64_t)bytes)) {
|
|
r->d->reason=GW_SPELL_LOCATOR_REASON_BAD_POINTER; return -1;
|
|
}
|
|
if(bytes>GW_SPELL_LOCATOR_READ_CAP-r->d->read_bytes) {
|
|
r->d->reason=GW_SPELL_LOCATOR_REASON_BUDGET; return 0;
|
|
}
|
|
++r->d->read_calls; r->d->read_bytes+=(uint32_t)bytes;
|
|
if(!r->read(r->context,address,output,bytes)) {
|
|
r->d->reason=GW_SPELL_LOCATOR_REASON_UNREADABLE; return -1;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
/* Snapshot a selected bucket/path, then compare the exact head and every node.
|
|
* Each selected node is only {next u64, key i32, locator-marker u32}. Length at
|
|
* +0x10 is deliberately not read: it belongs to 6A3570, not this AL predicate.
|
|
*/
|
|
static inline int gw_spell_locator_one(struct gw_spell_locator_reader *r,
|
|
uint32_t id, uint64_t count, uintptr_t buckets)
|
|
{
|
|
struct gw_spell_locator_node_snapshot nodes[GW_SPELL_LOCATOR_CHAIN_CAP];
|
|
unsigned char head[8], check[16];
|
|
uintptr_t head_address, node;
|
|
uint32_t used=0, i, pending=GW_SPELL_LOCATOR_REASON_MISSING;
|
|
uint64_t index=gw_spell_locator_hash(id)&(count-1);
|
|
int status, found=0;
|
|
r->d->problem_spell_id=id;
|
|
head_address=buckets+(uintptr_t)(index*8);
|
|
status=gw_spell_locator_read(r,head_address,head,8);
|
|
if(status!=1) return status;
|
|
node=(uintptr_t)gw_spell_locator_u64(head);
|
|
while(node && used<GW_SPELL_LOCATOR_CHAIN_CAP) {
|
|
if(!gw_spell_locator_work(r)) return 0;
|
|
if((node&7u) || !gw_spell_locator_range(node,16))
|
|
return gw_spell_locator_fail(r->d,GW_SPELL_LOCATOR_REASON_BAD_POINTER,id,-1);
|
|
for(i=0;i<used;++i) {
|
|
if(!gw_spell_locator_work(r)) return 0;
|
|
if(nodes[i].address==node)
|
|
return gw_spell_locator_fail(r->d,GW_SPELL_LOCATOR_REASON_CYCLE,id,-1);
|
|
}
|
|
nodes[used].address=node;
|
|
status=gw_spell_locator_read(r,node,nodes[used].bytes,16);
|
|
if(status!=1) return status;
|
|
++r->d->nodes_examined; ++used;
|
|
if(gw_spell_locator_u32(nodes[used-1].bytes+8)==id) {
|
|
found=1;
|
|
pending=gw_spell_locator_u32(nodes[used-1].bytes+12) ?
|
|
GW_SPELL_LOCATOR_REASON_READY : GW_SPELL_LOCATOR_REASON_ZERO;
|
|
break;
|
|
}
|
|
node=(uintptr_t)gw_spell_locator_u64(nodes[used-1].bytes);
|
|
}
|
|
if(!found && node)
|
|
return gw_spell_locator_fail(r->d,GW_SPELL_LOCATOR_REASON_CHAIN_LIMIT,id,-1);
|
|
status=gw_spell_locator_read(r,head_address,check,8);
|
|
if(status!=1) return status;
|
|
if(!gw_spell_locator_equal(head,check,8))
|
|
return gw_spell_locator_fail(r->d,GW_SPELL_LOCATOR_REASON_CHANGED,id,0);
|
|
for(i=0;i<used;++i) {
|
|
if(!gw_spell_locator_work(r)) return 0;
|
|
status=gw_spell_locator_read(r,nodes[i].address,check,16);
|
|
if(status!=1) return status;
|
|
if(!gw_spell_locator_equal(nodes[i].bytes,check,16))
|
|
return gw_spell_locator_fail(r->d,GW_SPELL_LOCATOR_REASON_CHANGED,id,0);
|
|
}
|
|
++r->d->checked_ids;
|
|
if(pending!=GW_SPELL_LOCATOR_REASON_READY)
|
|
return gw_spell_locator_fail(r->d,pending,id,0);
|
|
++r->d->ready_ids; return 1;
|
|
}
|
|
|
|
/* Exact read-only676A40/685D10/667AB0 equivalent. Statistics at provider
|
|
* +68/+6c/+70 are neither read nor written. Snapshot consumed fields only. */
|
|
struct gw_spell_locator_fallback_snapshot {
|
|
uintptr_t address; size_t size; unsigned char bytes[16];
|
|
};
|
|
struct gw_spell_locator_fallback_path {
|
|
struct gw_spell_locator_fallback_snapshot rows[80]; size_t used;
|
|
};
|
|
static inline int gw_spell_locator_take(struct gw_spell_locator_reader* r,
|
|
struct gw_spell_locator_fallback_path* path,uintptr_t address,void* output,size_t size)
|
|
{
|
|
int result;size_t i;
|
|
if(path->used>=80u || size>16u)
|
|
return gw_spell_locator_fail(r->d,GW_SPELL_LOCATOR_REASON_BUDGET,r->d->problem_spell_id,0);
|
|
result=gw_spell_locator_read(r,address,output,size);if(result!=1)return result;
|
|
path->rows[path->used].address=address;path->rows[path->used].size=size;
|
|
for(i=0;i<size;++i)path->rows[path->used].bytes[i]=((unsigned char*)output)[i];
|
|
++path->used;return 1;
|
|
}
|
|
static inline int gw_spell_locator_verify(struct gw_spell_locator_reader* r,
|
|
struct gw_spell_locator_fallback_path const* path)
|
|
{
|
|
unsigned char bytes[16];size_t i;int result;
|
|
for(i=0;i<path->used;++i){
|
|
result=gw_spell_locator_read(r,path->rows[i].address,bytes,path->rows[i].size);
|
|
if(result!=1)return result;
|
|
if(!gw_spell_locator_equal(bytes,path->rows[i].bytes,path->rows[i].size))
|
|
return gw_spell_locator_fail(r->d,GW_SPELL_LOCATOR_REASON_CHANGED,r->d->problem_spell_id,0);
|
|
}
|
|
return 1;
|
|
}
|
|
static inline uint64_t gw_spell_locator_primary_hash(uint32_t key)
|
|
{
|
|
uint64_t h=(uint64_t)key*UINT64_C(0xff51afd7ed558ccd);
|
|
h=(h^(h>>33))*UINT64_C(0xc4ceb9fe1a85ec53);return h^(h>>33);
|
|
}
|
|
static inline uint64_t gw_spell_locator_mul_high32(uint32_t n,uint64_t z)
|
|
{
|
|
uint64_t low=(uint64_t)(uint32_t)z*n,high=(z>>32)*n;
|
|
return (high>>32)+(((high<<32)+low)<low);
|
|
}
|
|
static inline int gw_spell_locator_fallback(struct gw_spell_locator_reader* r,
|
|
uintptr_t main_base,uint32_t id)
|
|
{
|
|
struct gw_spell_locator_fallback_path path;unsigned char raw[16];
|
|
uintptr_t provider,base,secondary,pairs,bucket_bytes,aux;
|
|
uint64_t pair_count,bucket_count,multiplier,aux_count,lo,hi,mid,offset,locator=0;
|
|
uint32_t stride,secondary_stride,min_id,max_id,primary_count,secondary_count;
|
|
uint32_t scalar,mask,width,key,g,top,index,payload=UINT32_C(0xffff);
|
|
uint64_t h,t,z;int status,available=0;
|
|
path.used=0;
|
|
#define GW_LOC_TAKE(A,N) do{status=gw_spell_locator_take(r,&path,(A),raw,(N));if(status!=1)return status;}while(0)
|
|
#define GW_LOC_BAD() return gw_spell_locator_fail(r->d,GW_SPELL_LOCATOR_REASON_BAD_PROVIDER,id,-1)
|
|
GW_LOC_TAKE(main_base+(uintptr_t)GW_SPELL_LOCATOR_PROVIDER_RVA,8);provider=(uintptr_t)gw_spell_locator_u64(raw);
|
|
if(!provider){
|
|
status=gw_spell_locator_verify(r,&path);if(status!=1)return status;
|
|
return gw_spell_locator_fail(r->d,GW_SPELL_LOCATOR_REASON_PROVIDER_PENDING,id,0);
|
|
}
|
|
if((provider&7u)||!gw_spell_locator_range(provider,0xe0u))GW_LOC_BAD();
|
|
GW_LOC_TAKE(provider,8);
|
|
if(gw_spell_locator_u64(raw)!=main_base+GW_SPELL_LOCATOR_PROVIDER_VTABLE_RVA)GW_LOC_BAD();
|
|
GW_LOC_TAKE(main_base+(uintptr_t)GW_SPELL_LOCATOR_PROVIDER_VTABLE_RVA+8u,8);
|
|
if(gw_spell_locator_u64(raw)!=main_base+GW_SPELL_LOCATOR_PROVIDER_METHOD_RVA)GW_LOC_BAD();
|
|
GW_LOC_TAKE(provider+0x40u,8);min_id=gw_spell_locator_u32(raw);max_id=gw_spell_locator_u32(raw+4);
|
|
if(id>=min_id&&id<=max_id){
|
|
key=id-min_id;
|
|
GW_LOC_TAKE(provider+0x98u+0x20u,8);pair_count=gw_spell_locator_u64(raw);
|
|
if(pair_count>GW_SPELL_LOCATOR_FALLBACK_CAP)GW_LOC_BAD();
|
|
if(pair_count){
|
|
GW_LOC_TAKE(provider+0x98u,4);scalar=gw_spell_locator_u32(raw);
|
|
GW_LOC_TAKE(provider+0xa0u,8);multiplier=gw_spell_locator_u64(raw);
|
|
GW_LOC_TAKE(provider+0xa8u,8);bucket_bytes=(uintptr_t)gw_spell_locator_u64(raw);
|
|
GW_LOC_TAKE(provider+0xb0u,8);pairs=(uintptr_t)gw_spell_locator_u64(raw);
|
|
GW_LOC_TAKE(provider+0xc0u,8);bucket_count=gw_spell_locator_u64(raw);
|
|
GW_LOC_TAKE(provider+0xc8u,4);mask=gw_spell_locator_u32(raw);
|
|
GW_LOC_TAKE(provider+0xccu,1);width=raw[0];
|
|
if(!bucket_count||bucket_count>GW_SPELL_LOCATOR_FALLBACK_CAP||!width||width>4u||
|
|
!gw_spell_locator_range(bucket_bytes,bucket_count*width+3u)||
|
|
(pairs&3u)||!gw_spell_locator_range(pairs,pair_count*8u))GW_LOC_BAD();
|
|
h=gw_spell_locator_primary_hash(key);
|
|
GW_LOC_TAKE(bucket_bytes+(uintptr_t)((h&(bucket_count-1u))*width),4);g=gw_spell_locator_u32(raw)&mask;
|
|
top=UINT32_C(1)<<((width*8u-1u)&31u);
|
|
if(g&top)index=g&~top;
|
|
else{
|
|
t=(uint64_t)g*UINT64_C(0x9e3779b97f4a7c15)^h;
|
|
t=(t^(t>>33))*UINT64_C(0xff51afd7ed558ccd);
|
|
t=(t^(t>>33))*UINT64_C(0xc4ceb9fe1a85ec53);t^=t>>33;
|
|
z=(uint64_t)((uint32_t)t^(uint32_t)(t>>32))*multiplier;
|
|
index=(uint32_t)gw_spell_locator_mul_high32(scalar,z);
|
|
}
|
|
if(index>=pair_count)GW_LOC_BAD();
|
|
GW_LOC_TAKE(pairs+(uintptr_t)index*8u,8);
|
|
if(gw_spell_locator_u32(raw)==key)payload=(uint32_t)raw[4]|((uint32_t)raw[5]<<8);
|
|
}
|
|
}
|
|
if(payload==UINT32_C(0xfffe))goto verify;
|
|
if(payload!=UINT32_C(0xffff)){
|
|
GW_LOC_TAKE(provider+0x48u,2);primary_count=(uint32_t)raw[0]|((uint32_t)raw[1]<<8);
|
|
if(payload<primary_count){
|
|
GW_LOC_TAKE(provider+8u,8);base=(uintptr_t)gw_spell_locator_u64(raw);
|
|
GW_LOC_TAKE(provider+0x38u,4);stride=gw_spell_locator_u32(raw);
|
|
offset=(uint64_t)payload*stride;
|
|
if(offset>UINT32_MAX||base>UINTPTR_MAX-offset)GW_LOC_BAD();
|
|
locator=base+offset;
|
|
}else{
|
|
index=(uint16_t)(payload-primary_count);
|
|
GW_LOC_TAKE(provider+0x54u,4);secondary_count=gw_spell_locator_u32(raw);
|
|
if(secondary_count>GW_SPELL_LOCATOR_FALLBACK_CAP||index>=secondary_count)GW_LOC_BAD();
|
|
GW_LOC_TAKE(provider+0x10u,8);secondary=(uintptr_t)gw_spell_locator_u64(raw);
|
|
GW_LOC_TAKE(provider+0x3cu,4);secondary_stride=gw_spell_locator_u32(raw);
|
|
offset=(uint64_t)index*secondary_stride;
|
|
if(offset>UINT32_MAX||secondary>UINTPTR_MAX-offset)GW_LOC_BAD();
|
|
locator=secondary+offset;
|
|
}
|
|
}else{
|
|
GW_LOC_TAKE(provider+0xd0u,16);aux=(uintptr_t)gw_spell_locator_u64(raw);aux_count=gw_spell_locator_u64(raw+8);
|
|
if(aux_count>GW_SPELL_LOCATOR_FALLBACK_CAP)GW_LOC_BAD();
|
|
if(aux_count){
|
|
if((aux&7u)||!gw_spell_locator_range(aux,aux_count*16u))GW_LOC_BAD();
|
|
lo=0;hi=aux_count;
|
|
while(lo<hi){
|
|
if(!gw_spell_locator_work(r))return 0;
|
|
mid=lo+(hi-lo)/2u;GW_LOC_TAKE(aux+(uintptr_t)mid*16u,4);
|
|
if(gw_spell_locator_u32(raw)<id)lo=mid+1u;else hi=mid;
|
|
}
|
|
if(lo<aux_count){
|
|
GW_LOC_TAKE(aux+(uintptr_t)lo*16u,4);
|
|
if(gw_spell_locator_u32(raw)==id){GW_LOC_TAKE(aux+(uintptr_t)lo*16u+8u,8);locator=gw_spell_locator_u64(raw);}
|
|
}
|
|
}
|
|
}
|
|
if(locator){if(!gw_spell_locator_range((uintptr_t)locator,1))GW_LOC_BAD();available=1;}
|
|
verify:
|
|
status=gw_spell_locator_verify(r,&path);if(status!=1)return status;
|
|
/* No read of locator contents or original statistics, no materialization. */
|
|
if(!available)return gw_spell_locator_fail(r->d,GW_SPELL_LOCATOR_REASON_MISSING,id,0);
|
|
return 1;
|
|
#undef GW_LOC_TAKE
|
|
#undef GW_LOC_BAD
|
|
}
|
|
|
|
/* 1 all canonical candidates pass original locator availability; 0 pending/changed/budget;
|
|
* -1 unsupported/malformed/unreadable. Neither 0 nor -1 permits release.
|
|
* Empty canonical subset is vacuously ready without a memory read.
|
|
*/
|
|
static inline int gw_spell_locators_available(uintptr_t main_base,
|
|
uint32_t const *canonical_ids, size_t count, gw_spell_locator_read_fn read,
|
|
void *context, gw_spell_locator_diagnostics *diagnostics)
|
|
{
|
|
gw_spell_locator_diagnostics local;
|
|
gw_spell_locator_diagnostics *d=diagnostics ? diagnostics : &local;
|
|
struct gw_spell_locator_reader r;
|
|
unsigned char header[16], after[16], prerequisite=0, prerequisite_after=0;
|
|
uintptr_t map, asserted, buckets;
|
|
uint64_t bucket_count, pointer;
|
|
uint32_t reason=GW_SPELL_LOCATOR_REASON_READY, problem=0;
|
|
int status=1, result=1;
|
|
size_t i;
|
|
gw_spell_locator_reset(d);
|
|
if(count>GW_SPELL_LOCATOR_MAX_IDS || (count && (!canonical_ids || !read)))
|
|
return gw_spell_locator_fail(d,GW_SPELL_LOCATOR_REASON_BAD_INPUT,0,-1);
|
|
if(!count) return 1;
|
|
if(sizeof(uintptr_t)!=8 || (main_base&UINT32_C(0xfff)) ||
|
|
!gw_spell_locator_range(main_base,GW_SPELL_LOCATOR_MAP_RVA+16))
|
|
return gw_spell_locator_fail(d,GW_SPELL_LOCATOR_REASON_BAD_MAIN_RANGE,0,-1);
|
|
r.read=read; r.context=context; r.d=d;
|
|
for(i=0;i<count;++i) {
|
|
if(!gw_spell_locator_work(&r)) return 0;
|
|
if(!canonical_ids[i] || canonical_ids[i]>UINT32_C(0x7fffffff))
|
|
return gw_spell_locator_fail(d,GW_SPELL_LOCATOR_REASON_BAD_INPUT,canonical_ids[i],-1);
|
|
}
|
|
asserted=main_base+(uintptr_t)GW_SPELL_LOCATOR_ASSERTED_RVA;
|
|
map=main_base+(uintptr_t)GW_SPELL_LOCATOR_MAP_RVA;
|
|
status=gw_spell_locator_read(&r,asserted,&prerequisite,1);
|
|
if(status!=1) return status;
|
|
d->asserted_prerequisite=prerequisite;
|
|
/* Owner policy: an unsupported asserted prerequisite is not an ordinary
|
|
* AL=false locator result, nor a claim that this byte means initialized. */
|
|
if(!prerequisite)
|
|
return gw_spell_locator_fail(d,GW_SPELL_LOCATOR_REASON_UNSUPPORTED_PREREQUISITE,0,-1);
|
|
status=gw_spell_locator_read(&r,map,header,16);
|
|
if(status!=1) return status;
|
|
bucket_count=gw_spell_locator_u64(header); pointer=gw_spell_locator_u64(header+8);
|
|
d->bucket_count=bucket_count;
|
|
if(!bucket_count || bucket_count>GW_SPELL_LOCATOR_BUCKET_CAP ||
|
|
(bucket_count&(bucket_count-1)))
|
|
return gw_spell_locator_fail(d,GW_SPELL_LOCATOR_REASON_BAD_MAP,0,-1);
|
|
buckets=(uintptr_t)pointer;
|
|
if((buckets&7u) || !gw_spell_locator_range(buckets,bucket_count*8))
|
|
return gw_spell_locator_fail(d,GW_SPELL_LOCATOR_REASON_BAD_POINTER,0,-1);
|
|
for(i=0;i<count;++i) {
|
|
result=gw_spell_locator_one(&r,canonical_ids[i],bucket_count,buckets);
|
|
if(!result&&d->reason==GW_SPELL_LOCATOR_REASON_MISSING){
|
|
result=gw_spell_locator_fallback(&r,main_base,canonical_ids[i]);
|
|
if(result==1){
|
|
uint32_t checked=d->checked_ids,ready=d->ready_ids;int again;
|
|
again=gw_spell_locator_one(&r,canonical_ids[i],bucket_count,buckets);
|
|
d->checked_ids=checked;d->ready_ids=ready;
|
|
if(again==1)result=gw_spell_locator_fail(d,GW_SPELL_LOCATOR_REASON_CHANGED,canonical_ids[i],0);
|
|
else if(again<0||d->reason!=GW_SPELL_LOCATOR_REASON_MISSING)result=again;
|
|
else{++d->ready_ids;d->reason=GW_SPELL_LOCATOR_REASON_READY;d->problem_spell_id=0;}
|
|
}
|
|
}
|
|
if(result!=1) break;
|
|
}
|
|
reason=d->reason; problem=d->problem_spell_id;
|
|
if(result<0 || reason==GW_SPELL_LOCATOR_REASON_BUDGET) return result;
|
|
status=gw_spell_locator_read(&r,map,after,16);
|
|
if(status!=1) return status;
|
|
status=gw_spell_locator_read(&r,asserted,&prerequisite_after,1);
|
|
if(status!=1) return status;
|
|
if(!gw_spell_locator_equal(header,after,16) || prerequisite_after!=prerequisite)
|
|
return gw_spell_locator_fail(d,GW_SPELL_LOCATOR_REASON_CHANGED,problem,0);
|
|
if(result==1) { d->reason=GW_SPELL_LOCATOR_REASON_READY; d->problem_spell_id=0; }
|
|
else { d->reason=reason; d->problem_spell_id=problem; }
|
|
return result;
|
|
}
|
|
#endif
|