Compare commits
1 Commits
agent/fix/
...
agent/bitt
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59df857f7b |
@@ -617,6 +617,20 @@ int AOSS_Init_old(AOSSInitInput* input)
|
||||
}
|
||||
resultCode = 0xffffffff;
|
||||
} else {
|
||||
/* The original initialization path repeats this status check. */
|
||||
if (state != 0) {
|
||||
input->status = 0xf;
|
||||
if (s_accessPointConfig) {
|
||||
AOSSi_Free(s_accessPointConfig);
|
||||
s_accessPointConfig = 0;
|
||||
}
|
||||
if (s_accessPointList) {
|
||||
AOSSi_Free(s_accessPointList);
|
||||
s_accessPointList = 0;
|
||||
}
|
||||
resultCode = 0xffffffff;
|
||||
goto finish_initialization;
|
||||
}
|
||||
s_accessPointConfig = (int *)AOSSi_Alloc(0x58);
|
||||
if (s_accessPointConfig == 0) {
|
||||
input->status = 0xf;
|
||||
@@ -724,19 +738,15 @@ handle_initial_link:
|
||||
AOSSi_Free(s_accessPointList);
|
||||
s_accessPointList = 0;
|
||||
}
|
||||
requestResult = 0;
|
||||
state = 0;
|
||||
do {
|
||||
AOSSRequestRecord* currentRecord = &requestRecords.records[requestResult];
|
||||
u16 transactionId;
|
||||
memcpy(requestRecords.bytes + state,input->optionData,6);
|
||||
transactionId = rand();
|
||||
currentRecord->transactionId = transactionId;
|
||||
receivedLength = SOHtoNs(transactionId);
|
||||
currentRecord->transactionId = receivedLength;
|
||||
requestResult++;
|
||||
state += sizeof(AOSSRequestRecord);
|
||||
} while (requestResult < 3);
|
||||
{
|
||||
int recordIndex;
|
||||
for (recordIndex = 0; recordIndex < 3; recordIndex++) {
|
||||
memcpy(requestRecords.records[recordIndex].address, input->optionData, 6);
|
||||
requestRecords.records[recordIndex].transactionId = rand();
|
||||
requestRecords.records[recordIndex].transactionId =
|
||||
SOHtoNs(requestRecords.records[recordIndex].transactionId);
|
||||
}
|
||||
}
|
||||
s_socket = SOSocket(2,2,0);
|
||||
if (s_socket < 0) {
|
||||
input->status = 0xf;
|
||||
@@ -801,7 +811,7 @@ perform_request:
|
||||
if (s_socketStarted == 1) {
|
||||
s_socketStarted = 0;
|
||||
requestResult = SOCleanup();
|
||||
if (-1 < requestResult) goto request_socket_cleanup_complete;
|
||||
if (requestResult >= 0) goto request_socket_cleanup_complete;
|
||||
requestResult = -1;
|
||||
}
|
||||
else {
|
||||
@@ -890,7 +900,6 @@ request_socket_cleanup_complete:
|
||||
resultCode = 0xffffffff;
|
||||
goto finish_initialization;
|
||||
}
|
||||
initialSleep = remainingWait <= 100 ? remainingWait : 100;
|
||||
AOSSi_Sleep(remainingWait > 100 ? 100 : remainingWait);
|
||||
if (remainingWait > 100) initialSleep = 100;
|
||||
else initialSleep = remainingWait;
|
||||
@@ -943,73 +952,76 @@ request_socket_cleanup_complete:
|
||||
goto finish_initialization;
|
||||
}
|
||||
}
|
||||
requestResult = s_socket;
|
||||
switch (protocolState) {
|
||||
case 0:
|
||||
if (s_operationState != 2) {
|
||||
s_operationState = 2;
|
||||
AOSSi_Status(2);
|
||||
}
|
||||
requestResult = AOSSSendDiscoveryRequest(networkAddresses,&requestRecords,requestResult);
|
||||
break;
|
||||
case 1:
|
||||
if (s_operationState != 3) {
|
||||
s_operationState = 3;
|
||||
AOSSi_Status(3);
|
||||
}
|
||||
requestResult = AOSSSendHelloRequest(networkAddresses,&requestRecords,requestResult);
|
||||
{
|
||||
int sendResult;
|
||||
int requestSocket = s_socket;
|
||||
switch (protocolState) {
|
||||
case 0:
|
||||
if (s_operationState != 2) {
|
||||
s_operationState = 2;
|
||||
AOSSi_Status(2);
|
||||
}
|
||||
sendResult = AOSSSendDiscoveryRequest(networkAddresses,&requestRecords,requestSocket);
|
||||
break;
|
||||
case 1:
|
||||
if (s_operationState != 3) {
|
||||
s_operationState = 3;
|
||||
AOSSi_Status(3);
|
||||
}
|
||||
sendResult = AOSSSendHelloRequest(networkAddresses,&requestRecords,requestSocket);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
if (s_operationState != 5) {
|
||||
s_operationState = 5;
|
||||
AOSSi_Status(5);
|
||||
}
|
||||
packetWords = s_responseBuffer;
|
||||
memset(s_responseBuffer,0,0x5dc);
|
||||
memcpy(messageIdentity,&requestRecords.records[2],8);
|
||||
manufacturerLength = strlen(s_manufacturer);
|
||||
AOSSXorBufferWithKey(messageIdentity,8,s_manufacturer,manufacturerLength);
|
||||
receivedLength = SOHtoNs(1);
|
||||
packetWords->initialLength = receivedLength;
|
||||
packetWords->initialType = 0;
|
||||
packetWords->initialSequence = 0;
|
||||
packetWords->responseLength = SOHtoNs(0x3000);
|
||||
packetWords->responseType = 0;
|
||||
packetWords->finalLength = SOHtoNs(0);
|
||||
packetWords->finalSequence = SOHtoNs(0);
|
||||
packetWords->reserved = 0;
|
||||
packetWords->messageType = 0x11;
|
||||
memcpy(packetWords->messageIdentity,messageIdentity,8);
|
||||
memset(&replyAddress,0,8);
|
||||
replyAddress.family = 2;
|
||||
replyAddress.port = SOHtoNs(0x5790);
|
||||
replyAddress.address = SOHtoNl(s_runtime.ipAddress);
|
||||
if ((s8)s_runtime.active == 0) {
|
||||
replyAddress.address = 0xffffffff;
|
||||
}
|
||||
replyAddress.length = 8;
|
||||
SOSendTo(requestResult,packetWords,0x18,0,&replyAddress);
|
||||
requestResult = 0;
|
||||
break;
|
||||
case 2:
|
||||
if (s_operationState != 5) {
|
||||
s_operationState = 5;
|
||||
AOSSi_Status(5);
|
||||
}
|
||||
packetWords = s_responseBuffer;
|
||||
memset(s_responseBuffer,0,0x5dc);
|
||||
memcpy(messageIdentity,&requestRecords.records[2],8);
|
||||
manufacturerLength = strlen(s_manufacturer);
|
||||
AOSSXorBufferWithKey(messageIdentity,8,s_manufacturer,manufacturerLength);
|
||||
receivedLength = SOHtoNs(1);
|
||||
packetWords->initialLength = receivedLength;
|
||||
packetWords->initialType = 0;
|
||||
packetWords->initialSequence = 0;
|
||||
packetWords->responseLength = SOHtoNs(0x3000);
|
||||
packetWords->responseType = 0;
|
||||
packetWords->finalLength = SOHtoNs(0);
|
||||
packetWords->finalSequence = SOHtoNs(0);
|
||||
packetWords->reserved = 0;
|
||||
packetWords->messageType = 0x11;
|
||||
memcpy(packetWords->messageIdentity,messageIdentity,8);
|
||||
memset(&replyAddress,0,8);
|
||||
replyAddress.family = 2;
|
||||
replyAddress.port = SOHtoNs(0x5790);
|
||||
replyAddress.address = SOHtoNl(s_runtime.ipAddress);
|
||||
if ((s8)s_runtime.active == 0) {
|
||||
replyAddress.address = 0xffffffff;
|
||||
}
|
||||
replyAddress.length = 8;
|
||||
SOSendTo(requestSocket,packetWords,0x18,0,&replyAddress);
|
||||
sendResult = 0;
|
||||
|
||||
break;
|
||||
default:
|
||||
requestResult = -1;
|
||||
break;
|
||||
}
|
||||
if (requestResult == -1) {
|
||||
s_errorCode = protocolState + 0x1000;
|
||||
input->status = 0xf;
|
||||
if (s_accessPointConfig) {
|
||||
AOSSi_Free(s_accessPointConfig);
|
||||
s_accessPointConfig = (int *)0x0;
|
||||
break;
|
||||
default:
|
||||
sendResult = -1;
|
||||
break;
|
||||
}
|
||||
if (s_accessPointList) {
|
||||
AOSSi_Free(s_accessPointList);
|
||||
s_accessPointList = 0;
|
||||
if (sendResult == -1) {
|
||||
s_errorCode = protocolState + 0x1000;
|
||||
input->status = 0xf;
|
||||
if (s_accessPointConfig) {
|
||||
AOSSi_Free(s_accessPointConfig);
|
||||
s_accessPointConfig = (int *)0x0;
|
||||
}
|
||||
if (s_accessPointList) {
|
||||
AOSSi_Free(s_accessPointList);
|
||||
s_accessPointList = 0;
|
||||
}
|
||||
resultCode = 0xffffffff;
|
||||
goto finish_initialization;
|
||||
}
|
||||
resultCode = 0xffffffff;
|
||||
goto finish_initialization;
|
||||
}
|
||||
memset(packetBuffer,0,0x5f8);
|
||||
pollTime.seconds = timeoutMilliseconds / 1000;
|
||||
@@ -1028,10 +1040,12 @@ request_socket_cleanup_complete:
|
||||
if (0 < requestResult) goto process_received_packet;
|
||||
receivedPackets = receivedPackets + 1;
|
||||
if (receivedPackets > attemptCount) {
|
||||
switch (protocolState) {
|
||||
case 0: s_errorCode = 0xf; break;
|
||||
case 1: s_errorCode = 0x10; break;
|
||||
default: s_errorCode = 0x11; break;
|
||||
if (protocolState == 0) {
|
||||
s_errorCode = 0xf;
|
||||
} else if (protocolState == 1) {
|
||||
s_errorCode = 0x10;
|
||||
} else {
|
||||
s_errorCode = 0x11;
|
||||
}
|
||||
protocolResult = -1;
|
||||
goto close_protocol_socket;
|
||||
@@ -1098,8 +1112,7 @@ process_received_packet:
|
||||
}
|
||||
else {
|
||||
if (protocolState != requestResult) {
|
||||
protocolState = requestResult;
|
||||
if (requestResult != 2) goto perform_request;
|
||||
if (requestResult != 2) goto advance_protocol_state;
|
||||
if (s_socket != -1) {
|
||||
SOClose(s_socket);
|
||||
}
|
||||
@@ -1237,7 +1250,8 @@ wait_for_packet:
|
||||
goto finish_initialization;
|
||||
}
|
||||
AOSSi_Sleep(remainingWait > 100 ? 100 : remainingWait);
|
||||
initialSleep = remainingWait <= 100 ? remainingWait : 100;
|
||||
if (remainingWait > 100) initialSleep = 100;
|
||||
else initialSleep = remainingWait;
|
||||
}
|
||||
if (AOSSi_cancel_flag == 1) {
|
||||
input->status = 0xf;
|
||||
@@ -1294,15 +1308,18 @@ wait_for_packet:
|
||||
resultCode = 0xffffffff;
|
||||
goto finish_initialization;
|
||||
}
|
||||
advance_protocol_state:
|
||||
protocolState = requestResult;
|
||||
goto perform_request;
|
||||
}
|
||||
protocolState = requestResult;
|
||||
if (receivedPackets > waitSettings.halfwords.high) {
|
||||
switch (requestResult) {
|
||||
case 0: s_errorCode = 0xf; break;
|
||||
case 1: s_errorCode = 0x10; break;
|
||||
default: s_errorCode = 0x11; break;
|
||||
if (requestResult == 0) {
|
||||
s_errorCode = 0xf;
|
||||
} else if (requestResult == 1) {
|
||||
s_errorCode = 0x10;
|
||||
} else {
|
||||
s_errorCode = 0x11;
|
||||
}
|
||||
protocolResult = -1;
|
||||
goto close_protocol_socket;
|
||||
@@ -1322,8 +1339,7 @@ wait_for_packet:
|
||||
resultCode = 0xffffffff;
|
||||
goto finish_initialization;
|
||||
}
|
||||
if (retryDelay > 100) AOSSi_Sleep(100);
|
||||
else AOSSi_Sleep(retryDelay);
|
||||
AOSSi_Sleep(retryDelay > 100 ? 100 : retryDelay);
|
||||
if (retryDelay > 100) delayStep = 100;
|
||||
else delayStep = retryDelay;
|
||||
}
|
||||
@@ -1350,7 +1366,7 @@ close_protocol_socket:
|
||||
if (s_socketStarted == 1) {
|
||||
s_socketStarted = 0;
|
||||
state = SOCleanup();
|
||||
if (-1 < state) goto protocol_socket_cleanup_complete;
|
||||
if (state >= 0) goto protocol_socket_cleanup_complete;
|
||||
state = -1;
|
||||
}
|
||||
else {
|
||||
|
||||
102
tools/decomp-assist/aoss-init-reconstruction-20261002.md
Normal file
102
tools/decomp-assist/aoss-init-reconstruction-20261002.md
Normal file
@@ -0,0 +1,102 @@
|
||||
# AOSS initialization source reconstruction, 2026-10-02
|
||||
|
||||
Baseline 3d3448e3. Only src/scene/setting/AOSS.c changed; ATERM, AOSSLink,
|
||||
headers, metadata, and linking remain untouched. Read AGENTS and the AOSS,
|
||||
round-five/six/seven, and fz1 attempt records before starting.
|
||||
|
||||
## Retained source boundaries
|
||||
|
||||
1. Restore the repeated initial-address status check and its cleanup block.
|
||||
In the target AOSS_Init_old object, the first address-setup error path ends
|
||||
at 0x6EC, followed by a second check and cleanup at 0x6F0-0x730 before the
|
||||
access-point allocation at 0x734. This check is redundant on the successful
|
||||
edge, but the original retains the complete branch and cleanup. A short
|
||||
source comment explains why it is not folded away in the reconstruction.
|
||||
2. Give the send operation a local result separate from its socket descriptor.
|
||||
The target keeps the socket snapshot through send setup, but consumes each
|
||||
send return directly at the common result test. The previous source reused
|
||||
one long-lived variable for both roles and copied both call results into a
|
||||
saved register before testing them.
|
||||
3. Restore two explicit zero/one/default timeout-error chains. Target error
|
||||
dispatch tests state zero first, then one, rather than using the previous
|
||||
switch's range dispatch.
|
||||
4. Publish the next protocol state at the common reconnection join. The target
|
||||
carries the returned state through reconnect processing, then assigns the
|
||||
protocol-state local once. The old source assigned it before reconnect and
|
||||
repeated the assignment afterward.
|
||||
5. Traverse the three request records with one actual array index. Both the
|
||||
six-byte address copy and the transaction-ID conversion use the same record.
|
||||
The previous source maintained an independent byte offset as well as the
|
||||
array index, producing a redundant second induction variable.
|
||||
6. Restore retry and cleanup boundaries: one conditional-argument sleep call,
|
||||
no unused pre-sleep delay assignment, consistent large-delay-first update,
|
||||
and the target's nonnegative socket-cleanup test.
|
||||
|
||||
All changes are ordinary initialized C. No new qualifiers, helpers, assembly,
|
||||
register declarations, data padding, or source/metadata pins were used.
|
||||
|
||||
## Measurements
|
||||
|
||||
| Cumulative source form | Init fuzzy | Instructions / 1584 |
|
||||
| --- | ---: | ---: |
|
||||
| Baseline | 93.78725% | 1575 |
|
||||
| Timeout error chains | 94.41288% | 1571 |
|
||||
| Also scoped send result | 94.454544% | 1569 |
|
||||
| Also repeated address guard | 95.45013% | 1586 |
|
||||
| Also receive-state join | 95.51326% | 1585 |
|
||||
| Also request-record array traversal | 95.78409% | 1583 |
|
||||
| Also retry/cleanup boundaries | 96.18624% | 1581 |
|
||||
|
||||
The instruction count need not monotonically approach the target: several
|
||||
changes remove extra source instructions while the guard restores an omitted
|
||||
block. Final Init remains nonexact. Unit fuzzy improves 96.777916% -> 97.71665%.
|
||||
Exact functions remain 16/21, exact code 6436/16192, and data 3928/3928.
|
||||
Every other AOSS function and every other unit's report remains unchanged.
|
||||
|
||||
Rejected experiments, all restored:
|
||||
|
||||
- Moving the receive-state join alone regressed the original baseline; it
|
||||
improved the retained scope/guard reconstruction when retested there.
|
||||
- Grouping timeout/receive/descriptors into one real polling context regressed
|
||||
Init 95.51326 -> 95.29293. No stack-layout aggregate was retained.
|
||||
- Deriving the current request record from an explicit byte cursor regressed
|
||||
95.51326 -> 95.423615; the final ordinary array traversal improved it.
|
||||
- Original extracted BSS symbols have global binding, but making the actual
|
||||
CRC table global changed no instructions. Global packet-state/runtime
|
||||
definitions changed no instructions and regressed data; all restored.
|
||||
|
||||
## Hello and remaining limits
|
||||
|
||||
AOSSSendHelloRequest stays at 92.190475%, 271/273 instructions. Its target
|
||||
materializes separate runtime/CRC/key-state bases; the source hoists a shared
|
||||
BSS base. The fresh audit found no omitted packet, CRC, key-schedule, or socket
|
||||
operation. Prior loop/temporary/register permutations were not repeated.
|
||||
|
||||
Init still differs in default-option object boundaries, redundant target
|
||||
link-result branches, polling scratch lifetimes/stack slots, and register and
|
||||
instruction scheduling. The preexisting initialized result fallback remains:
|
||||
no undefined read was introduced to imitate the target's uncertain early
|
||||
register use. No full-function, unit, or project-completion claim is made.
|
||||
|
||||
## Verification
|
||||
|
||||
- Configured only 43U with ../toolchain/wibo-build/wibo
|
||||
- WIBO_SJIS_MISSING_IMPORTS=1 ../.venv/bin/ninja all_source build/43U/report.json build/43U/ok
|
||||
- Pool identical (one ordinary .data string); every allocated data section is
|
||||
byte-identical to the fresh baseline and all five report 100%
|
||||
- All 16 exact functions freshly verified with ctxdiff, zero differences
|
||||
- Literal audit: 10 arguments across 16 exact functions; no skipped functions,
|
||||
candidates, or errors
|
||||
- Complete reports: only AOSS changes; its only improved function is Init;
|
||||
no per-function, code, data, or cross-unit regression
|
||||
- Focused native C harness passes 65536 retry spans, 20003 timeout-error states,
|
||||
and 65536 three-record initializations with boundary canaries. These check
|
||||
the rewritten local algorithms; they do not simulate network initialization
|
||||
- Harness source/executable: /tmp/aoss-reconstruction-harness.c and the same
|
||||
path without .c in the current executor
|
||||
- git diff --check passes
|
||||
- DOL SHA1: 26116613f624061ba99c8d1a299aaa6efa85670d
|
||||
|
||||
GATE: nonregression, exact-function preservation, complete data, pool, focused
|
||||
native tests, full 43U build, and DOL checks pass. Frozen for independent parent
|
||||
review; this is partial source reconstruction only.
|
||||
Reference in New Issue
Block a user