#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Ask a running Snapintosh boot to stop early, from the Mac, while P_CALL runs. The launcher is blocked in q1n1's P_CALL for the whole run and q1n1 is not servicing its proxy then. A launch with SNAP_EARLY_STOP=host makes the monitor poll q1n1's call service from CPU0's timer tick; q1n1 answers UDP port 4920 on the proxy's own link-local addresses (q1n1 platform/uefi/call-service.h). This sends QUERY (learn the armed session), then STOP for that session, and waits for q1n1's acknowledgement. The monitor then ends the run through the watchdog's own stop (compat/early-stop.h): every CPU quiesces, RAM is kept, and the launcher's P_CALL returns with exit 12 and this reason recorded. python3 tools/request-stop.py --device udp://en5 --reason "WindowServer is up" python3 tools/request-stop.py --device udp://en5 --query python3 tools/request-stop.py --device udp://en5 --reason TEXT \\ --launch-record build/PREFIX-early-stop-launch.json --launch-record refuses to stop anything but that launch's session. Without it the armed session is whatever run is current. The acknowledgement proves q1n1 latched the request; the launcher's return is what proves the run stopped. Exit status: 0 latched (by this request or an earlier one), 2 refused or not armed, 3 no answer, 1 bad arguments. Prints one JSON object. """ import argparse import json import os import secrets import socket import struct import sys import time import zlib PORT = 4920 TARGET = 'fe80::4919' # q1n1's fixed link-local address REQUEST = struct.Struct(' 63: text = text[:-1] raw = text.encode('utf-8') return raw def encode(op, nonce, session=0, reason=0, delay=0, text=''): if op not in (QUERY, STOP) or not 0 <= delay <= 0xffffffff or not 0 <= reason <= 0xffffffff: raise ValueError('bad request fields') body = REQUEST.pack(REQUEST_MAGIC, VERSION, op, nonce, session, reason, delay, text_field(text), 0, 0) return body[:96] + struct.pack('