883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
117 lines
4.9 KiB
Python
117 lines
4.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Exercise the production callback admission before packet translation.
|
|
|
|
Native Back retains the receiver until OpenRealm. The borrowed receiver/view
|
|
can therefore be stale after Source close; neither may be read on that path.
|
|
The harness keeps the actual callback entry and error-exit code, substituting
|
|
an admission counter for the unrelated packet translation body.
|
|
"""
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from wine_session_retirement_test import function
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class ClosedPipeCallbacks(unittest.TestCase):
|
|
def test_closed_and_stale_callbacks_are_quarantined_under_lock(self):
|
|
pipe = (ROOT / 'native/wine_pipe_host.c').read_text()
|
|
callbacks = []
|
|
for name, marker in (
|
|
('pipe_read_current', ' ++gw_wire_pipe_data.read_calls;'),
|
|
('pipe_write_current', ' ++gw_wire_pipe_data.write_calls;'),
|
|
):
|
|
body = function(pipe, name)
|
|
prefix = body[:body.index(marker)]
|
|
exit_code = body[body.rindex('\ndone:'):]
|
|
callbacks.append(prefix + ' ++admitted;\n' + exit_code)
|
|
|
|
source = r'''
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#define WINAPI
|
|
#include "wine_pipe_host.h"
|
|
typedef int SRWLOCK;
|
|
typedef int32_t NTSTATUS;
|
|
struct gw_wire_call { int unused; };
|
|
static struct gw_pipe_control gw_wire_pipe_data;
|
|
static int32_t pipe_generation;
|
|
static SRWLOCK lock;
|
|
static unsigned acquired,released,closed_on_acquire,admitted,closes,receiver_checks;
|
|
static int gw_wire_pipe_receiver_allowed(uint64_t receiver){
|
|
++receiver_checks;return receiver!=0;
|
|
}
|
|
static void AcquireSRWLockExclusive(SRWLOCK* p){
|
|
(void)p;++acquired;
|
|
if(closed_on_acquire)gw_wire_pipe_data.closed=1;
|
|
}
|
|
static void ReleaseSRWLockExclusive(SRWLOCK* p){(void)p;++released;}
|
|
static void close_pipe(int error){(void)error;++closes;}
|
|
#define CHECK(x) do{if(!(x)){fprintf(stderr,"assertion line %d\n",__LINE__);return 1;}}while(0)
|
|
'''
|
|
source += function(pipe, 'owned') + '\n' + '\n'.join(callbacks)
|
|
source += r'''
|
|
static void reset(void){
|
|
gw_wire_pipe_data=(struct gw_pipe_control){.abi=1,.size=sizeof(gw_wire_pipe_data),.stage=1,.closed=1,
|
|
.owner=1,.pipe=1,.connection=1,.queue=1};
|
|
pipe_generation=3;
|
|
acquired=released=closed_on_acquire=admitted=closes=receiver_checks=0;
|
|
}
|
|
int main(void){
|
|
struct gw_pipe_control before;
|
|
uint64_t native_pipe[3],native_connection[1],native_queue[1];
|
|
struct gw_pipe_view empty={0};
|
|
reset();before=gw_wire_pipe_data;
|
|
/* Deliberately inaccessible borrowed pointers expose a premature read. */
|
|
pipe_read_current((void*)1,(void*)1,3);
|
|
pipe_write_current((void*)1,(void*)1,1,3);
|
|
CHECK(acquired==2 && released==2 && !admitted && !closes && !receiver_checks);
|
|
CHECK(!memcmp(&before,&gw_wire_pipe_data,sizeof(before)));
|
|
CHECK(!owned((void*)1));
|
|
reset();gw_wire_pipe_data.closed=0;closed_on_acquire=1;
|
|
pipe_read_current((void*)1,(void*)1,3);
|
|
CHECK(acquired==1 && released==1 && !admitted && !closes && !receiver_checks);
|
|
reset();gw_wire_pipe_data.closed=0;closed_on_acquire=1;
|
|
pipe_write_current((void*)1,(void*)1,1,3);
|
|
CHECK(acquired==1 && released==1 && !admitted && !closes && !receiver_checks);
|
|
reset();gw_wire_pipe_data.closed=0;
|
|
pipe_read_current((void*)1,(void*)1,2);
|
|
pipe_write_current((void*)1,(void*)1,1,2);
|
|
CHECK(acquired==2 && released==2 && !admitted && !closes && !receiver_checks);
|
|
/* Live admission remains available with the existing exact identities. */
|
|
native_connection[0]=0x1450396b0ULL;
|
|
native_queue[0]=0x1234;
|
|
native_pipe[0]=0;native_pipe[1]=0x1234;native_pipe[2]=(uintptr_t)native_connection;
|
|
gw_wire_pipe_data.owner=0x1234;gw_wire_pipe_data.pipe=(uintptr_t)native_pipe;
|
|
gw_wire_pipe_data.connection=(uintptr_t)native_connection;
|
|
gw_wire_pipe_data.queue=(uintptr_t)native_queue;
|
|
pipe_read_current(native_pipe,&empty,3);
|
|
pipe_write_current(native_pipe,&empty,1,3);
|
|
CHECK(admitted==2 && !closes && acquired==4 && released==4);
|
|
puts("PASS closed and stale callback quarantine; live admission preserved");
|
|
return 0;
|
|
}
|
|
'''
|
|
with tempfile.TemporaryDirectory() as folder:
|
|
c = Path(folder) / 'callbacks.c'
|
|
exe = Path(folder) / 'callbacks'
|
|
c.write_text(source)
|
|
built = subprocess.run([
|
|
'cc', '-std=c11', '-Wall', '-Wextra', '-Werror',
|
|
'-Wno-unused-variable', '-Wno-unused-function',
|
|
'-I' + str(ROOT / 'native'), str(c), '-o', str(exe),
|
|
], capture_output=True, text=True)
|
|
self.assertEqual(built.returncode, 0, built.stderr)
|
|
result = subprocess.run([str(exe)], capture_output=True, text=True)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
self.assertIn('PASS closed and stale callback quarantine', result.stdout)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|