Merge remote-tracking branch 'origin/main' into pr-fix-90

This commit is contained in:
lucannez64 committed 2026-10-25 19:09:59 +01:00
commit 76073e6a45
62 files changed
+6534 -505

No files matched your search

+3 -3
View File
@@ -1,3 +1,3 @@
# Unified-diff context uses a single space for an empty source line.
# Do not report that patch syntax as trailing source whitespace.
patches/*.patch whitespace=-blank-at-eol
# Unified-diff context adds a space before source tabs and empty lines.
# Do not report that patch syntax as source whitespace errors.
patches/*.patch whitespace=-blank-at-eol,-space-before-tab
+18
View File
@@ -3,6 +3,12 @@ on: [push, pull_request]
permissions:
contents: read
jobs:
nix-fonts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@3c6342b75005b9cc7c7d4069c3e9179247c89012 # v31
- run: nix build .#checks.x86_64-linux.fonts --no-link -L
validate:
runs-on: ubuntu-latest
steps:
@@ -10,15 +16,27 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Require C++ regression compiler
run: |
command -v c++
c++ --version
- run: python scripts/validate.py
- run: python tools/riot-input-offline-check.py
- run: python tools/riot-launcher-offline-check.py
- run: python tools/riot-runtime-cleanup-offline-check.py
- run: python tools/riot-cdn-dns-offline-check.py
- run: python -m unittest discover -s tests -p 'test_nix_fonts.py'
- run: python -m unittest discover -s tests -p 'test_nix_repairs.py'
- run: python -m unittest discover -s tests -p 'test_hidden_riot_recovery.py'
- run: python -m unittest discover -s tests -p 'test_desktop_run.py'
- run: python -m unittest discover -s tests -p 'test_desktop_entry.py'
- run: python -m unittest discover -s tests -p 'test_urlsession_runner.py'
- run: python -m unittest discover -s tests -p 'test_system_profiler.py'
- run: python -m unittest discover -s tests -p 'test_metal_device_info.py'
- run: python -m unittest discover -s tests -p 'test_indium_address_shadow.py' -v
- run: python -m unittest discover -s tests -p 'test_exec_guest.py'
- run: python -m unittest discover -s tests -p 'test_close_league_client_in_game.py'
- run: python -m unittest discover -s tests -p 'test_recover_stale_client.py'
- run: python -m unittest discover -s tests -p 'test_clean_stale_helpers.py'
- run: python -m unittest discover -s tests -p 'test_hide_league_client_in_game.py'
- run: python -m unittest discover -s tests -p 'test_client_in_game_tricks.py'
+67
View File
@@ -0,0 +1,67 @@
# Contributing
Thank you for improving `darling-lol`. The project is an unofficial
interoperability effort; contributions must keep it in that scope.
## Before you start
- Read [`docs/COMPLIANCE.md`](docs/COMPLIANCE.md) and
[`docs/INTEROPERABILITY.md`](docs/INTEROPERABILITY.md).
- Do not add Riot client files, game binaries, game assets, logos, screenshots,
gameplay audio/video, account data, tokens or credentials.
- Do not add DRM/anti-cheat/authentication circumvention, telemetry spoofing,
credential handling, or gameplay automation. Changes that present the project
as an evasion tool are out of scope.
- Keep existing copyright, license and attribution notices. New third-party code
or assets need a license and provenance note in the pull request.
## License of contributions
- Original integration tooling (scripts, tools, tests, docs and project artwork)
is licensed under **GPL-3.0-only**.
- Patches to upstream components are licensed under the license of the upstream
file(s) they modify. If a patch touches files under different licenses, each
hunk keeps the license of its target file.
- By submitting a contribution, you confirm that you have the right to submit it
and agree to license it under the applicable terms above.
## Developer Certificate of Origin
Sign off every commit:
```sh
git commit -s -m "area: short description"
```
The sign-off certifies the Developer Certificate of Origin 1.1
(<https://developercertificate.org/>): you created the contribution or have the
right to submit it under the project's license, and you understand that the
contribution and its sign-off are public and may be redistributed.
## Checks
Run the source audit and the relevant tests before opening a pull request:
```sh
python3 scripts/validate.py
python3 -m unittest discover -s tests -p 'test_*.py'
```
The audit checks tracked source, rendered Python/shell, pinned revision format,
patch existence and patch parsing. It does not check patch applicability to the
pinned revisions. Do not bypass it; fix the source or document the exception in
the pull request.
## Pull requests
- Keep changes focused and describe the compatibility problem and the fix.
- Mention any change that touches platform identity, sandbox/AMFI probes,
anti-cheat or account risk. Do not describe it as stealth, evasion, spoofing
or an anti-cheat bypass.
- If you change a patch, run `python3 scripts/prepare.py --check-only` against
an existing pinned source checkout to verify that it applies to the pinned
revision.
- If you change a user-facing variable, keep the old name as a deprecated alias
for at least one release.
This is not legal advice. See [`docs/INTEROPERABILITY.md`](docs/INTEROPERABILITY.md).
+13 -1
View File
@@ -4,4 +4,16 @@
The manifest points to public upstream source repositories. This repository includes source differences and authored integration/research tools, not a copy of the upstream runtime, Apple's SDK binaries or Riot's client/game assets. Build artifacts and local installs are excluded.
Some compatibility tools contain short instruction signatures or API names used to recognize the user's installed client. The client itself is not redistributed. Installation downloads from Riot's distribution service directly.
Some compatibility tools refer to public API names and constants of the user's installed client. The client itself is not redistributed. Installation downloads from Riot's distribution service directly.
## Historical material
Earlier revisions of this repository included a third-party game logo and an embedded gameplay clip. Both were removed from the current tree; the current tree uses an original project mark and contains no gameplay media. Git history and third-party forks may still contain those earlier revisions. They are not part of the current project, are not licensed by this project, and should not be reused.
## Trademarks
League of Legends and Riot Games are trademarks or registered trademarks of Riot Games, Inc.
This project is an unofficial compatibility effort and is not affiliated with, endorsed by, or
sponsored by Riot Games.
See [compliance and terminology guidance](docs/COMPLIANCE.md) for scope and review expectations, and [interoperability and compliance scope](docs/INTEROPERABILITY.md) for the project's practices on interoperability, copyright, access controls and trademarks. Neither document is legal advice.
+66 -7
View File
@@ -16,14 +16,14 @@
>
> Even with all of that, you will probably still get permabanned.
>
> **3. Takedown.** Riot may well shut this project down. If that happens, I will publish a fork of Darling containing only the changes made here (none of them breach anything), and release the small script as a gist or similar.
> **3. Continuity.** If this repository is discontinued, the patches remain available under their upstream licenses, and the original integration tooling remains available under GPL-3.0.
>
> **4. To Riot.** If you are reading this, it means a lot of people want to play your game on Linux and are disappointed that they currently can't. As with macOS for your other games (TFT, Valorant), it feels like Riot doesn't care about a part of its players who have been waiting the longest. If you want to fix this, make LoL Next compatible with Linux, either natively or through a layer like Proton. Yes, that includes your kernel anticheat: Epic Games did it with Easy Anti-Cheat. Follow the trend. This is the year of Linux, and people shouldn't be locked out of a platform or forced to dual boot for a single game.
> Since Riot have heard of the repo if you want to contact me you can at [email protected] (especially if you want to do an official or supported version of league of legends on linux)
If someone else wants to contact me know that i'm open to jobs, part-time remote only as a employee and full time remote as a freelancer for a mission
https://github.com/user-attachments/assets/140df3e0-3790-46b6-bab5-578139b84a7c
A short manual ARAM run and the current compatibility status are documented in [docs/STATUS.md](docs/STATUS.md).
Experimental source patches and tools for running the **macOS League of Legends client on x86-64 Linux through Darling**.
@@ -36,11 +36,11 @@ This is a development snapshot, not a finished launcher. Riot and League clients
- Reusable server receive buffers and Darwin allocator hints translated to Linux lazy reclamation.
- Build/install/launch wrappers, atomic incremental installers and standalone regression probes.
Game files, Riot installers, account databases, tokens, local prefixes, captures and compiled binaries are not included. Install the game manually through Riot. The normal launcher does not enable an Electron inspector or start UI automation helpers. The launcher clears `DYLD_INSERT_LIBRARIES` and retains Darling runtime library/framework overrides; this is not a claim of approval by Riot.
Game files, Riot installers, account databases, tokens, local prefixes, captures and compiled binaries are not included. Install the game manually through Riot. The normal launcher does not enable an Electron inspector or start UI automation helpers; the opt-in window-management helpers described below are off by default and do not patch client binaries. The launcher clears `DYLD_INSERT_LIBRARIES` and retains Darling runtime library/framework overrides; this is not a claim of approval by Riot.
## Requirements
- x86-64 Linux **5.14 or newer**, an X11 session or Xwayland, and a working hardware Vulkan/OpenGL driver. AMD RADV has been exercised; other drivers are not validated. Hybrid laptops usually render on the integrated GPU unless started with PRIME offload; NVIDIA is not validated. See [hybrid graphics](docs/TROUBLESHOOTING.md#hybrid-graphics-laptops-amdintel-igpu--nvidia).
- x86-64 Linux **5.14 or newer**, an X11 session or Xwayland, and a working hardware Vulkan/OpenGL driver. AMD RADV and the NVIDIA driver (proprietary and open kernel modules) have been exercised, see [NVIDIA](docs/TROUBLESHOOTING.md#nvidia); other drivers are not validated. Hybrid laptops usually render on the integrated GPU unless started with PRIME offload. See [hybrid graphics](docs/TROUBLESHOOTING.md#hybrid-graphics-laptops-amdintel-igpu--nvidia).
- Git + Git LFS, Bash, curl, unzip, CMake, Make, Clang/LLD, LLVM development files, a C/C++ compiler, Python 3.12+ and the Darling build dependencies. The patch includes LLVM 22/23 branch-opcode compatibility; the new PC used LLVM/Clang 23. Node.js is needed only for the offline JavaScript checks.
- X11/XCB/SHM development files for the current runtime helpers.
- Enough free disk for Darling sources/build, Git LFS assets and the game: budget at least 50 GB. Building is substantially larger than this source-only repository.
@@ -109,9 +109,52 @@ First installation and future Riot updates can still encounter compatibility gap
For another region, set `RCLOL_REGION` and `RCLOL_LOCALE` before launch. For example `RCLOL_REGION=NA RCLOL_LOCALE=en_US ./scripts/run.sh`. Linux display selection follows `$DISPLAY`; the legacy launcher fallback is `:1`.
If the game or Riot client was closed but `darlingserver` is still running, opt in to partial recovery before the next launch:
```sh
RCLOL_RECOVER_STALE_CLIENT=1 ./scripts/run.sh
```
It stops only a windowless Riot/League/CEF tree at least 60 seconds old,
preserves `darlingserver`, launchd/mldr, sockets and `.init.pid`, and then
starts the product normally. It recognizes `LeagueClientUx`, `Riot Client` and
`RiotClientServices` windows, does nothing while a game or managed client window
is present, and fails closed when X11 properties cannot be read. See
[troubleshooting](docs/TROUBLESHOOTING.md#client-remains-running-without-a-window).
If repeated launches leave several `close-league-client-in-game.py` watchers,
opt in to removing the orphaned ones before the new helper starts:
```sh
RCLOL_CLEAN_STALE_HELPERS=1 ./scripts/run.sh
```
It only removes helpers of this prefix whose parent is `init`/`systemd` (the
launcher that started them has exited). A helper of a live launcher, another
prefix, the game, Riot/League/CEF, `darlingserver` and the runtime are never
touched. See [troubleshooting](docs/TROUBLESHOOTING.md#multiple-client-in-game-helpers).
For automatic client handling during a match, opt in with one switch:
```sh
RCLOL_CLIENT_IN_GAME_TRICKS=1 ./scripts/run.sh
```
It reads `lol-user-experience` from the installed League client's
`LCULocalPreferences.yaml`. When `potatoModeEnabled` is true, it closes the
client UI if `closeLeagueClientDuringGame` is true, and hides the
`LeagueClientUx`/`Riot Client` X11 windows when that value is false. Missing or
invalid preference values, disabled client optimizations and unreadable files
select no action. The `RCLOL_CLOSE_CLIENT_IN_GAME` and
`RCLOL_HIDE_CLIENT_IN_GAME` low-level switches remain available when the
automatic switch is not set. The helper exits after ten minutes without a
client or match once it has seen one. See
[troubleshooting](docs/TROUBLESHOOTING.md#automatic-client-handling-during-a-match)
for the measured effect and caveats.
## Testing
Start with standalone regression checks, then play a match manually. See [testing](docs/TESTING.md). Do not attach a debugger, query client APIs, inject diagnostic hooks or automate client/game input. This project ships no client-side automation, inspection or profiling helpers.
Start with standalone regression checks, then play a match manually. See [testing](docs/TESTING.md). Do not attach a debugger, query client APIs, inject diagnostic hooks or automate client/game input. The project includes standalone compatibility probes and the opt-in host-side window-management helpers described above, but no client injection hooks, client API automation or input automation; the normal launcher enables none of them.
FPS counters, game presentation requests and physical display refresh are different measurements. Record average and p99 frame times, the active scene, graphics settings, charger/power state and whether the game stayed focused. See [current status](docs/STATUS.md).
@@ -136,10 +179,26 @@ scripts/ portable entry points
upstream/manifest.json exact base revisions and patch ownership
patches/ current source changes, one patch per repository
tools/ runtime templates, installers and standalone regression probes
docs/ setup, testing, status and licensing notes
docs/ setup, testing, status, compliance and interoperability notes
build/ local sources, outputs and rendered tools (ignored)
```
Darling/upstream components retain their existing licenses; see [third-party notes](NOTICE.md). Original integration tooling is distributed under GPL-3.0; patches retain the licensing of their target files. This project is not affiliated with Riot Games.
Darling/upstream components retain their existing licenses; see [third-party notes](NOTICE.md). Original integration tooling is distributed under GPL-3.0; patches retain the licensing of their target files.
## Interoperability and compliance
This project is an unofficial interoperability effort. It distributes source patches for Darling and original tooling, not the Riot client, game code, assets or accounts. The normal launcher does not patch the client, game, CEF or anti-cheat. Users obtain the client from Riot and are responsible for complying with Riot's terms; account restrictions are possible. See [interoperability and compliance scope](docs/INTEROPERABILITY.md) and [compliance guidance](docs/COMPLIANCE.md). Neither document is legal advice.
## Trademarks
League of Legends and Riot Games are trademarks or registered trademarks of Riot Games, Inc.
This project is an unofficial compatibility effort and is not affiliated with, endorsed by, or
sponsored by Riot Games. No game client, game assets, or account data are distributed in this
repository.
See [compliance and terminology guidance](docs/COMPLIANCE.md) and [interoperability and compliance scope](docs/INTEROPERABILITY.md) for the project's scope and review expectations.
## Donations
If you want to help me live or just pay me a coffee
you can at [Ko-Fi](https://ko-fi.com/lucannez64)
+2 -2
View File
@@ -1,5 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" role="img" aria-label="darling-lol">
<title>darling-lol</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" role="img" aria-label="Darling Launcher">
<title>Darling Launcher</title>
<rect x="8" y="8" width="112" height="112" rx="26" fill="#0f172a"/>
<path fill-rule="evenodd" fill="#2dd4bf" d="M38 30h20c21 0 34 15 34 34s-13 34-34 34H38V30zm18 18v32h2c9 0 16-7 16-16s-7-16-16-16h-2z"/>
<rect x="30" y="90" width="68" height="8" rx="4" fill="#818cf8"/>

Before

Width:  |  Height:  |  Size: 411 B

After

Width:  |  Height:  |  Size: 421 B

+76
View File
@@ -0,0 +1,76 @@
# Scope and compliance guidance
This project is an unofficial compatibility layer for running the macOS League of Legends
client on Linux through Darling. It is not affiliated with, endorsed by, or sponsored by Riot
Games, Inc. See [interoperability and compliance scope](INTEROPERABILITY.md) for the project's
practices on interoperability, copyright, access controls and trademarks. Neither document is
legal advice.
## Scope
- The project is about compatibility: making the client run, render and behave correctly on
Linux.
- It does not aim to circumvent DRM, anti-cheat, licensing, telemetry, authentication, or other
platform security controls, and it does not distribute a game client, game assets, or account
data.
- It does not forge authentication tokens or server-side integrity attestations. The synthetic
platform identity is local compatibility metadata, not an Apple-issued identifier or a Riot
credential. This repository does not pass it as Riot authentication data; the official
client's later handling of guest-visible values is outside this repository's scope.
- Do not describe or present the project as a tool for evading detection, preventing bans,
bypassing DRM, or defeating anti-cheat. Do not promise that an account will not be banned.
## Terminology
Prefer accurate compatibility language:
| Prefer | Avoid |
|---|---|
| compatibility issue, client check, platform identity | detection vector, stealth, evasion, bypass |
| hardware/platform reporting | spoofing, telemetry leak |
| runtime/launcher fix | anti-cheat bypass |
Technical facts can be described precisely without framing the work as evasion. If a change
touches a client check or a platform identity, say what it does and why it is needed for
compatibility.
## Known local limitations
- Darling has no macOS MAC/Seatbelt/AMFI framework. The compatibility layer reports the local
`___mac_syscall` probe as satisfied so Chromium/CEF can start. This does **not** implement a
sandbox and does not make the guest secure. Treat the guest as unsandboxed and do not run
untrusted content. It does not interact with Riot's servers or bypass a Riot control.
- Platform-identity values generated by `tools/configure-darling-platform.py` are synthetic and
local. They are not Apple-issued identifiers, credentials or authentication tokens; do not use
them with Apple services or to impersonate real hardware.
- The opt-in hide helper manages local client windows while a match runs. The opt-in close helper
terminates eligible League client UI processes. Neither helper patches client binaries, CEF,
anti-cheat or DRM, and both helpers are off by default.
## Assets and third-party material
- Do not add or link third-party game assets: logos, icons, fonts, screenshots, gameplay
audio/video, client files, game data, or account data.
- Project icons and artwork must be original. Forks must use their own name and icon; see the
trademark notice in `README.md` and `NOTICE.md`.
- Do not commit local prefixes, logs, tokens, captures, or compiled client/runtime binaries.
- Keep upstream copyright, license and attribution notices.
- Donations are voluntary and support the free tooling. They do not sell the game, a license,
access or priority.
## Pull requests and issues
- Describe the compatibility problem and the fix. Avoid "stealth", "spoof", "evade",
"undetectable", or "unbannable" framing.
- Maintainers may ask for wording changes before merging. This is about keeping the project's
scope accurate, not about hiding technical details.
- Contributions that add third-party assets or present the project as a DRM/anti-cheat
circumvention tool are out of scope for this repository.
- Sign off commits under the Developer Certificate of Origin; see
[`CONTRIBUTING.md`](../CONTRIBUTING.md). By contributing, you confirm that you have the right
to submit the work and license it under the project's terms.
## Note
This document describes project scope and review expectations. It is not legal advice. See
[interoperability and compliance scope](INTEROPERABILITY.md) and [`NOTICE.md`](../NOTICE.md).
+176
View File
@@ -0,0 +1,176 @@
# Interoperability and compliance scope
> This document explains how the project stays within interoperability and
> responsible-use practices. It is **not legal advice**. Software, contract and
> platform rules are fact-specific and differ by country. Consult qualified
> counsel before distributing, modifying or using this project.
## 1. Purpose
`darling-lol` (<https://github.com/lucannez64/darling-lol/>) is an unofficial
interoperability effort. It applies source patches to
[Darling](https://github.com/darlinghq/darling), a free-software macOS
compatibility layer, so that the official macOS Riot client can run on
x86-64 Linux. The user obtains the client from Riot and signs in through Riot's
own client and services.
The project is not a game, a game server, an account service, a launcher for
pirated content, or a substitute for Riot's platform. It does not provide Riot
accounts, authentication, matchmaking, payments, telemetry or game servers.
## 2. What we distribute and what we do not
We keep the project on the interoperability side by distributing only:
- source patches for Darling, a free-software compatibility layer;
- original integration, build and test tooling;
- project artwork;
- documentation and license notices.
We do **not** distribute, bundle, mirror or sublicense:
- the Riot client or game binaries;
- game assets, art, audio, video, fonts or data;
- account databases, tokens or credentials;
- Riot installers or installers for pirated content.
The user obtains the client from Riot and installs it through Riot's own
installer. The project does not provide accounts, authentication, matchmaking,
payments, telemetry or game servers, and it does not sell the game, a license,
access or priority.
## 3. Platform identity
Darling needs macOS-like platform metadata. `tools/configure-darling-platform.py`
can generate synthetic serial numbers, UUIDs and related fields, or import
values supplied by the user, so that the guest environment is internally
consistent.
These values are **local compatibility metadata**:
- they are not Apple-issued identifiers, credentials or authentication tokens;
- they are not used with Apple services and should not be used to impersonate
real hardware;
- this repository does not pass them to Riot as authentication data. The values
are exposed to guest applications through IOKit, and the official client's
later handling of them is outside this repository's scope. The official client
authenticates through Riot's own flow.
See `docs/PLATFORM_IDENTITY.md` for the schema, validation rules and warnings.
## 4. Local sandbox/AMFI probe
Darling has no macOS MAC, Seatbelt or AMFI framework. Chromium/CEF, which the
Riot client embeds, probes `___mac_syscall`. An `ENOSYS` response is treated as
fatal and prevents CEF helper processes from starting. The compatibility layer
therefore reports the local probe as satisfied. The relevant code and comments
are in `patches/xnu.patch` (`mac_syscall.c`).
This compatibility shim:
- does not implement a sandbox and does not make the guest secure;
- does not interact with Riot's servers or alter Riot's account, payment or
server-side integrity flows;
- does not grant access to Riot's content or services.
Treat the guest as **unsandboxed**. Do not run untrusted content inside it. This
is a local compatibility limitation, not a claim of security. See
`docs/COMPLIANCE.md` for the project's terminology and scope guidance.
## 5. Copyright and licenses
We keep the project's copyright and licensing position clear:
- the game, client, code and assets remain Riot's; we do not reproduce, store,
distribute or commercialise them;
- we distribute patches to free-software Darling and original tooling, not a
copy of the game or the upstream runtime;
- each patch keeps the license and notices of the upstream file it modifies;
original tooling is GPL-3.0-only;
- we keep the upstream license and attribution notices in the patched files and
describe the project's licensing position in `NOTICE.md`;
- we do not remove copyright or license notices from patched files;
- we review good-faith licensing and removal requests.
We do not sell the game, a license, access or priority. Donations are voluntary
and support development of the free tooling; they do not purchase the game or
any Riot service.
## 6. Access, authentication and integrity controls
The project is designed for compatibility, not for defeating access,
authentication, payment or integrity controls:
- we do not provide tools or features whose purpose is to defeat those controls;
- we do not forge authentication tokens, session data, account data or
server-side integrity attestations;
- we do not proxy or emulate Riot accounts, matchmaking, payments, telemetry or
game servers;
- we do not patch Riot's client or game binaries, CEF or anti-cheat;
- we do not automate gameplay input or provide cheats;
- the opt-in hide helper manages local client windows while a match runs; the
opt-in close helper terminates eligible League client UI processes. Both are
off by default and do not change client binaries, CEF or anti-cheat.
The synthetic platform identity in §3 is local metadata; it is not a credential.
This repository does not pass it as Riot authentication data.
## 7. User agreements and account risk
Use of the project is at your own risk. You must:
- own a legitimate Riot account and obtain the client from Riot;
- comply with Riot's terms and user agreement;
- not cheat, exploit, automate gameplay or use the project to gain an unfair
advantage;
- accept that Riot does not support this environment and may suspend or ban
accounts, including accounts used only for testing. Do not use a main or
ranked account.
The project does not authorise any violation of Riot's terms. If you do not
agree, do not use the project. Account restrictions are a real risk and are
documented in the README announcement.
## 8. Trademarks and presentation
League of Legends and Riot Games are trademarks or registered trademarks of Riot
Games, Inc. The names are used only to describe the compatibility target
(nominative use). The project:
- does not use Riot logos, game art or other Riot brand assets;
- uses an original project mark;
- is not affiliated, endorsed or sponsored by Riot Games;
- asks forks to use their own name and icon and not to imply endorsement.
See `NOTICE.md` and `docs/COMPLIANCE.md`.
## 9. Historical material
Earlier revisions of the repository included a third-party game logo and an
embedded gameplay clip. They were removed from the current tree; the current
tree uses an original project mark and contains no gameplay media. Git history
and third-party forks may still contain those earlier revisions. They are not
part of the current project, are not licensed by this project, and should not be
reused. The project will review good-faith removal requests.
## 10. Notices and contact
For a licensing, trademark or interoperability question, contact the maintainer
using the address in `README.md`, or open an issue in the repository. Include:
- the repository URL, file or commit at issue;
- the right or license you assert;
- the action you request;
- a way to contact you.
For a formal copyright notice, use the hosting platform's copyright notice
process. This document is not a designation of an agent for any platform and
does not replace that process.
## 11. No legal advice and no warranty
This document is a technical and scope statement, not legal advice. The project
is provided "as is", without warranty of any kind. Nothing here guarantees that
a particular use is lawful in a particular country, that Riot will not restrict
an account, or that a court or regulator will accept the project's position. If
you need legal certainty, consult a lawyer qualified in your country.
+31
View File
@@ -91,6 +91,9 @@ darling-lol --installer
darling-lol-shell
```
The application menu entry is `Darling Launcher`, and `darling-launcher` is an
alias for `darling-lol` for scripts that prefer the neutral name.
If the desktop entry does not appear, ensure your desktop session includes
`~/.nix-profile/share` in `XDG_DATA_DIRS`, then log out and back in. Non-NixOS
systems may need this desktop-session integration after installing Nix.
@@ -207,6 +210,34 @@ If you start Darling manually in this shell, run `darling shutdown` there
before exiting. A separately launched shell cannot reconnect to an existing
Darling namespace; `darling-lol --stop` can still stop it.
### Text fonts
The FHS environment bundles Liberation and DejaVu text fonts and uses its own
fontconfig configuration and standard aliases. It does not depend on fonts in
the host's `/usr/share/fonts`, which the FHS environment replaces. Fonts in your
user font directories remain available. This also prevents an icon-only user
font inventory from becoming the only fallback for ordinary text.
The FHS environment selects the packaged fontconfig configuration and clears
inherited `FONTCONFIG_PATH` and `FONTCONFIG_SYSROOT` overrides. Clearing the
sysroot prevents it from redirecting the packaged configuration and font paths.
Custom XDG font/configuration directories and legacy
`~/.fonts` remain supported, including paths with spaces. The host configuration
and user font files are not modified.
To check font availability without starting Darling or Riot:
```sh
nix run .#default -- fc-match sans-serif
nix run .#default -- fc-match Arial
```
These should select DejaVu Sans and Liberation Sans respectively. The standalone
`nix build .#checks.x86_64-linux.fonts` check verifies generic and common Windows
font aliases with both an empty home directory and icon-only user fonts. This
checks font availability; CAPTCHA text rendering still needs manual verification
in Riot's UI.
## Files and operational limits
- Workspace: `${XDG_DATA_HOME:-$HOME/.local/share}/darling-lol`.
+10 -1
View File
@@ -6,7 +6,16 @@ A prefix without saved identity files keeps the host-derived UUID and
`DARLING-` serial; launching never generates an override. Import mode uses
values supplied by the user. `--provision` generates synthetic identifiers; it
does not issue authentic Apple identities or change CPU, GPU, or security
metadata.
metadata. The overrides are for application compatibility; they are not intended
to bypass anti-cheat, telemetry, licensing, or platform security controls.
> **Synthetic, local metadata.** These values are not Apple-issued identifiers,
> credentials or authentication tokens. Do not use them with Apple services or
> to impersonate real hardware. This repository does not pass them to Riot as
> authentication data; the values are exposed to guest applications through
> IOKit, and the official client's later handling of them is outside this
> repository's scope. See the
> [interoperability and compliance scope](INTEROPERABILITY.md).
Preview an OpenCore `config.plist`, a flat GenSMBIOS JSON file, or an existing
`darling-smbios.conf` without changing the selected prefix:
+41 -4
View File
@@ -61,10 +61,15 @@ The normal launcher starts neither an Electron inspector nor client API/UI helpe
## Application-menu diagnostics and recovery options
`scripts/create-desktop-entry.sh` creates an application-menu entry that runs
`scripts/desktop-run.sh`, preserving the normal launcher behavior and saving
stdout/stderr in `build/desktop-launch.log` with mode 0600. Logs can contain
private session details; do not attach raw launcher logs to a public issue.
`scripts/create-desktop-entry.sh` creates a `Darling Launcher` application-menu
entry that runs `scripts/desktop-run.sh`, preserving the normal launcher behavior
and saving stdout/stderr in `build/desktop-launch.log` with mode 0600. Logs can
contain private session details; do not attach raw launcher logs to a public
issue. The helper also removes the `league-of-legends.*` entry and icons written
by older versions, but only when it can prove this project created them. The
entry keeps `StartupWMClass=RiotClientServices`: Darling derives `WM_CLASS` from
the basename of `argv[0]`, so that is the window class of the client the entry
starts, while `Riot Client` is only its bundle display name.
Region/locale remain the existing `RCLOL_REGION`/`RCLOL_LOCALE` options.
`RCLOL_CDN_IPV4_ONLY` defaults to `1` in the Riot launcher and can be set to `0`
@@ -73,6 +78,38 @@ opts in to Hyprland-only recovery of a default-prefix Riot session with no
visible window; it is off by default. See [troubleshooting](TROUBLESHOOTING.md#riot-exits-and-league-reports-that-it-lost-its-connection)
for the observed failures, recovery guards and NSURLSession limitations.
`RCLOL_RECOVER_STALE_CLIENT=1` opts in to partial runtime recovery before
launch. If `darlingserver` is alive, no game is running, no managed client
window is visible and stale Riot/League/CEF processes at least 60 seconds old
remain, the launcher stops only that client tree and reuses the runtime. It
recognizes `LeagueClientUx`, `Riot Client` and `RiotClientServices` windows and
preserves `darlingserver`, launchd/mldr, sockets and `.init.pid`; if X11/Xwayland
properties cannot be inspected it does nothing. See
[troubleshooting](TROUBLESHOOTING.md#client-remains-running-without-a-window).
`RCLOL_CLEAN_STALE_HELPERS=1` runs a preflight before the match helper starts.
It removes `close-league-client-in-game.py` and
`hide-league-client-in-game.py` processes of this prefix whose parent is
`init`/`systemd`, which means the launcher that started them has exited. A
helper of a live launcher, another prefix, the game, Riot/League/CEF and
`darlingserver` are preserved. It fails closed when a command line,
environment, stat entry or parent cannot be read. See
[troubleshooting](TROUBLESHOOTING.md#multiple-client-in-game-helpers).
`RCLOL_CLIENT_IN_GAME_TRICKS=1` opts in to automatic client handling during a
match. It reads `lol-user-experience` from the installed client's
`LCULocalPreferences.yaml`: with `potatoModeEnabled: true`, it closes the client
UI when `closeLeagueClientDuringGame: true`, and hides the managed
`LeagueClientUx`/`Riot Client` X11 windows when that value is false. Missing or
invalid preference values, disabled client optimizations and unreadable files
select no action. The low-level `RCLOL_CLOSE_CLIENT_IN_GAME=1` and
`RCLOL_HIDE_CLIENT_IN_GAME=1` switches remain available when the automatic
switch is not set. The feature is off by default, requires X11/Xwayland, and
does not patch client binaries, CEF or the game. The hide helper exits after ten
minutes without a client or match once it has seen one. See
[the troubleshooting measurement](TROUBLESHOOTING.md#automatic-client-handling-during-a-match)
for the measured CPU effect and limitations.
`RCLOL_FILTER_HOST_ENV=1` opts in to removing host desktop-session variables before
the guest starts: `WAYLAND_DISPLAY`, `XDG_SESSION_*`, `XDG_CURRENT_DESKTOP`,
GNOME/KDE/GDM, systemd, SSH agent, terminal, toolkit (`QT_*`, `GTK_*`, `GDK_*`),
+206 -1
View File
@@ -78,6 +78,7 @@ Host-only checks, which do not start Darling:
python3 tools/riot-cdn-dns-offline-check.py
python3 -m unittest discover -s tests -p 'test_hidden_riot_recovery.py'
python3 -m unittest discover -s tests -p 'test_desktop_run.py'
python3 -m unittest discover -s tests -p 'test_desktop_entry.py'
python3 -m unittest discover -s tests -p 'test_urlsession_runner.py'
```
@@ -87,9 +88,25 @@ insensitivity, A queries, non-CDN names and misleading domain suffixes without
sending a DNS query. Recovery tests use fake `/proc` entries and mock every
compositor/shutdown command. The desktop test checks exit/argument forwarding,
append-only output and tightening an existing public log to mode 0600. The
runner test uses a fake `darling` executable to verify loopback fixtures and
desktop-entry test renders the helper against a disposable `HOME` and checks
the neutral fields, Exec quoting, icon paths, that only launcher artifacts
this project created are removed, and that the checkout and packaged entries
share their identity fields. The runner test uses a fake `darling` executable to verify loopback fixtures and
private-prefix-only shutdown/cleanup.
With the pinned Darling sources available, run the host resolver regression:
```sh
python3 -m unittest discover -s tests -p 'test_host_dns.py' -v
```
It compiles the actual patched vchroot implementation in its Linux test mode
and reads temporary resolver files through absolute and relative host symlinks.
It checks atomic file replacement, symlink retargeting, guest DNS overrides and
guest absolute-link scope. A CMake fixture verifies that both install modes
replace an older Google resolver file with the host link. No Darling session or
DNS traffic is started.
## CoreText font-list and AppKit resize regressions
After preparing the source and configuring the runtime tools:
@@ -119,6 +136,121 @@ Expected: `CORETEXT_FONT_LIST pass=1` with nonzero family/face counts (306/1124
The font probe reproduces Chromium's installed-family enumeration, mandatory family matching and localized-name lookup with a null language output. It checks ownership of the single-match result and that a nonexistent mandatory family produces no substitute. The resize probe checks backing-layer bounds immediately after frame/bounds changes, including a scaled view and a child layer, without relying on input or coordinate conversion to refresh them. It also verifies that native parent size is current during child layout, and that adding an overlay sibling after the content view does not redirect subsequent content resizing into that overlay. The old sibling selection left content at 1600×900 while stretching the 30×20 overlay to 1280×720; the corrected layout resizes the content and preserves the overlay. Before the fixes, these checks report a stale 1280×720 layer and native parent after a 1600×900 resize. The `FRAME_SIZE_HOOK` check uses a subclass whose `setFrameSize:` publishes its viewport size. It checks growth and shrinkage through parent autoresizing, direct `setFrame:`, and direct `setFrameSize:`. Before component-setter dispatch was corrected only the final direct size setter reached the subclass (one callback); afterward all four updates do, with current geometry visible inside the callback. No probe launches or contacts Riot/League. The user confirmed that the language dropdown and League window resizing work after the final X11 correction (2026-10-15). The practice-tool crash remains unresolved.
### Local event monitors and client dragging
`python3 tools/build-riot-x11-runtime.py` builds
`build/riot-event-monitors-check`. With patched AppKit installed and clients
closed, run:
```sh
darling shell env DYLD_LIBRARY_PATH=/Users/me/RuntimeLibraries \
DYLD_FRAMEWORK_PATH=/Users/me/RuntimeFrameworks \
/Volumes/SystemRoot/path/to/darling-lol/build/riot-event-monitors-check
```
Expected: nine `PASS` lines and exit status 0. This independent probe tests
multiple monitors, mask filtering, removal, consumption, event replacement,
self-removal, and the in-flight snapshot when another monitor is removed.
Monitor order is unspecified and is deliberately not asserted. It dispatches
only synthetic events to its own unmapped window.
The same source runs against native macOS AppKit:
```sh
clang -fblocks -framework AppKit tools/riot-event-monitors-check.m \
-o /tmp/riot-event-monitors-check
/tmp/riot-event-monitors-check
```
Native reference: macOS 26.6.2. LeagueClientUx uses local
monitors for custom window movement; intercepting a fixed titlebar strip instead
would bypass its own drag policy and risk stealing its window-control clicks.
For a live regression check, drag its header, drag ordinary content (which must
not move the window), minimize and restore it, and check Riot Client header
dragging separately. No match is required.
### X11 window decorations
`python3 tools/build-riot-x11-runtime.py` also builds
`build/riot-window-decorations-check`. Install and activate both the patched
AppKit and X11 backend before running it, with clients and the game closed:
```sh
darling shell env DYLD_LIBRARY_PATH=/Users/me/RuntimeLibraries \
DYLD_FRAMEWORK_PATH=/Users/me/RuntimeFrameworks \
/Volumes/SystemRoot/path/to/darling-lol/build/riot-window-decorations-check
```
Expected: `WINDOW_DECORATIONS_CHECK cases=10 pass=1`. The independent Cocoa
probe reads `_MOTIF_WM_HINTS` on its own unmapped native windows. It covers a
normal titled window, hidden title alone, hidden plus transparent titlebar,
both reverse transitions, untitled masks with additional flags, switching to
borderless after creation, native-window recreation, and properties set before
the native window exists. It sends no input, maps no windows and does not
launch or contact Riot/League. Check the success marker, not only the launcher
exit status: some Darling versions do not propagate a guest assertion failure.
Before the fix the hidden/transparent case fails. With the corrected overlays,
the ten cases passed on KDE Wayland/Xwayland. Passive inspection of the reopened
Riot Client also confirmed the no-decoration hint and identical compositor frame
and client dimensions (1536×864), instead of the previous 28-pixel titlebar.
This validates the Riot Client window, not every LeagueClientUx or game mode.
### NSOpenPanel Open/Cancel (issue #85)
`python3 tools/build-riot-openpanel-check.py` builds
`build/riot-openpanel-check`. Install the patched AppKit first, with clients and
the game closed. The probe opens its own directory chooser in a fresh `/tmp`
folder containing one subfolder and needs no Riot/League client:
```sh
P=/Volumes/SystemRoot/path/to/darling-lol/build/riot-openpanel-check
E="env DYLD_LIBRARY_PATH=/Users/me/RuntimeLibraries DYLD_FRAMEWORK_PATH=/Users/me/RuntimeFrameworks"
for m in cancel open-selected open-none; do darling shell $E $P --auto $m; done
darling shell $E $P --interactive
```
Each `--auto` mode waits 1.5 s, then clicks the panel's own Cancel or Open
button (selecting the subfolder first for `open-selected`), and checks that
`runModal` returned, the result code and URL, and that the panel is gone. A
15 s watchdog on a separate thread reports a hang. Expected, one line per mode:
```
OPENPANEL_CHECK mode=cancel result=PASS code=0 ...
OPENPANEL_CHECK mode=open-selected result=PASS code=1 url=/tmp/openpanel-check.XXXXXX/subfolder ...
OPENPANEL_CHECK mode=open-none result=PASS code=1 url=/tmp/openpanel-check.XXXXXX ...
```
A failure prints `result=FAIL ... problems=...` (`HANG` when `runModal` never
returned) and exits non-zero. `--interactive` shows the panel for manual clicks
and prints `OPENPANEL_CHECK mode=interactive result=RETURNED code=... url=...`
once it closes. As with the other probes, check the printed line rather than
only the launcher exit status.
### NSSavePanel Finder tags (`setTagNames:` / `tagNames`)
`python3 tools/build-riot-save-panel-tag-check.py` builds
`build/riot-save-panel-tag-check`. Install the patched AppKit first, with clients
and the game closed. The probe checks selector availability, inheritance, and
safe no-op semantics without launching any client or creating window fixtures:
```sh
P=/Volumes/SystemRoot/path/to/darling-lol/build/riot-save-panel-tag-check
E="env DYLD_LIBRARY_PATH=/Users/me/RuntimeLibraries DYLD_FRAMEWORK_PATH=/Users/me/RuntimeFrameworks"
darling shell $E $P
```
Expected output:
```
SAVE_PANEL_TAG class=NSSavePanel selectors=1 inherited=1 values=1 pass=1
SAVE_PANEL_TAG class=NSOpenPanel selectors=1 inherited=1 values=1 pass=1
SAVE_PANEL_TAG_CHECK pass=1
```
Cocotron does not persist Finder tag metadata or provide a tag UI. `setTagNames:`
safely ignores input and `tagNames` returns an empty `NSArray` to prevent
unrecognized-selector crashes from callers (such as Electron file dialogs).
### Presentation publisher handoff
With clients closed, run `build/riot-client-resize-check --handoff` through Darling with the normal runtime overrides. This creates an owned window and two fixture frame slots. The live software owner first supplies a 1280×720 main frame, then switches to a 262×131 popup; another slot supplies the resized main frame without the software flag. The test samples its own window beyond the original frame extent and checks generation colors across growth and shrinkage. The old selector reports black at the 1600×900 sample; the correction passes all four sizes. Repeat with `RCLOL_XSHM=0` and with `DARLING_XSHM_LIBRARY` pointing to the normal transport to cover both paths. The fixtures remove their own frame slots on exit; they do not read client pixels or send input.
@@ -533,3 +665,76 @@ launch, window placement, click alignment and edge panning before rollout.
After installing the tested X11 and CoreGraphics binaries locally, the user
reported that everything was working (2026-10-16). Fullscreen policy was unchanged.
## VRR presentation regression (#46)
```sh
python3 -m unittest discover -s tests -p 'test_x11_vrr.py'
```
The host fixtures exercise the patched eligibility, X11 property updates and
EGL surface ownership transitions. They cover hidden/titled/partial views,
multiple views, parent recreation, child fallback and current-context handling.
Build `build-riot-coregraphics-runtime.py`, `build-riot-x11-runtime.py` and
`build-riot-metal-presentation.py` together. Stage all three updated frameworks
(CoreGraphics, AppKit's X11 backend, QuartzCore) when testing isolated binaries.
Run `riot-metal-presentation-check` with `RIOT_PRESENTATION_PARENT=1` to create
an owned borderless game-like window. It verifies the parent drawable is
borrowed. Add `RIOT_PRESENTATION_RESIZE=1` to verify fallback to a child at
half width and borrowing the parent again when restored. Add
`RIOT_PRESENTATION_NESTED=1` for nested layers.
The default probe still exercises the independent child-window path.
For physical VRR validation, enable adaptive sync in the monitor and desktop,
then manually test fullscreen and borderless League with a frame cap inside
the monitor's VRR range (for example 157 FPS on a 165 Hz display), with VSync
off. Check the monitor's live refresh display as well as the game FPS counter.
Also test leaving fullscreen, restoring it, resizing, and alt-tab. Report GPU,
driver, compositor and session type. A stable FPS counter or the X11 property
alone does not prove that the monitor is using variable refresh.
Local native validation on 2026-10-19 passed all three modes (child, parent
with resize, nested parent with resize), including Vulkan-to-GL pixel readback
and ten presentations per mode, using staged frameworks in a private prefix.
Physical VRR and in-game performance on the reporter's Mutter setup remain
unverified.
## Metal VSync regression (#46)
```sh
python3 -m unittest discover -s tests -p 'test_metal_vsync.py'
```
These host checks compile the patched layer-tree policy, flush body and CGL
swap methods against inert fixtures. They cover nested layers, VSync toggles,
shared-window requests, independent contexts, late attachment and failed
context/interval changes. They do not measure physical display refresh.
For manual validation after updating with the clients closed, compare the
same scene with in-game VSync on and off. With VSync on, presentation should
follow the display/compositor cadence; with it off, the game's frame cap
should continue to work. Record monitor refresh, compositor, X11/Xwayland,
GPU/driver and window mode. The window presentation probe above checks the
API wiring; an in-game/compositor timing comparison remains necessary.
## Combined VSync and VRR testing
The `test/vsync-vrr` branch combines PRs #81 and #88, resolving their shared
compositor-patch and presentation-probe changes. The probe toggles
`displaySyncEnabled` and checks the CGL interval in child, parent and nested
parent modes; the parent modes also support resize fallback/restoration.
All three native modes passed locally in a private prefix, together with ten
host regression checks and validation of all 31 component patches.
After closing the game and both clients:
```sh
git fetch origin
git switch --track origin/test/vsync-vrr
./scripts/update.sh
```
Test VSync with desktop VRR disabled, then test VRR with VSync off and a cap
inside the monitor's adaptive range. Finally test both enabled. Report game
FPS and the monitor's live refresh reading separately.
+197 -6
View File
@@ -149,6 +149,41 @@ ownership or window information cannot be read. A hidden background client or
download is restarted when recovery is enabled. Other desktop environments are
not supported by this helper; recovery is off by default.
For a live Darling runtime with no visible client window but stale Riot/League/
CEF processes at least 60 seconds old, `RCLOL_RECOVER_STALE_CLIENT=1` performs a
partial recovery before the next launch. It keeps `darlingserver`, launchd/mldr,
sockets and `.init.pid`, stops only the stale client process tree, and then lets
the normal launcher start the product again. It recognizes `LeagueClientUx`,
`Riot Client` and `RiotClientServices` windows, does nothing while a game process
is running or when a managed client window is visible, and fails closed when
X11/Xwayland properties are missing or unreadable. This saves the Darling
bootstrap but not the Riot Client/CEF startup itself. If no window appears
afterward, use a full runtime shutdown/restart.
### Multiple client-in-game helpers
The close/hide helper is a long-lived watcher. If an earlier launcher exits
while it remains, the next launch can start another copy; list them with:
```sh
pgrep -af 'close-league-client-in-game.py|hide-league-client-in-game.py'
```
To remove the orphaned copies before the next helper starts:
```sh
RCLOL_CLEAN_STALE_HELPERS=1 ./scripts/run.sh
```
Only helpers of the current prefix whose parent is `init`/`systemd` are
terminated. Helpers whose launcher is still alive, other prefixes, the game,
Riot/League/CEF, `darlingserver` and the runtime are never touched. A dry run
is available from the configured tools directory:
```sh
RCLOL_CLEAN_STALE_HELPERS=1 python3 build/runtime/tools/clean-stale-helpers.py --dry-run
```
### Client window stays black after a match
The League client keeps its Chromium/CEF UI (`LeagueClientUx` and its helpers)
@@ -192,6 +227,85 @@ observation, without waiting for a match:
python3 tools/close-league-client-in-game.py --once --dry-run
```
### Automatic client handling during a match
A single opt-in switch reads the client's own preferences and chooses the mode:
```sh
RCLOL_CLIENT_IN_GAME_TRICKS=1 ./scripts/run.sh
```
It reads `lol-user-experience` from the installed client's
`LCULocalPreferences.yaml`:
| Client preference | Launcher action |
|---|---|
| `potatoModeEnabled: false` or unreadable | no client-in-game helper |
| `potatoModeEnabled: true`, close preference missing or invalid | no action |
| `potatoModeEnabled: true`, `closeLeagueClientDuringGame: true` | close the client UI |
| `potatoModeEnabled: true`, `closeLeagueClientDuringGame: false` | hide the client windows |
The hide path unmaps the `LeagueClientUx` and `Riot Client` X11 windows and maps
them again when the game process ends. The client is not closed, the League
backend and Riot client keep running, and the game window is never hidden. The
close path uses the UI-close helper described above. The hide helper exits after
ten minutes without a client or match once it has seen one; a missing or invalid
close preference selects no helper.
The low-level `RCLOL_HIDE_CLIENT_IN_GAME=1` and
`RCLOL_CLOSE_CLIENT_IN_GAME=1` switches remain available when the automatic
switch is not set. All modes are off by default. The helpers are
window-management only: they do not patch client binaries, CEF, anti-cheat or
DRM. They attribute the game to this prefix through the loader's
`__mldr_sockpath`, and fail closed when ownership, proc state, environment or
window information cannot be read. The hide helper requires an X11 or Xwayland
desktop; on a native Wayland window manager without Xwayland it cannot find the
windows.
On a CPU-bound host the hide effect appears after CEF has been hidden for a few
seconds. In a local 30-second test on an i5-3470 with a Radeon RX 550, hiding
`LeagueClientUx` reduced the summed CPU of the matched client/CEF processes from
120.7% to 93.4% (about 23%, or 27 percentage points, of one core); showing the
window returned it to 119.9%. This is not a universal FPS or percentage claim:
a game that is GPU-bound, a client with no active UI work, or a different
desktop may show less benefit. The hidden window can also need a moment to
repaint after it is shown.
With client optimizations enabled and close-during-game enabled, the close
helper remains the more aggressive option when in-client chat during the match
is not needed.
Diagnose the match detector without changing any window:
```sh
python3 tools/hide-league-client-in-game.py --once
```
### Riot reports NO INTERNET FOUND while the host is online
Older base runtimes ship Google DNS servers (`8.8.8.8` and `8.8.4.4`), which
some mobile and managed networks block. The base resolver now links to the
host's `/etc/resolv.conf` through `/Volumes/SystemRoot`, including when the host
file is a symlink into `/run` for systemd-resolved or NetworkManager. File and
symlink replacements remain visible without copying the resolver on launch.
Exit Riot and League, then run `./scripts/update.sh` to rebuild and install both
the base link and the host symlink handling correction. Existing prefix DNS
overrides in `$DPREFIX/private/etc/resolv.conf` (normally
`~/.darling/private/etc/resolv.conf`) remain in effect; remove a previous manual
override with Darling stopped if you want to follow the host instead. A custom
prefix `/etc` directory can also shadow the base `/etc -> private/etc` link.
Check resolution inside the guest with:
```sh
darling shell curl --noproxy '*' https://clientconfig.rpg.riotgames.com/
```
An HTTP response establishes that resolution succeeded even if that endpoint
rejects the request. This change follows the host resolver configuration;
already-running clients may cache DNS settings until restarted.
### Downloads repeatedly fail with an IPv6 CONNECT_TO error
The bundled downloader was observed retrying CDN chunks with:
@@ -226,6 +340,27 @@ reference before callback delivery. This establishes the cancellation fix; a lon
Riot session still needs confirmation. With both clients and the game closed,
run `./scripts/update.sh` to install it, then `sh scripts/run.sh`.
## League and Riot UIs crash after clicking Play
The League UX processes and then the Riot Client renderer stop with `SIGTRAP`
a few seconds after the lobby opens. The renderer prints
`Check failed: kr == KERN_SUCCESS. mach_make_memory_entry_64: (os/kern) resource shortage (6)`
from `platform_shared_memory_region_mac.cc`. darlingserver backs every named
memory entry with a memfd, and its open descriptors peak at about 1100 when the
lobby opens. Under the rootless NixOS launcher darlingserver cannot raise its
hard `RLIMIT_NOFILE` to `nr_open`, so it used to keep the soft limit it
inherited. When that limit was 1024 (several Electron apps and desktop launchers
pass it on), `memfd_create` failed with `EMFILE`.
darlingserver now raises its soft limit to the inherited hard limit when it
cannot raise the hard one. A failed named-entry creation also logs
`MEMDIAG … failed errno=… nofile=soft/hard` to `dserver.log`, and every 1024th
memfd logs `MEMDIAG descriptors live=…` so a leak would show as a growing `live`
count. With a 1024 soft limit the old server reproduced the crash and logged
`errno=24 nofile=1024/524288`. With the fix, the server reports a 524288 soft
limit under the same launch. To check a running server, read the `Max open files`
line of `/proc/$(pgrep -x darlingserver)/limits`.
## UI crashes after a button opens an external link
LaunchServices dereferenced a nullable error-output pointer in six paths. The patch checks the pointer itself and populates supplied outputs; the standalone regression covers missing handlers and null outputs. Electron opens LaunchServices through an absolute CoreServices subframework path, so the paired installer also replaces that binary in the stopped guest prefix. Updating only `RuntimeFrameworks/LaunchServices.framework` can leave the crash unfixed.
@@ -330,7 +465,7 @@ It prints each thread-local access that calls its thunk without the descriptor i
## Base install refuses to continue while Darling is not running
`sudo cmake --install` prints `Darling currently running for <user>, shutting it down...` several times and then `Darling launchd PID … remains alive after shutdown`. A guest launchd outlived its darlingserver, so `darling shutdown` sees no container to stop. `python3 build/runtime/tools/ensure-darling-runtime.py` stops such a launchd (your own, only when no darlingserver runs); `scripts/run.sh` and `scripts/install-runtime.sh` run it too.
`sudo cmake --install` prints `Darling currently running for <user>, shutting it down...` several times and then `Darling launchd PID … remains alive after shutdown`. A guest launchd outlived its darlingserver, so `darling shutdown` sees no container to stop. Automatic cleanup by process name is disabled because guest names and UIDs do not prove prefix ownership (killing by name risks terminating an active launchd from an unrelated prefix or session). If setup is blocked, shut down the original Darling session from its own namespace (`darling shutdown`), or inspect the leftover PID under `/proc/<PID>` before terminating it manually.
## Lower fight FPS than Windows
@@ -349,11 +484,25 @@ On Hyprland, also check that direct scanout is off (`hyprctl getoption render:di
On the NVIDIA proprietary driver, check the submit worker's kernel time: a thread of the game process spending most of its time in the kernel (`/proc/<pid>/task/<tid>/stat` system time, or `perf trace -s -p <pid>`) points at driver calls. Each `vkQueueSubmit2` and each CPU-side `vkSignalSemaphore` is an RM control ioctl (command `0xc020462a`) that queues on a driver-wide lock. Before 2026-10-18 every command buffer signalled the event loop's wake-up semaphore, ~25 times per frame; with lazy wake-ups (default) and a 5 ms batch window (`/tmp/metal-submit-batch-us` = `5000`, `/tmp/metal-submit-batch-max` = `64`) an RTX 4090 ran at 206–552 FPS against 91–147 FPS with `/tmp/metal-no-lazy-wakeup`, in alternating 20 s phases of one match (the later phases with wake-ups on were capped at 240 FPS) (see [setup](SETUP.md#metal-and-indium-overlays)).
The NVIDIA performance figures above were reported on an earlier runtime base;
they have not been remeasured after integration with current `main`.
they have not been remeasured after integration with current `main`. On `bcb3245` an RTX 5060 Laptop reported ~200–215 FPS in Practice Tool ([#53](https://github.com/lucannez64/darling-lol/issues/53)).
## NVIDIA
With the window visual and compositor draw buffer fixes (#22) and the RPC socket fix (#25), the game renders and runs on these NVIDIA GPUs:
| GPU | Driver | Report | Result |
|---|---|---|---|
| GTX 1060 6GB | 580.178.04 | [below](#nvidia-580-pascal-and-older-black-game-window) | client and tutorial |
| RTX 2070 SUPER | 615.78, proprietary | [#55](https://github.com/lucannez64/darling-lol/issues/55) | tutorials, Co-op vs AI, Swiftplay and Draft games; no crashes |
| RTX 3060 | 615.71 | [below](#nvidia-resize-signals-cpu-readback-and-completion-latency) | custom matches through CPU readback |
| RTX 5060 Laptop | 615.71.09, open modules | [#53](https://github.com/lucannez64/darling-lol/issues/53) | Practice Tool at ~200–215 FPS on `bcb3245`; MUX set to discrete, PRIME variables set |
| RTX 5070 | 615.78.08, open modules | [#69](https://github.com/lucannez64/darling-lol/issues/69) | tutorial |
If the game window stays black on NVIDIA, check `metal-device.log` as described in [Check which GPU rendered](#check-which-gpu-rendered).
## Hybrid graphics laptops (AMD/Intel iGPU + NVIDIA)
Metal renders with Vulkan, and each finished frame is handed to an OpenGL (EGL) context that presents it. The hand-off uses opaque file descriptors, which only work when Vulkan and OpenGL run on the same GPU. Indium takes the first Vulkan device the loader lists, and on a hybrid laptop both that device and the EGL context are normally the integrated GPU, so the discrete GPU stays idle. A report in [issue #3](https://github.com/lucannez64/darling-lol/issues/3) (Ryzen 9 5900HS, RTX 3060 Laptop) measured 60-70 FPS in ARAM on the integrated GPU; on the NVIDIA GPU the game showed a black screen. **Running on an NVIDIA GPU is not validated.**
Metal renders with Vulkan, and each finished frame is handed to an OpenGL (EGL) context that presents it. The hand-off uses opaque file descriptors, which only work when Vulkan and OpenGL run on the same GPU. Indium takes the first Vulkan device the loader lists, and on a hybrid laptop both that device and the EGL context are normally the integrated GPU, so the discrete GPU stays idle. A report in [issue #3](https://github.com/lucannez64/darling-lol/issues/3) (Ryzen 9 5900HS, RTX 3060 Laptop) measured 60-70 FPS in ARAM on the integrated GPU; on the NVIDIA GPU the game showed a black screen, since fixed (see [NVIDIA](#nvidia)).
### Run on the discrete GPU
@@ -363,7 +512,12 @@ Start the launcher with PRIME render offload so that both Vulkan and OpenGL move
prime-run sh scripts/run.sh
```
`prime-run` sets `__NV_PRIME_RENDER_OFFLOAD=1`, `__VK_LAYER_NV_optimus=NVIDIA_only` and `__GLX_VENDOR_LIBRARY_NAME=nvidia`. `darling` copies the caller's environment into the guest, and guest processes inherit it; whether the Riot client passes all of it to the game has not been checked; the log below shows the result. Darling's OpenGL uses EGL, so if the log below still shows the integrated GPU as the presenting renderer, also set `__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json`. On two Mesa GPUs, `DRI_PRIME=1` does the same.
`prime-run` sets `__NV_PRIME_RENDER_OFFLOAD=1`, `__VK_LAYER_NV_optimus=NVIDIA_only` and `__GLX_VENDOR_LIBRARY_NAME=nvidia`. `darling` copies the caller's environment into the guest, and guest processes inherit it; whether the Riot client passes all of it to the game has not been checked; the log below shows the result. Darling's OpenGL uses EGL, so if the log below still shows the integrated GPU as the presenting renderer, also set `__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json`. On two Mesa GPUs, `DRI_PRIME=1` does the same. The RTX 5060 Laptop in [#53](https://github.com/lucannez64/darling-lol/issues/53) rendered with all four variables set:
```sh
__NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia \
__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json sh scripts/run.sh
```
The guest file `/tmp/metal-gpu` (a device index or part of its name, for example `nvidia`) moves only the Vulkan side. Use it for diagnosis: on its own it splits the two sides across GPUs, and frames cannot be presented.
@@ -397,9 +551,9 @@ The first import of a drawable into the presenting OpenGL context, and the first
[MetalDevice] pid=… drawable GL semaphore (first) import_error=0x0 wait_error=0x0 ok (checked for the first 600 imports)
```
A non-zero error or `FAILED` means the frames cannot reach the window. Before 2026-10-16 the import did not mark the memory as dedicated, which the extension requires; Mesa ignores it, and it is the suspected cause of the NVIDIA black screen (not yet confirmed). An NVIDIA log of 2026-10-16 showed `glTiling=optimal` with `setup_error=0x501 storage_error=0x501 FAILED`: NVIDIA's GL rejects `GL_LINEAR_TILING_EXT`, so the linear Vulkan image could not be imported. Since then the internal image and the GL texture use optimal tiling when `GL_VENDOR` contains NVIDIA (`vkTiling=optimal glTiling=optimal ok` is the expected line); everything else keeps linear. If the game shows a black screen on NVIDIA, report it with this file.
A non-zero error or `FAILED` means the frames cannot reach the window. Before 2026-10-16 the import did not mark the memory as dedicated, which the extension requires; Mesa ignores it. It was suspected of causing the NVIDIA black screen; the causes found later were the window visual and the draw buffer (#22). An NVIDIA log of 2026-10-16 showed `glTiling=optimal` with `setup_error=0x501 storage_error=0x501 FAILED`: NVIDIA's GL rejects `GL_LINEAR_TILING_EXT`, so the linear Vulkan image could not be imported. Since then the internal image and the GL texture use optimal tiling when `GL_VENDOR` contains NVIDIA (`vkTiling=optimal glTiling=optimal ok` is the expected line); everything else keeps linear. If the game shows a black screen on NVIDIA, report it with this file.
An additional NVIDIA report on `68f816d` showed successful optimal-tiling import but repeated `Metal Device timed out giving us a Drawable to present` messages. Its [presentation trace](https://github.com/lucannez64/darling-lol/issues/3#issuecomment-6214732591) shows all three drawables queued and all three main-thread presentation callbacks running, followed by timeouts with three frames still queued. The compositor only prepared a Metal layer when it was the root layer, skipping nested Metal layers. It now prepares Metal layers throughout the tree. A standalone nested-layer reproduction exhausts the pool before this correction and passes ten presentations with pixel readback after it; the root-layer probe also passes. Confirmation on the reporter's NVIDIA system is still needed.
An additional NVIDIA report on `68f816d` showed successful optimal-tiling import but repeated `Metal Device timed out giving us a Drawable to present` messages. Its [presentation trace](https://github.com/lucannez64/darling-lol/issues/3#issuecomment-6214732591) shows all three drawables queued and all three main-thread presentation callbacks running, followed by timeouts with three frames still queued. The compositor only prepared a Metal layer when it was the root layer, skipping nested Metal layers. It now prepares Metal layers throughout the tree. A standalone nested-layer reproduction exhausts the pool before this correction and passes ten presentations with pixel readback after it; the root-layer probe also passes. Issue #3 has since been closed, and the game renders on NVIDIA (see [NVIDIA](#nvidia)).
### NVIDIA resize signals, CPU readback and completion latency
@@ -541,3 +695,40 @@ Recovery requires every matching client to be at least 60 seconds old and a
complete Hyprland window record (`class`, `title`, `mapped`, `hidden`). A second
process scan after window inspection must find the same client identities and
no game. Missing information or shutdown failure leaves normal launch in charge.
## Variable refresh rate (VRR)
Full-window borderless game layers now use the opaque managed X11 parent
surface for presentation. Previously they swapped an independent child while
the managed parent remained static. Using one surface lets the compositor
track the game's updates for VRR and avoids scanning out an empty parent.
Partial views, titled windows and other applications retain child drawables.
The child fallback retains the compositor-bypass prohibition that prevents
black screens. The fullscreen parent path advertises `_VARIABLE_REFRESH=1`;
leaving fullscreen clears that request. Desktop/driver policy still decides
whether to enable adaptive sync.
With the game and both clients closed, rebuild with `./scripts/update.sh`;
CoreGraphics, QuartzCore and the X11 backend must be updated together. Enable
VRR in the desktop and monitor, and compare the monitor's live refresh reading
to a frame cap below its maximum refresh, initially with VSync off. VRR and
VSync are separate: this change does not implement an in-game frame limiter.
See [the VRR probe and manual checks](TESTING.md#vrr-presentation-regression-46).
Standalone child, parent and nested-parent presentation probes passed locally;
monitor-level VRR and the reporter's in-game behavior still need confirmation.
## VSync and frame caps (#46)
The Metal layer's `displaySyncEnabled` property previously had no effect on
the window swap interval. A game that delegates pacing to VSync could run
uncapped when VSync was enabled. The compositor now applies that property to
the window before swapping, including nested Metal layers and setting changes.
If several Metal layers share a window, any layer requesting VSync enables it
for that window. Other windows retain independent swap settings.
Exit the game and both clients, then run `./scripts/update.sh` to rebuild and
install the QuartzCore and OpenGL changes. Until updated, disable in-game
VSync to use the game's frame cap, as the issue reporter confirmed. Physical
scanout timing still depends on the driver and desktop compositor; the fix
has standalone regression coverage but needs an in-game timing retest.
+112 -31
View File
@@ -1,5 +1,5 @@
{
description = "Darling League of Legends - experimental macOS LoL runner on Linux via Darling";
description = "Unofficial Darling launcher for the macOS game client on Linux";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
@@ -12,6 +12,23 @@
pkgs = nixpkgs.legacyPackages.${system};
llvmPackages = pkgs.llvmPackages_21;
# Host /etc/fonts survives buildFHSEnv, but host /usr/share/fonts does
# not. Use store paths for both text fonts and the standard alias rules.
darlingFonts = [ pkgs.liberation_ttf pkgs.dejavu_fonts ];
darlingFontsConf = pkgs.makeFontsConf {
fontDirectories = darlingFonts;
includes = [
"${pkgs.fontconfig.out}/etc/fonts/conf.d"
# makeFontsConf adds XDG font directories, but neither it nor
# conf.d/50-user.conf adds the legacy ~/.fonts directory.
(pkgs.writeText "darling-user-fonts.conf" ''
<fontconfig>
<dir>~/.fonts</dir>
</fontconfig>
'')
];
};
# Python environment with dependencies required by tooling
pythonEnv = pkgs.python3.withPackages (
ps: with ps; [
@@ -119,7 +136,7 @@
pythonEnv
];
# FHS environment for building and running Darling and League of Legends.
# FHS environment for building and running Darling and the macOS game client.
# Darling requires root/multitasking mount & namespace semantics, /usr/local layout,
# and dynamically compiled overlays. An FHS environment provides the standard standard
# filesystem hierarchies (/usr/include, /usr/lib, /usr/bin) and native dynamic linker.
@@ -155,6 +172,8 @@
export DPREFIX="''${DPREFIX:-$HOME/.darling}"
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
unset FONTCONFIG_PATH FONTCONFIG_SYSROOT
export FONTCONFIG_FILE=${darlingFontsConf}
export DARLING_RUNNER_DIR=${darlingRunner}/bin
export PATH="$DARLING_RUNNER_DIR:/usr/local/bin:''${PATH:-}"
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib64/pkgconfig:/usr/share/pkgconfig:''${PKG_CONFIG_PATH:-}"
@@ -204,10 +223,10 @@
mkdir -p $out/bin $out/share/darling-lol $out/share/icons/hicolor/scalable/apps $out/share/icons/hicolor/128x128/apps $out/share/pixmaps $out/share/applications
cp -r * $out/share/darling-lol/
cp darling-lol.svg $out/share/icons/hicolor/scalable/apps/darling-lol.svg
cp darling-lol.png $out/share/icons/hicolor/128x128/apps/darling-lol.png
cp darling-lol.png $out/share/pixmaps/darling-lol.png
cp darling-lol.svg $out/share/pixmaps/darling-lol.svg
cp darling-lol.svg $out/share/icons/hicolor/scalable/apps/darling-launcher.svg
cp darling-lol.png $out/share/icons/hicolor/128x128/apps/darling-launcher.png
cp darling-lol.png $out/share/pixmaps/darling-launcher.png
cp darling-lol.svg $out/share/pixmaps/darling-launcher.svg
# Install configured launcher
substitute ./darling-lol-launcher.sh $out/bin/darling-lol \
@@ -216,6 +235,7 @@
--replace-fail "@UNSHARE_BIN@" "${pkgs.util-linux}/bin/unshare"
chmod +x $out/bin/darling-lol
wrapProgram $out/bin/darling-lol --prefix PATH : ${pkgs.lib.makeBinPath [ pythonEnv pkgs.coreutils pkgs.util-linux pkgs.gawk ]}
ln -s darling-lol $out/bin/darling-launcher
makeWrapper $out/bin/darling-lol $out/bin/darling-lol-installer \
--add-flags "--installer"
@@ -226,15 +246,15 @@
makeWrapper $out/bin/darling-lol $out/bin/darling-lol-build \
--add-flags "./scripts/build.sh"
cat << 'DESKTOP_EOF' > $out/share/applications/darling-lol.desktop
cat << 'DESKTOP_EOF' > $out/share/applications/darling-launcher.desktop
[Desktop Entry]
Categories=Game;
Comment=Play League of Legends macOS client on Linux via Darling
Exec=darling-lol
GenericName=MOBA Game
Icon=darling-lol
Keywords=League;LoL;Riot;Darling;
Name=League of Legends
Comment=Unofficial launcher for the macOS game client via Darling
Exec=darling-launcher
GenericName=Game
Icon=darling-launcher
Keywords=Darling;Launcher;Compatibility;
Name=Darling Launcher
StartupWMClass=RiotClientServices
Terminal=true
Type=Application
@@ -245,7 +265,7 @@ DESKTOP_EOF
'';
meta = with pkgs.lib; {
description = "Tooling and patches to run macOS League of Legends on Linux with Darling";
description = "Unofficial tooling and patches to run the macOS game client on Linux with Darling";
homepage = "https://github.com/lucannez64/darling-lol";
license = licenses.gpl3Only;
platforms = [ "x86_64-linux" ];
@@ -253,20 +273,81 @@ DESKTOP_EOF
};
in
{
checks.${system}.packaging = pkgs.runCommand "darling-lol-packaging-tests" {
nativeBuildInputs = [ pythonEnv pkgs.bash pkgs.git pkgs.coreutils pkgs.util-linux pkgs.gawk ];
} ''
cp -R ${darlingLol}/share/darling-lol source
chmod -R u+w source
cd source
export HOME="$TMPDIR/home" PYTHONDONTWRITEBYTECODE=1
mkdir -p "$HOME"
# Tests use private stub binaries/repositories, never Darling itself.
python3 -m unittest discover -s tests -v
python3 scripts/validate.py
grep -q '^Terminal=true$' ${darlingLol}/share/applications/darling-lol.desktop
touch "$out"
'';
checks.${system} = {
fonts = pkgs.runCommand "darling-lol-font-tests" {
nativeBuildInputs = [ pkgs.fontconfig ];
} ''
export HOME="$TMPDIR/home with spaces" XDG_CONFIG_HOME="$TMPDIR/config with spaces"
export XDG_DATA_HOME="$TMPDIR/data with spaces" XDG_CACHE_HOME="$TMPDIR/cache with spaces"
unset FONTCONFIG_PATH FONTCONFIG_SYSROOT
export FONTCONFIG_FILE=${darlingFontsConf}
mkdir -p "$HOME" "$XDG_CONFIG_HOME" "$XDG_DATA_HOME" "$XDG_CACHE_HOME"
# Check real font selection with no host or user text fonts available.
check_font() {
actual=$(fc-match --format '%{family}' "$1")
if [ "$actual" != "$2" ]; then
echo "Font match for $1: expected $2, got $actual" >&2
exit 1
fi
test -r "$(fc-match --format '%{file}' "$1")"
}
check_aliases() {
check_font sans-serif 'DejaVu Sans'
check_font serif 'DejaVu Serif'
check_font monospace 'DejaVu Sans Mono'
check_font Arial 'Liberation Sans'
check_font 'Times New Roman' 'Liberation Serif'
check_font 'Courier New' 'Liberation Mono'
}
check_aliases
# Reproduce an icon-only user inventory without host text fonts.
cp -R ${pkgs.font-awesome}/share/fonts "$XDG_DATA_HOME/fonts"
fc-list --format '%{file}\n' | grep -F "$XDG_DATA_HOME/fonts/"
check_aliases
# Retain custom XDG and legacy fonts as well as user alias rules.
chmod u+w "$XDG_DATA_HOME/fonts"
mkdir -p "$HOME/.fonts" "$XDG_CONFIG_HOME/fontconfig"
cp ${pkgs.liberation_ttf}/share/fonts/truetype/LiberationSans-Regular.ttf "$XDG_DATA_HOME/fonts/user-text.ttf"
cp ${pkgs.liberation_ttf}/share/fonts/truetype/LiberationSerif-Regular.ttf "$HOME/.fonts/legacy-text.ttf"
fc-list --format '%{file}\n' | grep -Fx "$XDG_DATA_HOME/fonts/user-text.ttf"
fc-list --format '%{file}\n' | grep -Fx "$HOME/.fonts/legacy-text.ttf"
cat > "$XDG_CONFIG_HOME/fontconfig/fonts.conf" <<'USERCONF_EOF'
<fontconfig>
<alias>
<family>DarlingCompatibilityAlias</family>
<prefer><family>Liberation Serif</family></prefer>
</alias>
</fontconfig>
USERCONF_EOF
check_font DarlingCompatibilityAlias 'Liberation Serif'
touch "$out"
'';
packaging = pkgs.runCommand "darling-lol-packaging-tests" {
nativeBuildInputs = [ pythonEnv pkgs.bash pkgs.git pkgs.coreutils pkgs.util-linux pkgs.gawk ];
} ''
cp -R ${darlingLol}/share/darling-lol source
chmod -R u+w source
cd source
export HOME="$TMPDIR/home" PYTHONDONTWRITEBYTECODE=1
mkdir -p "$HOME"
# Tests use private stub binaries/repositories, never Darling itself.
python3 -m unittest discover -s tests -v
python3 scripts/validate.py
grep -q '^Terminal=true$' ${darlingLol}/share/applications/darling-launcher.desktop
grep -q '^Name=Darling Launcher$' ${darlingLol}/share/applications/darling-launcher.desktop
grep -q '^Icon=darling-launcher$' ${darlingLol}/share/applications/darling-launcher.desktop
grep -q '^Keywords=Darling;Launcher;Compatibility;$' ${darlingLol}/share/applications/darling-launcher.desktop
grep -q '^Categories=Game;$' ${darlingLol}/share/applications/darling-launcher.desktop
# Darling derives WM_CLASS from argv[0], so the window class is the
# client executable name; this is an interoperability identifier.
grep -q '^StartupWMClass=RiotClientServices$' ${darlingLol}/share/applications/darling-launcher.desktop
! grep -qiE '^(Name|Comment|GenericName|Keywords)=.*(League|LoL|Riot|Vanguard|anti-cheat)' ${darlingLol}/share/applications/darling-launcher.desktop
test -x ${darlingLol}/bin/darling-launcher
touch "$out"
'';
};
packages.${system} = {
darling-lol = darlingLol;
@@ -278,7 +359,7 @@ DESKTOP_EOF
default = {
type = "app";
program = "${darlingLol}/bin/darling-lol";
meta.description = "Launch League of Legends via Darling";
meta.description = "Launch the macOS game client via Darling";
};
shell = {
type = "app";
@@ -288,7 +369,7 @@ DESKTOP_EOF
installer = {
type = "app";
program = "${darlingLol}/bin/darling-lol-installer";
meta.description = "Run the Darling and League of Legends rootless installer";
meta.description = "Run the Darling rootless installer";
};
build = {
type = "app";
@@ -300,7 +381,7 @@ DESKTOP_EOF
devShells.${system}.default = pkgs.mkShell {
packages = buildDeps ++ [ darlingLolFhs ];
shellHook = ''
echo "Darling LoL build & development environment loaded."
echo "Darling build & development environment loaded."
echo "Tip: Run 'darling-lol-fhs' to enter the FHS build sandbox if standard paths (/usr/include, /usr/lib) are needed."
'';
};
+642 -93
View File
File diff suppressed because it is too large. Load diff
+639 -69
View File
File diff suppressed because it is too large. Load diff
+85 -13
View File
@@ -445,7 +445,7 @@ index 458e659..2e33f20 100644
// wait until it's read
if (!dtape_semaphore_down_simple(kqchan->waiter_read_semaphore)) {
diff --git a/duct-tape/src/memory.c b/duct-tape/src/memory.c
index 3114947..e2a8d5e 100644
index 3114947..20cd162 100644
--- a/duct-tape/src/memory.c
+++ b/duct-tape/src/memory.c
@@ -11,6 +11,7 @@
@@ -456,7 +456,55 @@ index 3114947..e2a8d5e 100644
#include <mach_debug/mach_debug.h>
struct zone {
@@ -341,7 +342,14 @@ kern_return_t copyoutmap(vm_map_t map, void* fromdata, vm_map_address_t toaddr,
@@ -52,6 +53,26 @@ int ftruncate(int fd, off_t length);
#define MFD_CLOEXEC 0x1
+/* darling-lol diagnostics: why shared-memory creation fails. */
+int* __errno_location(void);
+struct dtape_diag_rlimit { unsigned long cur, max; };
+int prlimit(int pid, int resource, const struct dtape_diag_rlimit* new_limit, struct dtape_diag_rlimit* old_limit);
+#define DTAPE_DIAG_RLIMIT_NOFILE 7
+
+static long dtape_diag_live_descriptors;
+static unsigned long dtape_diag_created_descriptors;
+
+static void dtape_diag_log_shortage(const char* what, int fd, uint64_t size) {
+ int err = *__errno_location();
+ struct dtape_diag_rlimit limit = {0, 0};
+ prlimit(0, DTAPE_DIAG_RLIMIT_NOFILE, NULL, &limit);
+ dtape_log_error("MEMDIAG %s failed errno=%d size=%#llx fd=%d live=%ld created=%lu nofile=%lu/%lu",
+ what, err, (unsigned long long)size, fd,
+ __atomic_load_n(&dtape_diag_live_descriptors, __ATOMIC_RELAXED),
+ __atomic_load_n(&dtape_diag_created_descriptors, __ATOMIC_RELAXED),
+ limit.cur, limit.max);
+}
+
void dtape_memory_init(void) {
};
@@ -107,6 +128,12 @@ static dtape_map_shared_descriptor_t* dtape_map_shared_descriptor_create(int mem
desc->memfd = memfd;
desc->size = size;
+ long live = __atomic_add_fetch(&dtape_diag_live_descriptors, 1, __ATOMIC_RELAXED);
+ unsigned long created = __atomic_add_fetch(&dtape_diag_created_descriptors, 1, __ATOMIC_RELAXED);
+ if (created % 1024 == 0) {
+ dtape_log_error("MEMDIAG descriptors live=%ld created=%lu last_fd=%d", live, created, memfd);
+ }
+
return desc;
};
@@ -121,6 +148,7 @@ static void dtape_map_shared_descriptor_release(dtape_map_shared_descriptor_t* d
close(desc->memfd);
free(desc);
+ __atomic_sub_fetch(&dtape_diag_live_descriptors, 1, __ATOMIC_RELAXED);
};
static dtape_map_shared_entry_t* dtape_map_shared_entry_create(uint64_t address, uint64_t size, uint64_t page_offset, dtape_map_shared_descriptor_t* descriptor) {
@@ -341,7 +369,14 @@ kern_return_t copyoutmap(vm_map_t map, void* fromdata, vm_map_address_t toaddr,
memmove((void*)toaddr, fromdata, length);
return KERN_SUCCESS;
} else {
@@ -472,7 +520,7 @@ index 3114947..e2a8d5e 100644
}
};
@@ -526,20 +534,212 @@ kern_return_t mach_vm_allocate_kernel(vm_map_t map, mach_vm_offset_t* addr, mach
@@ -526,20 +561,218 @@ kern_return_t mach_vm_allocate_kernel(vm_map_t map, mach_vm_offset_t* addr, mach
}
};
@@ -570,8 +618,13 @@ index 3114947..e2a8d5e 100644
+ dtape_map_shared_descriptor_t* desc = NULL;
+ if (permission & MAP_MEM_NAMED_CREATE) {
+ memfd = memfd_create("darling-mementry", MFD_CLOEXEC);
+ if (memfd < 0 || ftruncate(memfd, map_size) < 0) {
+ if (memfd >= 0) close(memfd);
+ if (memfd < 0) {
+ dtape_diag_log_shortage("named-create memfd_create", memfd, map_size);
+ return KERN_RESOURCE_SHORTAGE;
+ }
+ if (ftruncate(memfd, map_size) < 0) {
+ dtape_diag_log_shortage("named-create ftruncate", memfd, map_size);
+ close(memfd);
+ return KERN_RESOURCE_SHORTAGE;
+ }
+ } else {
@@ -627,6 +680,7 @@ index 3114947..e2a8d5e 100644
+
+ desc = dtape_map_shared_descriptor_create(memfd, map_size);
+ if (desc == NULL) {
+ dtape_diag_log_shortage("named-entry descriptor malloc", memfd, map_size);
+ close(memfd);
+ return KERN_RESOURCE_SHORTAGE;
+ }
@@ -689,7 +743,7 @@ index 3114947..e2a8d5e 100644
};
kern_return_t mach_memory_info(host_priv_t host, mach_zone_name_array_t* namesp, mach_msg_type_number_t* namesCntp, mach_zone_info_array_t* infop, mach_msg_type_number_t* infoCntp, mach_memory_info_array_t* memoryInfop, mach_msg_type_number_t* memoryInfoCntp) {
@@ -591,8 +791,115 @@ kern_return_t mach_vm_machine_attribute(vm_map_t map, mach_vm_address_t addr, ma
@@ -591,8 +824,115 @@ kern_return_t mach_vm_machine_attribute(vm_map_t map, mach_vm_address_t addr, ma
};
kern_return_t mach_vm_map_external(vm_map_t target_map, mach_vm_offset_t* address, mach_vm_size_t initial_size, mach_vm_offset_t mask, int flags, ipc_port_t port, vm_object_offset_t offset, boolean_t copy, vm_prot_t cur_protection, vm_prot_t max_protection, vm_inherit_t inheritance) {
@@ -807,7 +861,7 @@ index 3114947..e2a8d5e 100644
};
kern_return_t mach_vm_msync(vm_map_t map, mach_vm_offset_t address, mach_vm_size_t size, vm_sync_t sync_flags) {
@@ -620,15 +927,22 @@ kern_return_t mach_vm_msync(vm_map_t map, mach_vm_offset_t address, mach_vm_size
@@ -620,15 +960,22 @@ kern_return_t mach_vm_msync(vm_map_t map, mach_vm_offset_t address, mach_vm_size
};
kern_return_t mach_vm_page_info(vm_map_t map, mach_vm_address_t address, vm_page_info_flavor_t flavor, vm_page_info_t info, mach_msg_type_number_t* count) {
@@ -833,7 +887,7 @@ index 3114947..e2a8d5e 100644
};
kern_return_t mach_vm_protect(vm_map_t map, mach_vm_offset_t start, mach_vm_size_t size, boolean_t set_maximum, vm_prot_t new_protection) {
@@ -756,7 +1070,8 @@ region_info_out:
@@ -756,7 +1103,8 @@ region_info_out:
return kr;
};
default:
@@ -843,7 +897,7 @@ index 3114947..e2a8d5e 100644
}
};
@@ -856,7 +1171,7 @@ static kern_return_t mach_vm_remap_external_shared(vm_map_t target_map, mach_vm_
@@ -856,7 +1204,7 @@ static kern_return_t mach_vm_remap_external_shared(vm_map_t target_map, mach_vm_
src_existing_entry_count = dtape_map_find_shared_entries_locked(src_map, start_memaddr, map_size, src_existing_entries, sizeof(src_existing_entries) / sizeof(*src_existing_entries));
@@ -852,7 +906,7 @@ index 3114947..e2a8d5e 100644
// special case for what LLDB does with dyld info
dtape_map_shared_descriptor_retain(src_existing_entries[0]->descriptor);
descriptor = src_existing_entries[0]->descriptor;
@@ -1441,6 +1756,10 @@ mach_destroy_memory_entry(
@@ -1441,6 +1789,10 @@ mach_destroy_memory_entry(
named_entry->ref_count -= 1;
if (named_entry->ref_count == 0) {
@@ -863,7 +917,7 @@ index 3114947..e2a8d5e 100644
if (named_entry->is_sub_map) {
vm_map_deallocate(named_entry->backing.map);
} else if (named_entry->is_copy) {
@@ -1456,6 +1775,9 @@ mach_destroy_memory_entry(
@@ -1456,6 +1808,9 @@ mach_destroy_memory_entry(
named_entry_unlock(named_entry);
named_entry_lock_destroy(named_entry);
@@ -1802,7 +1856,7 @@ index cc10f1d..7df0056 100644
try {
thread->processSignal(_body.bsd_signal_number, _body.linux_signal_number, _body.code, _body.signal_address, _body.thread_state, _body.float_state);
diff --git a/src/darlingserver.cpp b/src/darlingserver.cpp
index f79f057..2bf9cfb 100644
index f79f057..54c42aa 100644
--- a/src/darlingserver.cpp
+++ b/src/darlingserver.cpp
@@ -497,6 +497,45 @@ static void handle_sigusr1(int signum) {
@@ -1882,7 +1936,25 @@ index f79f057..2bf9cfb 100644
if (argc < 6) {
fprintf(stderr, "darlingserver is not meant to be started manually\n");
exit(1);
@@ -745,6 +808,13 @@ int main(int argc, char** argv) {
@@ -577,8 +640,15 @@ int main(int argc, char** argv) {
// now set our increased rlimit
if (setrlimit(RLIMIT_NOFILE, &increased_limit) != 0) {
- fprintf(stderr, "Warning: failed to increase FD rlimit: %s\n", strerror(errno));
- //exit(1);
+ // darling-lol: a rootless user namespace cannot raise the hard limit.
+ // Still raise the soft limit to it: every named memory entry holds a
+ // memfd here, and Chromium's UX restart pushes past a 1024 soft limit,
+ // failing memfd_create with EMFILE.
+ increased_limit.rlim_cur = increased_limit.rlim_max = default_limit.rlim_max;
+ if (setrlimit(RLIMIT_NOFILE, &increased_limit) != 0) {
+ fprintf(stderr, "Warning: failed to increase FD rlimit: %s\n", strerror(errno));
+ //exit(1);
+ }
}
#endif
@@ -745,6 +815,13 @@ int main(int argc, char** argv) {
#endif
// create the server
+42 -7
View File
@@ -289,7 +289,7 @@ index b7ffcce..5b1e84c 100644
};
};
diff --git a/private-include/indium/command-encoder.private.hpp b/private-include/indium/command-encoder.private.hpp
index c3b1b93..3dab2ce 100644
index c3b1b93..6b8783d 100644
--- a/private-include/indium/command-encoder.private.hpp
+++ b/private-include/indium/command-encoder.private.hpp
@@ -1,6 +1,7 @@
@@ -300,7 +300,7 @@ index c3b1b93..3dab2ce 100644
#include <memory>
#include <optional>
#include <array>
@@ -17,117 +18,295 @@
@@ -17,117 +18,330 @@
#include <iridium/iridium.hpp>
@@ -529,6 +529,40 @@ index c3b1b93..3dab2ce 100644
+ struct AddressPool {
+ std::shared_ptr<Buffer> chunk;
+ size_t used = 0;
+
+ // Two shader stages are live in the render encoder. Cache their small
+ // immutable tables in CPU memory, not in the GPU-mapped scratch chunk.
+ // This is only a read cache: misses retain the original byte comparison.
+ struct Shadow {
+ bool valid = false;
+ uint32_t offset;
+ VkDeviceSize range;
+ size_t count;
+ std::array<uint64_t, 64> addresses;
+ };
+ std::array<Shadow, 2> shadows;
+ size_t nextShadow = 0;
+
+ bool sameAddresses(uint32_t offset, VkDeviceSize range, const uint64_t* addresses, size_t count) const {
+ for (const auto& shadow : shadows) {
+ // A table's last eight bytes can be padding. If a new layout
+ // reads that padding, only the mapped bytes define the old key.
+ if (shadow.valid && shadow.offset == offset && shadow.range == range && count <= shadow.count)
+ return !memcmp(shadow.addresses.data(), addresses, count * sizeof(uint64_t));
+ }
+ return !memcmp(static_cast<const char*>(chunk->contents()) + offset, addresses, count * sizeof(uint64_t));
+ }
+
+ void rememberAddresses(uint32_t offset, VkDeviceSize range, const uint64_t* addresses, size_t count) {
+ if (count > 64) return;
+ auto& shadow = shadows[nextShadow];
+ nextShadow = (nextShadow + 1) % shadows.size();
+ shadow.offset = offset;
+ shadow.range = range;
+ shadow.count = count;
+ memcpy(shadow.addresses.data(), addresses, count * sizeof(uint64_t));
+ shadow.valid = true;
+ }
+ };
- if (functionResources.buffers.size() > 0) {
@@ -583,17 +617,18 @@ index c3b1b93..3dab2ce 100644
+ if (bindingReuseEnabled() && previous && addressPool.chunk && previous->range == tableSize &&
+ previous->offset <= chunkSize && tableSize <= chunkSize - previous->offset &&
+ previous->buffer == static_cast<PrivateBuffer*>(addressPool.chunk.get())->buffer() &&
+ !memcmp(static_cast<const char*>(addressPool.chunk->contents()) + previous->offset,
+ addresses.data(), addresses.size() * sizeof(uint64_t)))
+ addressPool.sameAddresses(previous->offset, previous->range, addresses.data(), addresses.size()))
+ return *previous;
+ size_t tableOffset = (addressPool.used + alignment - 1) & ~(alignment - 1);
+ if (!addressPool.chunk || tableOffset + tableSize > chunkSize) {
+ addressPool.chunk = privateDevice->acquireScratchChunk();
+ for (auto& shadow : addressPool.shadows) shadow.valid = false;
+ // we need to keep the chunk alive until the operation is completed
+ keepAliveBuffers.push_back(addressPool.chunk);
+ tableOffset = 0;
+ }
+ memcpy(static_cast<char*>(addressPool.chunk->contents()) + tableOffset, addresses.data(), addresses.size() * sizeof(uint64_t));
+ if (previous) addressPool.rememberAddresses(static_cast<uint32_t>(tableOffset), tableSize, addresses.data(), addresses.size());
+ addressPool.used = tableOffset + tableSize;
+ // plain pointer: a shared_ptr cast here was an atomic reference count round trip per stage per draw
+ auto* privateAddressBuffer = static_cast<PrivateBuffer*>(addressPool.chunk.get());
@@ -654,7 +689,7 @@ index c3b1b93..3dab2ce 100644
descSet.descriptorCount = 1;
descSet.pBufferInfo = &info;
}
@@ -136,17 +315,27 @@ namespace Indium {
@@ -136,17 +350,27 @@ namespace Indium {
auto& bindingInfo = funcInfo.bindings[j];
if (bindingInfo.type == Iridium::BindingType::Texture) {
@@ -691,7 +726,7 @@ index c3b1b93..3dab2ce 100644
auto& descSet = writeDescSet.emplace_back();
descSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descSet.dstSet = descriptorSets[i];
@@ -156,19 +345,21 @@ namespace Indium {
@@ -156,19 +380,21 @@ namespace Indium {
descSet.descriptorCount = 1;
descSet.pImageInfo = &info;
} else if (bindingInfo.type == Iridium::BindingType::Sampler) {
@@ -724,7 +759,7 @@ index c3b1b93..3dab2ce 100644
info.sampler = privateSampler->sampler();
auto& descSet = writeDescSet.emplace_back();
@@ -188,10 +379,4 @@ namespace Indium {
@@ -188,10 +414,4 @@ namespace Indium {
return descriptorSets;
};
+15
View File
@@ -205,6 +205,21 @@ index 06c5d4aa..9f24ea91 100644
if (context.numTasks >= MAX_TASKS) {
secnotice("http", "Too many fetch %@ requests for this cert", [self class]);
return true;
diff --git a/trust/trustd/macOS/com.apple.trustd.plist b/trust/trustd/macOS/com.apple.trustd.plist
index b3780e3c..71e089a4 100644
--- a/trust/trustd/macOS/com.apple.trustd.plist
+++ b/trust/trustd/macOS/com.apple.trustd.plist
@@ -2,7 +2,9 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
- <key>EnablePressuredExit</key>
+ <key>KeepAlive</key>
+ <true/>
+ <key>RunAtLoad</key>
<true/>
<key>EnableTransactions</key>
<true/>
diff --git a/trust/trustd/trustdFileHelper/main.m b/trust/trustd/trustdFileHelper/main.m
index f6d166e2..fb7ae819 100644
--- a/trust/trustd/trustdFileHelper/main.m
+21 -1
View File
@@ -5051,7 +5051,7 @@ index b998456..c6281e6 100644
+ * (/tmp/rclol-local-semaphores, the former opt-in switch, is now a no-op). While it was on by default in every
+ * process (2026-10-10 22:22-23:50) LeagueClient died ~85 s after start in 3 of 4 checked launches
+ * ("mach_msg_overwrite failed -9", then dserver_rpc_interrupt_enter -9: its RPC descriptor had become invalid) and
+ * the user saw Vanguard errors; that mechanism is not understood, so the clients keep the server path. With the
+ * the client logged integrity-check errors; that mechanism is not understood, so the clients keep the server path. With the
+ * lifetime fixes above the game ran two full matches with it (2026-10-14: the main thread's server waits fell from
+ * 1.36 to 0.10 ms per frame, 39 to 15 blocks per frame). /tmp/rclol-local-semaphores-all turns it on for every
+ * process (probe tests). Decided once per process and logged
@@ -6180,3 +6180,23 @@ index 0000000..eb90f43
+ return true;
+}
+#endif
diff --git a/darling/src/libsystem_kernel/emulation/src/linux_premigration/vchroot_userspace.c b/darling/src/libsystem_kernel/emulation/src/linux_premigration/vchroot_userspace.c
--- a/darling/src/libsystem_kernel/emulation/src/linux_premigration/vchroot_userspace.c
+++ b/darling/src/libsystem_kernel/emulation/src/linux_premigration/vchroot_userspace.c
@@ -421,12 +421,14 @@
ctxt->follow = true;
ctxt->symlink_depth++;
- // resolve absolute symlinks within the prefix
+ // Keep absolute host symlinks outside the prefix after crossing
+ // /Volumes/SystemRoot (e.g. /etc/resolv.conf -> /run/...).
+ // Resolve guest symlinks within the prefix
//
// however, DON'T resolve `/proc` symlinks within the prefix.
// anything under `/proc` is from Linux's `/proc` since we bind-mount it, so we can special-case them because we want those to be Linux-root relative.
// see https://github.com/darlinghq/darling/issues/1052 for the issue this works around.
- if (link[0] == '/' && !(strncmp(link, "/proc/", 6) == 0 || (rv == 5 && strncmp(link, "/proc", 5) == 0))) {
+ if (link[0] == '/' && ctxt->current_root_len > 0 && !(strncmp(link, "/proc/", 6) == 0 || (rv == 5 && strncmp(link, "/proc", 5) == 0))) {
ctxt->current_root = prefix_path;
ctxt->current_root_len = prefix_path_len;
}
+1 -1
View File
@@ -4,4 +4,4 @@ set -eu
repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
cd "$repo"
python3 scripts/configure.py >/dev/null
python3 build/runtime/tools/riot-desktop-entry.py
python3 build/runtime/tools/desktop-entry.py
+175
View File
@@ -0,0 +1,175 @@
// CPU-only buffer/Vulkan shims; the scratch, pool and table helper are extracted
// from the authoritative component patch, not copied into this fixture.
#include <algorithm>
#include <array>
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <memory>
#include <new>
#include <vector>
static size_t allocationCalls = 0;
void* operator new(size_t size) {
++allocationCalls;
if (auto* p = std::malloc(size ? size : 1)) return p;
throw std::bad_alloc();
}
void operator delete(void* p) noexcept { std::free(p); }
void operator delete(void* p, size_t) noexcept { std::free(p); }
using VkBuffer = uint64_t;
using VkDeviceSize = uint64_t;
constexpr VkBuffer VK_NULL_HANDLE = 0;
namespace Iridium { enum class BindingType { Buffer, Texture, Sampler }; }
static bool enabled = true;
bool bindingReuseEnabled() { return enabled; }
void logUnboundResource(const char*, size_t, size_t, size_t) {}
struct Buffer { virtual ~Buffer() = default; virtual void* contents() = 0; };
struct PrivateBuffer : Buffer {
uint64_t id, address;
size_t reads = 0;
std::vector<unsigned char> bytes;
PrivateBuffer(uint64_t id, uint64_t address) : id(id), address(address), bytes(256*1024, 0xa5) {}
void* contents() override { ++reads; return bytes.data(); }
VkBuffer buffer() const { return id; }
uint64_t gpuAddress() const { return address; }
};
struct PrivateDevice {
size_t chunks = 0;
uint64_t fallback = 0xf00d;
uint64_t fallbackBufferAddress() { return fallback; }
std::shared_ptr<Buffer> acquireScratchChunk() { ++chunks; return std::make_shared<PrivateBuffer>(chunks, chunks << 20); }
};
struct FunctionResources { std::vector<std::pair<std::shared_ptr<Buffer>, size_t>> buffers; };
struct Resolved { PrivateBuffer* value = nullptr; };
struct ResolvedFunctionResources { std::vector<Resolved> buffers; };
struct Binding { Iridium::BindingType type; size_t index; };
struct FunctionInfo { std::vector<Binding> bindings; };
/* ACTUAL_PATCHED_HELPER */
struct Check {
AddressPool pool;
std::shared_ptr<PrivateDevice> device = std::make_shared<PrivateDevice>();
std::vector<std::shared_ptr<Buffer>> keep;
std::array<BufferAddressTable, 4> tables{};
Check() { keep.reserve(8); }
PrivateBuffer* mapped() { return static_cast<PrivateBuffer*>(pool.chunk.get()); }
void run(size_t stage, const FunctionResources& resources, const FunctionInfo& info,
bool reuse, const ResolvedFunctionResources* resolved = nullptr, bool previous = true) {
auto old = tables[stage];
auto used = pool.used, chunks = device->chunks, calls = allocationCalls;
auto table = makeBufferAddressTable(resources, info, resolved, device, keep, pool,
previous ? &tables[stage] : nullptr);
// Only the existing DescriptorScratch overflow and new scratch chunk
// may allocate (make_shared control/object plus the chunk byte vector).
assert(allocationCalls - calls == (info.bindings.size() > 64 ? 1u : 0u) +
(device->chunks - chunks) * 2);
assert((table.buffer == old.buffer && table.offset == old.offset && pool.used == used) == reuse);
assert(table.range == ((std::count_if(info.bindings.begin(), info.bindings.end(),
[](const Binding& b) { return b.type == Iridium::BindingType::Buffer; }) * 8 + 15) & ~size_t(15)));
assert(keep.size() == device->chunks);
size_t index = 0;
for (const auto& binding : info.bindings) {
if (binding.type != Iridium::BindingType::Buffer) continue;
PrivateBuffer* buffer = nullptr;
if (resolved && binding.index < resolved->buffers.size()) buffer = resolved->buffers[binding.index].value;
else if (binding.index < resources.buffers.size()) buffer = dynamic_cast<PrivateBuffer*>(resources.buffers[binding.index].first.get());
uint64_t expected = buffer ? buffer->gpuAddress() + resources.buffers[binding.index].second : device->fallback;
uint64_t actual;
memcpy(&actual, mapped()->bytes.data() + table.offset + index++ * 8, 8);
assert(actual == expected);
}
tables[stage] = table;
}
};
FunctionInfo info(size_t count, size_t start = 0) {
FunctionInfo result;
for (size_t i = 0; i < count; ++i) result.bindings.push_back({Iridium::BindingType::Buffer, start+i});
return result;
}
int main() {
// Two 64-key entries: +1080 bytes per pool on the tested 64-bit ABI.
static_assert(sizeof(AddressPool) == sizeof(std::shared_ptr<Buffer>) + sizeof(size_t) + 1080);
FunctionResources r;
auto resource = std::make_shared<PrivateBuffer>(100, 0x1000);
for (size_t i = 0; i < 150; ++i) r.buffers.push_back({resource, i*16});
Check p;
auto f = info(3);
p.run(0, r, f, false);
auto accesses = p.mapped()->reads;
p.run(0, r, f, true); assert(p.mapped()->reads == accesses);
r.buffers[100].second++; p.run(0, r, f, true);
auto equivalent = std::make_shared<PrivateBuffer>(101, 0x0ff0);
r.buffers[0] = {equivalent, 16}; p.run(0, r, f, true);
r.buffers[1].second++; p.run(0, r, f, false);
auto mixed = f;
mixed.bindings.push_back({Iridium::BindingType::Texture, 999});
mixed.bindings.push_back({Iridium::BindingType::Sampler, 999});
p.run(0, r, mixed, true);
p.run(1, r, info(4, 20), false);
accesses = p.mapped()->reads;
p.run(0, r, f, true); p.run(1, r, info(4, 20), true);
assert(p.mapped()->reads == accesses); // both interleaved stages hit CPU keys
for (size_t i = 0; i < 5; ++i) {
r.buffers[20].second++; p.run(1, r, info(4, 20), false);
}
accesses = p.mapped()->reads;
p.run(0, r, f, true);
assert(p.mapped()->reads == accesses + 1); // eviction retains mapped fallback
Check padding;
padding.run(0, r, info(1), false);
r.buffers[1] = {resource, uint64_t(0xa5a5a5a5a5a5a5a5ULL - resource->gpuAddress())};
accesses = padding.mapped()->reads;
padding.run(0, r, info(2), true); // odd -> even reads real padding
assert(padding.mapped()->reads == accesses + 1);
r.buffers[1].second++; padding.run(0, r, info(2), false);
accesses = padding.mapped()->reads;
padding.run(0, r, info(1), true); // even -> odd needs only cached prefix
assert(padding.mapped()->reads == accesses);
padding.run(0, r, info(3), false);
Check large;
for (size_t count : {size_t(64), size_t(65), size_t(150), size_t(32767), size_t(32768)}) {
large.run(0, r, info(count), false);
large.run(0, r, info(count), true);
}
r.buffers[64].second++; large.run(0, r, info(65), false);
large.run(1, r, info(8), false, nullptr, false);
large.run(1, r, info(8), true);
Check missing;
FunctionResources empty;
missing.run(0, empty, info(2, 999), false);
missing.run(0, empty, info(2, 999), true);
missing.device->fallback++; missing.run(0, empty, info(2, 999), false);
ResolvedFunctionResources resolved;
resolved.buffers.resize(r.buffers.size()); resolved.buffers[0].value = resource.get();
missing.run(1, r, info(1), false, &resolved);
missing.run(1, r, info(1), true, &resolved);
resolved.buffers[0].value = nullptr;
missing.run(1, r, info(1), false, &resolved);
Check roll;
roll.run(0, r, info(2), false); roll.run(1, r, info(2, 3), false);
auto oldChunk = roll.pool.chunk;
roll.pool.used = 256*1024;
r.buffers[0].second++; roll.run(0, r, info(2), false);
assert(roll.pool.chunk != oldChunk && roll.keep.size() == 2);
// Old offset 256 must not supply a stale key for untouched new-chunk bytes.
roll.tables[1] = {roll.tables[0].buffer, 256, 16};
roll.run(1, r, info(2, 3), false); roll.run(1, r, info(2, 3), true);
enabled = false; roll.run(1, r, info(2, 3), false); enabled = true;
Check guard;
guard.run(0, r, info(0), false); guard.run(0, r, info(0), true);
auto id = guard.tables[0].buffer;
guard.tables[0] = {id, 256*1024, 0}; guard.run(0, r, info(0), true);
guard.tables[0] = {id, 256*1024+1, 0}; guard.run(0, r, info(0), false);
accesses = guard.mapped()->reads;
guard.tables[0] = {id, 256*1024-8, 16}; guard.run(0, r, info(1), false);
assert(guard.mapped()->reads == accesses + 1); // write only; no invalid read
guard.tables[0].buffer += 100; guard.run(0, r, info(1), false);
guard.tables[0].range = 32; guard.run(0, r, info(1), false);
}
+110
View File
@@ -0,0 +1,110 @@
"""Exercise orphan-helper cleanup with fake /proc entries and mocked signals."""
import importlib.util
import io
import os
from pathlib import Path
import signal
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location(
'clean_stale_helpers', ROOT / 'tools/clean-stale-helpers.py')
clean_stale_helpers = importlib.util.module_from_spec(spec)
spec.loader.exec_module(clean_stale_helpers)
HELPER = '/repo/tools/close-league-client-in-game.py'
HIDE_HELPER = '/repo/tools/hide-league-client-in-game.py'
class CleanStaleHelpersTests(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
self.proc = self.root / 'proc'
self.proc.mkdir()
self.prefix = self.root / '.darling'
self.other = self.root / 'other-prefix'
def parent(self, pid, comm):
folder = self.proc / str(pid)
folder.mkdir(exist_ok=True)
(folder / 'comm').write_text(comm + '\n')
def process(self, pid, script=HELPER, parent_pid=500, parent_comm='systemd',
prefix='own', argv0='/usr/bin/python3', state='S',
environment=True, arguments=('--detach',)):
folder = self.proc / str(pid)
folder.mkdir()
argv = [argv0, script, *arguments]
(folder / 'cmdline').write_bytes(
b'\0'.join(arg.encode() for arg in argv) + b'\0')
if parent_comm is not None:
self.parent(parent_pid, parent_comm)
fields = [state, str(parent_pid)] + ['0'] * 17 + ['100']
(folder / 'stat').write_text(f'{pid} (python3) ' + ' '.join(fields) + '\n')
if environment:
prefix = self.prefix if prefix == 'own' else prefix
(folder / 'environ').write_bytes(
b'DPREFIX=' + os.fsencode(prefix) + b'\0')
else:
(folder / 'environ').write_bytes(b'UNRELATED=1\0')
return folder
def run_clean(self, dry_run=False):
killed = []
def kill(pid, signum):
killed.append((pid, signum))
out = io.StringIO()
result = clean_stale_helpers.clean(
self.prefix, proc_root=self.proc, kill=kill,
sleep=lambda _seconds: None, out=out, dry_run=dry_run)
return result, killed, out.getvalue()
def test_removes_only_orphaned_helpers_of_this_prefix(self):
self.process(100, HELPER)
self.process(101, HIDE_HELPER)
self.process(200, HELPER, parent_pid=600, parent_comm='darling')
self.process(201, HELPER, prefix=self.other)
self.process(202, HELPER, argv0='/usr/bin/vim')
self.process(203, HELPER, state='Z')
self.process(204, HELPER, environment=False)
self.process(205, HELPER, parent_pid=700, parent_comm=None)
result, killed, output = self.run_clean()
self.assertEqual(result, 0)
self.assertEqual(sorted(killed), sorted([
(100, signal.SIGTERM), (100, signal.SIGKILL),
(101, signal.SIGTERM), (101, signal.SIGKILL),
]))
self.assertIn('removing 2 orphaned helper(s): 100,101', output)
def test_dry_run_reports_without_signalling(self):
self.process(100)
result, killed, output = self.run_clean(dry_run=True)
self.assertEqual((result, killed), (0, []))
self.assertIn('would remove 1 orphaned helper(s): 100', output)
def test_no_orphans_is_a_noop(self):
self.process(200, parent_pid=600, parent_comm='darling')
result, killed, output = self.run_clean()
self.assertEqual((result, killed), (0, []))
self.assertIn('no orphaned helpers', output)
def test_relative_helper_prefix_is_preserved(self):
self.process(100, prefix='relative-prefix')
result, killed, output = self.run_clean()
self.assertEqual((result, killed), (0, []))
self.assertIn('no orphaned helpers', output)
def test_launcher_runs_cleanup_before_starting_a_helper(self):
source = (ROOT / 'tools/run-riot-client.sh').read_text()
self.assertIn('RCLOL_CLEAN_STALE_HELPERS', source)
self.assertLess(source.index('clean-stale-helpers.py'),
source.index('close-league-client-in-game.py'))
if __name__ == '__main__':
unittest.main()
+99
View File
@@ -0,0 +1,99 @@
"""Select the automatic client-in-game mode from LCULocalPreferences.yaml."""
import importlib.util
import io
import os
from pathlib import Path
import tempfile
import unittest
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location(
'client_in_game_tricks', ROOT / 'tools/client-in-game-tricks.py')
tricks = importlib.util.module_from_spec(spec)
spec.loader.exec_module(tricks)
class ClientInGameTricksTests(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.path = Path(self.temp.name) / 'LCULocalPreferences.yaml'
def write(self, optimization=None, close=None):
lines = ['lol-user-experience:', ' data:']
if optimization is not None:
lines.append(f' potatoModeEnabled: {optimization}')
if close is not None:
lines.append(f' closeLeagueClientDuringGame: {close}')
self.path.write_text('\n'.join(lines) + '\n')
def test_close_when_both_preferences_are_true(self):
self.write(True, True)
self.assertEqual(tricks.mode(self.path), 'close')
def test_hide_when_optimizations_are_on_and_close_is_false(self):
self.write(True, False)
self.assertEqual(tricks.mode(self.path), 'hide')
def test_none_when_close_preference_is_missing_or_invalid(self):
self.write(True)
self.assertEqual(tricks.mode(self.path), 'none')
for value in ('maybe', '"true', 'true#note', '"true"junk'):
self.write(True, value)
self.assertEqual(tricks.mode(self.path), 'none', value)
def test_none_when_optimizations_are_off(self):
self.write(False, True)
self.assertEqual(tricks.mode(self.path), 'none')
def test_none_when_optimizations_are_missing_or_file_is_unreadable(self):
self.write(None, True)
self.assertEqual(tricks.mode(self.path), 'none')
self.assertEqual(tricks.mode(self.path.with_name('missing.yaml')), 'none')
def test_last_duplicate_value_wins_and_quotes_are_accepted(self):
self.path.write_text(
'lol-user-experience:\n'
' data:\n'
' potatoModeEnabled: false\n'
' closeLeagueClientDuringGame: false\n'
' potatoModeEnabled: "true"\n'
' closeLeagueClientDuringGame: "true"\n')
self.assertEqual(tricks.mode(self.path), 'close')
def test_keys_outside_the_named_section_are_ignored(self):
self.path.write_text(
'lol-user-experience:\n'
' data:\n'
' potatoModeEnabled: true\n'
' closeLeagueClientDuringGame: false\n'
'other-section:\n'
' potatoModeEnabled: true\n'
' closeLeagueClientDuringGame: true\n')
self.assertEqual(tricks.mode(self.path), 'hide')
def test_inline_yaml_comments_are_ignored(self):
self.path.write_text(
'lol-user-experience:\n'
' data:\n'
' potatoModeEnabled: true # client optimizations\n'
' closeLeagueClientDuringGame: "true" # close during matches\n')
self.assertEqual(tricks.mode(self.path), 'close')
def test_second_read_failure_fails_closed(self):
self.write(True, False)
text = self.path.read_text()
with patch.object(Path, 'read_text', side_effect=[text, OSError()]):
self.assertEqual(tricks.mode(self.path), 'none')
def test_main_prints_mode(self):
self.write(True, False)
output = io.StringIO()
with patch('sys.stdout', output):
self.assertEqual(tricks.main([str(self.path)]), 0)
self.assertEqual(output.getvalue().strip(), 'hide')
if __name__ == '__main__':
unittest.main()
+157
View File
@@ -0,0 +1,157 @@
"""Verify the desktop-entry helper against a disposable HOME."""
import os
import re
import shutil
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
HELPER = ROOT / 'tools/desktop-entry.py'
FLAKE = ROOT / 'flake.nix'
OLD_SVG = '<svg><linearGradient id="goldGrad"/><path d="M172 108 L242 108"/></svg>'
IDENTITY_KEYS = ('Name', 'GenericName', 'Comment', 'Icon', 'Keywords', 'Categories', 'StartupWMClass')
def parse_entry(text):
entry = {}
for line in text.splitlines():
if '=' in line and not line.startswith(('#', '[')):
key, value = line.split('=', 1)
entry[key] = value
return entry
class DesktopEntryTests(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory(prefix='desktop entry ', dir=os.environ.get('TMPDIR'))
self.addCleanup(self.tmp.cleanup)
self.root = Path(self.tmp.name)
self.home = self.root / 'home'
self.home.mkdir()
def project(self, name='project'):
project = self.root / name
project.mkdir(parents=True)
shutil.copy2(ROOT / 'darling-lol.svg', project / 'darling-lol.svg')
shutil.copy2(ROOT / 'darling-lol.png', project / 'darling-lol.png')
return project
def install(self, project):
script = project / 'desktop-entry.py'
script.write_text(HELPER.read_text()
.replace('@PROJECT_ROOT@', str(project))
.replace('@HOST_HOME@', str(self.home)))
return subprocess.run([sys.executable, str(script)], capture_output=True, text=True,
env=dict(os.environ, HOME=str(self.home)), check=False)
def entry(self):
return self.home / '.local/share/applications/darling-launcher.desktop'
def icons(self):
base = self.home / '.local/share/icons'
return base / 'hicolor/scalable/apps/darling-launcher.svg', base / 'hicolor/128x128/apps/darling-launcher.png'
def test_installs_neutral_entry_and_icons(self):
project = self.project()
result = self.install(project)
self.assertEqual(result.returncode, 0, result.stderr)
text = self.entry().read_text()
self.assertIn('Name=Darling Launcher\n', text)
self.assertIn('Icon=darling-launcher\n', text)
self.assertIn(f'Path={project}\n', text)
for field in ('Name', 'Comment', 'GenericName', 'Keywords'):
line = next(line for line in text.splitlines() if line.startswith(field + '='))
for brand in ('League', 'LoL', 'Riot', 'Vanguard', 'anti-cheat'):
self.assertNotIn(brand.lower(), line.lower())
svg, png = self.icons()
self.assertTrue(svg.is_file())
self.assertTrue(png.is_file())
self.assertEqual(png.read_bytes(), (project / 'darling-lol.png').read_bytes())
def test_preserves_entries_and_icons_it_did_not_create(self):
project = self.project()
other = self.root / 'elsewhere'
(self.home / '.local/share/applications').mkdir(parents=True)
legacy_entry = self.home / '.local/share/applications/league-of-legends.desktop'
legacy_entry.write_text(f'[Desktop Entry]\nExec={other}/scripts/desktop-run.sh\n')
(self.home / 'Desktop').mkdir()
desktop_entry = self.home / 'Desktop/league-of-legends.desktop'
desktop_entry.write_text(f'[Desktop Entry]\nExec={other}/scripts/desktop-run.sh\n')
icons = self.home / '.local/share/icons'
icons.mkdir(parents=True)
(icons / 'league-of-legends.png').write_text('user icon')
result = self.install(project)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertTrue(legacy_entry.is_file())
self.assertTrue(desktop_entry.is_file())
self.assertEqual((icons / 'league-of-legends.png').read_text(), 'user icon')
self.assertTrue(self.entry().is_file())
def test_removes_legacy_artifacts_it_created(self):
project = self.project()
applications = self.home / '.local/share/applications'
applications.mkdir(parents=True)
owned = f'[Desktop Entry]\nExec="{project}/scripts/desktop-run.sh"\n'
legacy_entry = applications / 'league-of-legends.desktop'
legacy_entry.write_text(owned)
(self.home / 'Desktop').mkdir()
desktop_link = self.home / 'Desktop/league-of-legends.desktop'
desktop_link.symlink_to(project / 'scripts/desktop-run.sh')
icons = self.home / '.local/share/icons'
scalable = icons / 'hicolor/scalable/apps'
legacy_png_dir = icons / 'hicolor/512x512/apps'
scalable.mkdir(parents=True)
legacy_png_dir.mkdir(parents=True)
legacy_svg = scalable / 'league-of-legends.svg'
legacy_svg.write_text(OLD_SVG)
legacy_png = legacy_png_dir / 'league-of-legends.png'
legacy_png.write_bytes(b'old client icon')
result = self.install(project)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertFalse(legacy_entry.exists())
self.assertFalse(desktop_link.is_symlink())
self.assertFalse(legacy_svg.exists())
self.assertFalse(legacy_png.exists())
self.assertTrue(self.entry().is_file())
def test_quotes_exec_arguments_with_reserved_characters(self):
project = self.project('proj $dollar#hash\'quote')
result = self.install(project)
self.assertEqual(result.returncode, 0, result.stderr)
text = self.entry().read_text()
exec_line = next(line for line in text.splitlines() if line.startswith('Exec='))
self.assertTrue(exec_line.startswith('Exec="'), exec_line)
self.assertTrue(exec_line.endswith('"'), exec_line)
self.assertIn('\\$dollar', exec_line)
if shutil.which('desktop-file-validate'):
check = subprocess.run(['desktop-file-validate', str(self.entry())],
capture_output=True, text=True, check=False)
self.assertEqual(check.returncode, 0, check.stdout + check.stderr)
def test_identity_fields_match_the_packaged_entry(self):
project = self.project()
result = self.install(project)
self.assertEqual(result.returncode, 0, result.stderr)
rendered = parse_entry(self.entry().read_text())
packaged_here = re.search(
r"cat << 'DESKTOP_EOF' > \$out/share/applications/darling-launcher\.desktop\n(.*?)\n\s*DESKTOP_EOF",
FLAKE.read_text(), re.S)
self.assertIsNotNone(packaged_here, 'packaged desktop entry not found in flake.nix')
packaged = parse_entry(packaged_here.group(1))
for key in IDENTITY_KEYS:
self.assertIn(key, packaged)
self.assertEqual(rendered.get(key), packaged[key], key)
def test_missing_icon_fails(self):
project = self.project()
(project / 'darling-lol.png').unlink()
result = self.install(project)
self.assertNotEqual(result.returncode, 0)
self.assertIn('launcher icon is missing', result.stderr)
if __name__ == '__main__':
unittest.main()
+346
View File
@@ -0,0 +1,346 @@
"""Exercise the in-match client window hide with fake /proc entries and X11."""
import importlib.util
import io
import os
from pathlib import Path
import tempfile
import unittest
from unittest.mock import Mock, patch
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location(
'hide_in_game', ROOT / 'tools/hide-league-client-in-game.py')
hide_in_game = importlib.util.module_from_spec(spec)
spec.loader.exec_module(hide_in_game)
GAME = '/Applications/League of Legends.app/Contents/LoL/LeagueofLegends'
MAIN = '/Applications/League of Legends.app/Contents/LoL/LeagueClientUx.app/Contents/MacOS/LeagueClientUx'
RIOT = '/Applications/Riot Client.app/Contents/MacOS/RiotClientServices'
class FakeX11:
def __init__(self):
self.unmapped = []
self.shown = []
def unmap(self, window):
self.unmapped.append(window)
def show(self, window):
self.shown.append(window)
class HideClientInGameTests(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
self.proc = self.root / 'proc'
self.proc.mkdir()
self.prefix = self.root / '.darling'
self.env_patch = patch.dict(os.environ, {'DPREFIX': str(self.prefix)})
self.env_patch.start()
self.addCleanup(self.env_patch.stop)
def environment(self, prefix):
return b'%s=%s\0' % (
hide_in_game.SOCK_VARIABLE,
os.fsencode(prefix / hide_in_game.SOCK_NAME),
)
def process(self, pid, executable=GAME, prefix='own', environ=None, args=('--flag',)):
folder = self.proc / str(pid)
folder.mkdir()
(folder / 'cmdline').write_bytes(
executable.encode() + b'\0' +
b''.join(arg.encode() + b'\0' for arg in args))
if environ is None:
environ = self.environment(self.prefix if prefix == 'own' else prefix)
(folder / 'environ').write_bytes(environ)
(folder / 'stat').write_text(f'{pid} (game) S')
return folder
def test_game_running_for_own_prefix(self):
self.process(123)
self.assertTrue(hide_in_game.game_running(self.prefix, self.proc))
def test_no_game_is_false(self):
self.process(123, executable=MAIN)
self.assertFalse(hide_in_game.game_running(self.prefix, self.proc))
def test_game_of_another_prefix_is_false(self):
self.process(123, prefix=self.root / 'other')
self.assertFalse(hide_in_game.game_running(self.prefix, self.proc))
def test_game_without_socket_is_false(self):
self.process(123, environ=b'')
self.assertFalse(hide_in_game.game_running(self.prefix, self.proc))
def test_unreadable_environment_is_unknown(self):
folder = self.process(123)
original = Path.read_bytes
def read(path):
if path.name == 'environ':
raise PermissionError()
return original(path)
with patch.object(Path, 'read_bytes', read):
self.assertIsNone(hide_in_game.game_running(self.prefix, self.proc))
def test_unreadable_process_directory_is_unknown(self):
class UnreadableProc:
def iterdir(self):
raise OSError()
self.assertIsNone(hide_in_game.game_running(self.prefix, UnreadableProc()))
def test_host_socket_for_guest_uses_nspid(self):
host = self.proc / '999'
host.mkdir()
(host / 'status').write_text('Name:\tCrBrowserMain\nNSpid:\t999\t5877\n')
(host / 'environ').write_bytes(self.environment(self.prefix))
self.assertEqual(
hide_in_game.host_socket_for_guest(5877, self.proc),
os.fsencode(self.prefix / hide_in_game.SOCK_NAME),
)
def test_window_belongs_to_prefix(self):
socket = os.fsencode(self.prefix / hide_in_game.SOCK_NAME)
with patch.object(hide_in_game, 'window_pid', return_value=5877), \
patch.object(hide_in_game, 'host_socket_for_guest', return_value=socket):
self.assertTrue(hide_in_game.window_belongs_to_prefix('0x10', self.prefix))
self.assertFalse(hide_in_game.window_belongs_to_prefix(
'0x10', self.root / 'other'))
def test_once_runs_without_opt_in(self):
output = io.StringIO()
with patch.dict(os.environ, {
'RCLOL_HIDE_CLIENT_IN_GAME': '',
'RCLOL_CLOSE_CLIENT_IN_GAME': '',
}), patch.object(hide_in_game, 'target_prefix',
return_value=self.prefix), \
patch.object(hide_in_game, 'game_running', return_value=True), \
patch.object(hide_in_game.sys, 'stdout', output):
self.assertEqual(hide_in_game.main(['--once']), 0)
self.assertIn('match=running', output.getvalue())
def test_target_windows_ignores_game_class(self):
with patch.object(hide_in_game, 'xprop_root',
return_value=['0x10', '0x20', '0x30']), \
patch.object(hide_in_game, 'window_class',
side_effect=[
'wm_class(string) = "leagueclientux"',
'wm_class(string) = "leagueoflegends"',
'wm_class(string) = "riot client"',
]), \
patch.object(hide_in_game, 'window_belongs_to_prefix', return_value=True):
self.assertEqual(hide_in_game.target_windows(self.prefix), [0x10, 0x30])
def test_target_windows_requires_this_prefix(self):
with patch.object(hide_in_game, 'xprop_root',
return_value=['0x10', '0x20']), \
patch.object(hide_in_game, 'window_class',
return_value='wm_class(string) = "leagueclientux"'), \
patch.object(hide_in_game, 'window_belongs_to_prefix',
side_effect=[True, False]):
self.assertEqual(hide_in_game.target_windows(self.prefix), [0x10])
def test_target_windows_caches_non_empty_classes(self):
cache = {}
with patch.object(hide_in_game, 'xprop_root', return_value=['0x10']), \
patch.object(hide_in_game, 'window_class',
return_value='wm_class(string) = "leagueclientux"') as classes, \
patch.object(hide_in_game, 'window_belongs_to_prefix', return_value=True):
self.assertEqual(hide_in_game.target_windows(self.prefix, cache), [0x10])
self.assertEqual(hide_in_game.target_windows(self.prefix, cache), [0x10])
self.assertEqual(classes.call_count, 1)
def test_missing_wm_class_is_not_cached_as_a_class(self):
with patch.object(hide_in_game, 'xprop_value',
return_value='WM_CLASS: not found.'):
self.assertEqual(hide_in_game.window_class('0x10'), '')
def test_unmap_failure_removes_the_window_from_hidden(self):
class FailingX11(FakeX11):
def unmap(self, window):
raise RuntimeError('unmap failed')
watcher = hide_in_game.Watcher(
self.prefix, FailingX11(),
window_source=lambda _prefix, _cache: [0xabc],
state_source=lambda _prefix: True,
sleep=lambda _seconds: None,
out=io.StringIO(),
)
watcher._hide_new()
self.assertEqual(watcher.hidden, set())
def test_interrupted_unmap_keeps_the_window_tracked(self):
shown = []
class InterruptingX11:
def unmap(self, window):
raise KeyboardInterrupt
def show(self, window):
shown.append(window)
watcher = hide_in_game.Watcher(
self.prefix, InterruptingX11(),
window_source=lambda _prefix, _cache: [0xabc],
state_source=lambda _prefix: True,
sleep=lambda _seconds: None,
out=io.StringIO(),
)
with self.assertRaises(KeyboardInterrupt):
watcher._hide_new()
self.assertEqual(watcher.hidden, {0xabc})
watcher.restore()
self.assertEqual(shown, [0xabc])
def test_log_failure_does_not_discard_an_unmapped_window(self):
class BrokenOutput:
def write(self, _text):
raise BrokenPipeError
def flush(self):
pass
watcher = hide_in_game.Watcher(
self.prefix, FakeX11(),
window_source=lambda _prefix, _cache: [0xabc],
state_source=lambda _prefix: True,
sleep=lambda _seconds: None,
out=BrokenOutput(),
)
watcher._hide_new()
self.assertEqual(watcher.hidden, {0xabc})
def test_restore_log_failure_still_shows_the_window(self):
class BrokenOutput:
def write(self, _text):
raise BrokenPipeError
def flush(self):
pass
x11 = FakeX11()
watcher = hide_in_game.Watcher(
self.prefix, x11,
window_source=lambda _prefix, _cache: [0xabc],
state_source=lambda _prefix: True,
sleep=lambda _seconds: None,
out=BrokenOutput(),
)
watcher.hidden = {0xabc}
watcher._show_all('test')
self.assertEqual(x11.shown, [0xabc])
self.assertEqual(watcher.hidden, set())
def test_idle_timeout_leaves_after_client_disappears(self):
states = iter([True, False, False])
windows = iter([[0xabc], [], []])
times = iter([0.0, 10.0, 700.0])
x11 = FakeX11()
output = io.StringIO()
watcher = hide_in_game.Watcher(
self.prefix, x11,
window_source=lambda _prefix, _cache: next(windows),
state_source=lambda _prefix: next(states),
sleep=lambda _seconds: None,
out=output,
clock=lambda: next(times),
)
self.assertEqual(watcher.run(max_steps=3), 0)
self.assertEqual(x11.unmapped, [0xabc])
self.assertEqual(x11.shown, [0xabc])
self.assertIn('no client or match', output.getvalue())
def test_hides_then_shows_on_match_end(self):
states = iter([True, True, False])
x11 = FakeX11()
output = io.StringIO()
watcher = hide_in_game.Watcher(
self.prefix, x11,
window_source=lambda _prefix, _cache: [0xabc],
state_source=lambda _prefix: next(states),
sleep=lambda _seconds: None,
out=output,
)
watcher.run(max_steps=3)
self.assertEqual(x11.unmapped, [0xabc])
self.assertEqual(x11.shown, [0xabc])
self.assertIn('hidden 0xabc', output.getvalue())
self.assertIn('the match ended', output.getvalue())
self.assertIn('shown 0xabc', output.getvalue())
def test_unreadable_state_restores_the_window(self):
states = iter([True, None])
x11 = FakeX11()
output = io.StringIO()
watcher = hide_in_game.Watcher(
self.prefix, x11,
window_source=lambda _prefix, _cache: [0xdef],
state_source=lambda _prefix: next(states),
sleep=lambda _seconds: None,
out=output,
)
watcher.run(max_steps=2)
self.assertEqual(x11.unmapped, [0xdef])
self.assertEqual(x11.shown, [0xdef])
self.assertIn('unreadable /proc state', output.getvalue())
def test_no_game_does_not_touch_windows(self):
x11 = FakeX11()
watcher = hide_in_game.Watcher(
self.prefix, x11,
window_source=lambda _prefix, _cache: [0xabc],
state_source=lambda _prefix: False,
sleep=lambda _seconds: None,
out=io.StringIO(),
)
watcher.run(max_steps=1)
self.assertEqual(x11.unmapped, [])
self.assertEqual(x11.shown, [])
def test_main_is_disabled_by_default(self):
with patch.dict(os.environ, {
'RCLOL_HIDE_CLIENT_IN_GAME': '',
'RCLOL_CLOSE_CLIENT_IN_GAME': '',
}):
self.assertEqual(hide_in_game.main([]), 0)
def test_close_mode_takes_precedence(self):
with patch.dict(os.environ, {
'RCLOL_HIDE_CLIENT_IN_GAME': '1',
'RCLOL_CLOSE_CLIENT_IN_GAME': '1',
}):
self.assertEqual(hide_in_game.main([]), 0)
def test_helper_starts_after_the_installed_client_check(self):
source = (ROOT / 'tools/run-riot-client.sh').read_text()
self.assertLess(source.index('Riot Client is not installed in'),
source.index('RCLOL_CLIENT_IN_GAME_TRICKS'))
def test_master_tricks_switch_enables_hide(self):
class FakeX11:
def close(self):
pass
watcher = Mock()
with patch.dict(os.environ, {
'RCLOL_CLIENT_IN_GAME_TRICKS': '1',
'RCLOL_HIDE_CLIENT_IN_GAME': '',
'RCLOL_CLOSE_CLIENT_IN_GAME': '',
}), patch.object(hide_in_game, 'target_prefix',
return_value=self.prefix), \
patch.object(hide_in_game, 'X11', return_value=FakeX11()), \
patch.object(hide_in_game, 'Watcher', return_value=watcher):
self.assertEqual(hide_in_game.main([]), 0)
watcher.run.assert_called_once_with()
watcher.restore.assert_called_once_with()
if __name__ == '__main__':
unittest.main()
+133
View File
@@ -0,0 +1,133 @@
"""Exercise the base resolver install and actual vchroot code without DNS traffic."""
from pathlib import Path
import os
import shutil
import subprocess
import tempfile
import unittest
import test_runtime_compatibility as sources
@unittest.skipUnless(shutil.which('cc') and shutil.which('patch'), 'C compiler and patch required')
class HostDNSChecks(unittest.TestCase):
patched = sources.CompatibilityChecks.patched
def setUp(self):
self.temporary = tempfile.TemporaryDirectory(prefix='host-dns-')
self.addCleanup(self.temporary.cleanup)
self.root = Path(self.temporary.name)
self.prefix = self.root / 'guest'
(self.prefix / 'private/etc').mkdir(parents=True)
(self.prefix / 'Volumes/SystemRoot').mkdir(parents=True)
(self.prefix / 'etc').symlink_to('private/etc')
self.resolver = self.prefix / 'private/etc/resolv.conf'
def build_vchroot(self):
path = 'darling/src/libsystem_kernel/emulation/'
source = self.patched('xnu', path + 'src/linux_premigration/vchroot_userspace.c')
header = self.root / 'darling/emulation/linux_premigration/vchroot_expand.h'
header.parent.mkdir(parents=True)
header.write_text(self.patched('xnu', path + 'include/linux_premigration/vchroot_expand.h'))
# Use upstream's Linux TEST mode, replacing only its CLI and RPC setup.
fixture = r'''
#define _GNU_SOURCE
#define TEST
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#define LC_C_LOCALE 0
#define strncasecmp_l(a,b,n,l) strncasecmp(a,b,n)
#define __simple_printf printf
#define __simple_abort abort
static int dserver_rpc_vchroot_path(char *p, unsigned long n, uint64_t *len) { abort(); }
#define main upstream_main
'''
fixture += source + r'''
#undef main
int main(int argc, const char **argv) {
if (argc != 3) return 2;
int fd = open(argv[1], O_RDONLY | O_DIRECTORY);
if (fd < 0 || __darling_vchroot(fd)) return 3;
close(fd);
struct vchroot_expand_args args = {.dfd = -100, .flags = VCHROOT_FOLLOW};
strcpy(args.path, argv[2]);
int result = vchroot_expand(&args);
if (result) return 4;
FILE *file = fopen(args.path, "r");
if (!file) return 5;
char buf[4096];
while (fgets(buf, sizeof(buf), file)) fputs(buf, stdout);
return fclose(file) != 0;
}
'''
file = self.root / 'check.c'
file.write_text(fixture)
self.binary = self.root / 'check'
result = subprocess.run(['cc', '-std=gnu11', '-I', str(self.root), str(file),
'-o', str(self.binary)], capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stderr)
def read_guest(self, path='/etc/resolv.conf'):
result = subprocess.run([str(self.binary), str(self.prefix), path],
capture_output=True, text=True, timeout=10)
self.assertEqual(result.returncode, 0, result.stderr)
return result.stdout
def test_host_symlink_chains_updates_and_guest_override(self):
self.build_vchroot()
host = self.root / 'host'
host.mkdir()
data = host / 'stub-resolv.conf'
data.write_text('nameserver 127.0.0.53\nsearch tether.example\n')
self.resolver.symlink_to('/Volumes/SystemRoot' + str(data))
self.assertEqual(self.read_guest(), data.read_text())
self.resolver.unlink()
# An absolute host link followed by a relative one models resolved and
# NetworkManager layouts. Never write to the real host resolver.
(host / 'relative').symlink_to(data.name)
(host / 'resolv.conf').symlink_to(host / 'relative')
self.resolver.symlink_to('/Volumes/SystemRoot' + str(host / 'resolv.conf'))
self.assertEqual(self.read_guest(), data.read_text())
# Network managers replace files atomically; a bind mount or snapshot
# would keep reading the old resolver inode.
replacement = host / 'next'
replacement.write_text('nameserver 192.0.2.53\n')
os.replace(replacement, data)
self.assertEqual(self.read_guest(), data.read_text())
other = host / 'other'
other.write_text('nameserver 192.0.2.54\n')
(host / 'resolv.conf').unlink()
(host / 'resolv.conf').symlink_to(other)
self.assertEqual(self.read_guest(), other.read_text())
self.resolver.unlink()
self.resolver.write_text('nameserver 127.0.0.1\n')
self.assertEqual(self.read_guest(), self.resolver.read_text())
# Absolute links originating inside the guest must retain guest scope.
(self.prefix / 'guest-link').symlink_to('/private/etc/resolv.conf')
self.assertEqual(self.read_guest('/guest-link'), self.resolver.read_text())
@unittest.skipUnless(shutil.which('cmake'), 'CMake required')
def test_base_install_replaces_google_file_with_host_link(self):
cmake = self.patched('darling', 'CMakeLists.txt')
start = cmake.index('# Follow the host resolver')
end = cmake.index('\n', cmake.index('InstallSymlink(', start))
macro = self.patched('darling', 'cmake/InstallSymlink.cmake')
project = self.root / 'project'
project.mkdir()
(project / 'CMakeLists.txt').write_text(
'cmake_minimum_required(VERSION 3.16)\nproject(dns NONE)\n' + macro + '\n' + cmake[start:end] + '\n')
base = self.root / 'base'
target = base / 'libexec/darling/private/etc/resolv.conf'
target.parent.mkdir(parents=True)
for packaging in ('OFF', 'ON'):
target.unlink(missing_ok=True)
target.write_text('nameserver 8.8.8.8\nnameserver 8.8.4.4\n')
build = self.root / ('build-' + packaging)
subprocess.run(['cmake', '-S', str(project), '-B', str(build),
'-DCMAKE_INSTALL_PREFIX=' + str(base),
'-DBINARY_PACKAGING_MODE=' + packaging], check=True, capture_output=True)
subprocess.run(['cmake', '--install', str(build)], check=True, capture_output=True)
self.assertTrue(target.is_symlink())
self.assertEqual(os.readlink(target), '/Volumes/SystemRoot/etc/resolv.conf')
+50
View File
@@ -0,0 +1,50 @@
"""Compile the shipped address-table helper against an inert CPU-only fixture."""
from pathlib import Path
import re
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
HEADER = 'private-include/indium/command-encoder.private.hpp'
def address_helper():
patch = (ROOT / 'patches/metal--deps--indium.patch').read_text()
marker = f'diff --git a/{HEADER} b/{HEADER}\n'
section = patch.split(marker, 1)[1].split('\ndiff --git ', 1)[0]
# Extract each postimage hunk separately: never silently join a source gap.
hunks = re.split(r'(?m)^@@ [^\n]*\n', section)[1:]
postimages = [''.join(line[1:] for line in hunk.splitlines(keepends=True)
if line.startswith((' ', '+'))) for hunk in hunks]
def region(start, end):
matches = [text[text.index(start):text.index(end, text.index(start))]
for text in postimages if start in text and end in text]
if len(matches) != 1:
raise AssertionError('expected one complete patched region: ' + start)
return matches[0]
return (region(' template<class T, size_t capacity = 64> class DescriptorScratch',
' // Per-encoder binding tables') +
region('\tstruct AddressPool {', '\n\ttemplate<size_t setCount>'))
@unittest.skipUnless(shutil.which('c++'), 'C++ compiler required')
class AddressShadowChecks(unittest.TestCase):
def test_interleaving_fallback_padding_rollover_large_keys_and_allocations(self):
fixture = (ROOT / 'tests/fixtures/indium-address-shadow.cpp').read_text()
with tempfile.TemporaryDirectory() as folder:
path = Path(folder)
source = path / 'check.cpp'
source.write_text(fixture.replace('/* ACTUAL_PATCHED_HELPER */', address_helper()))
build = subprocess.run(['c++', '-std=c++17', '-O1', str(source), '-o', str(path/'check')],
capture_output=True, text=True)
self.assertEqual(build.returncode, 0, build.stderr)
result = subprocess.run([str(path/'check')], capture_output=True, text=True, timeout=30)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
if __name__ == '__main__':
unittest.main()
+139
View File
@@ -0,0 +1,139 @@
"""Exercise the patched presentation policy and CGL call order without a GPU."""
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
import test_runtime_compatibility as sources
@unittest.skipUnless(shutil.which('c++'), 'C++ compiler required')
class MetalVSyncChecks(unittest.TestCase):
patched = sources.CompatibilityChecks.patched
def test_explicit_vsync_is_scoped_to_each_cgl_context(self):
source = self.patched('darling', 'src/frameworks/OpenGL/OpenGL.c')
methods = '\n'.join(sources.function(source, name) for name in ('CGLFlushDrawable', 'CGLSetParameter'))
fixture = r'''
#include <cassert>
#include <cstdio>
using GLint=int;
using CGLError=int;
using CGLContextParameter=int;
using EGLBoolean=int;
constexpr int kCGLNoError=0, kCGLBadContext=1, kCGLBadState=2, kCGLBadAddress=3, kCGLBadValue=4;
constexpr int kCGLCPSwapInterval=1;
struct Context { int egl_display=1, egl_surface=1, swap_interval=1, swap_interval_requested=0; };
using CGLContextObj=Context*;
static Context* current;
static int display=1, applied=-1;
static bool fail=false;
static int swapInterval(int, int value) { if(fail) return 0; applied=value; return 1; }
static auto p_eglSwapInterval=swapInterval;
static int p_eglSwapBuffers(int,int) { return 1; }
static Context* CGLGetCurrentContext() { return current; }
''' + methods + r'''
int main() {
Context a, b;
current=&a;
int interval=1;
assert(CGLSetParameter(&a,kCGLCPSwapInterval,&interval)==0 && applied==1);
CGLFlushDrawable(&a); assert(applied==1);
current=&b;
CGLFlushDrawable(&b); assert(applied==0); // Another window retains its default.
current=&a;
interval=0;
assert(CGLSetParameter(&a,kCGLCPSwapInterval,&interval)==0 && applied==0);
interval=1;
assert(CGLSetParameter(&a,kCGLCPSwapInterval,&interval)==0 && applied==1);
current=&b; fail=true;
assert(CGLSetParameter(&b,kCGLCPSwapInterval,&interval)==kCGLBadValue);
assert(!b.swap_interval_requested); // Failed requests must not change policy.
fail=false; CGLFlushDrawable(&b); assert(applied==0);
assert(CGLFlushDrawable(nullptr)==kCGLBadContext);
}
'''
self.run_cpp(fixture)
def test_nested_layers_toggles_windows_and_context_failures(self):
source = self.patched('cocotron', 'QuartzCore/CALayerContext.m')
policy = sources.function(source, 'metalSwapInterval')
# Translate only Objective-C message/iteration syntax; compile the actual
# policy and flush body against inert layer and CGL fixtures.
policy = policy.replace('[[layer class] isSubclassOfClass: [CAMetalLayerInternal class]]', 'layer->metal')
policy = policy.replace('[(CAMetalLayer *)layer displaySyncEnabled]', 'layer->sync')
policy = policy.replace('for (CALayer *child in layer.sublayers)', 'for (CALayer *child : layer->children)')
flush = source.split('- (void) flush {', 1)[1].split('\n}\n', 1)[0]
fixture = r'''
#include <cassert>
#include <vector>
using GLint = int;
using CGLContextObj = int;
constexpr int kCGLNoError = 0, kCGLCPSwapInterval = 1;
constexpr int NULL_CONTEXT = 0;
struct CALayer { bool metal=false, sync=true; std::vector<CALayer*> children; };
struct Context { int interval=-2, swaps=0; } contexts[3];
static int current=2, attached=0;
static bool fail=false, skip=false;
static int CGLGetCurrentContext() { return current; }
static int CGLSetCurrentContext(int context) { current=context; return 0; }
static int CGLContextMakeCurrentAndAttachToWindow(int context, int window) {
if(fail) return 1;
current=context; attached=window; return 0;
}
static int CGLSetParameter(int context, int parameter, const int* interval) {
assert(current==context && attached==context && parameter==kCGLCPSwapInterval);
contexts[context].interval=*interval; return 0;
}
static int CGLFlushDrawable(int context) {
assert(current==context && attached==context);
++contexts[context].swaps; return 0;
}
static bool skipLocalRender(CALayer*, int) { return skip; }
'''
fixture += policy
fixture += '\nstruct Window { int _glContext=1, _cglWindow=1, _frame=0; CALayer* _layer; void flush() {'
fixture += flush.replace('NULL', 'NULL_CONTEXT').replace('_frame.size', '_frame') + '\n} };\n'
fixture += r'''
int main() {
CALayer root, container, metal, other;
metal.metal=other.metal=true;
root.children={&container}; container.children={&metal};
assert(metalSwapInterval(&root)==1);
Window a{1,1,0,&root};
a.flush(); assert(contexts[1].interval==1 && current==2);
metal.sync=false;
a.flush(); assert(contexts[1].interval==0 && current==2);
container.children.push_back(&other);
a.flush(); assert(contexts[1].interval==1);
other.sync=false;
a.flush(); assert(contexts[1].interval==0);
CALayer plain;
assert(metalSwapInterval(&plain)==-1);
Window b{2,2,0,&plain};
b.flush(); assert(contexts[2].interval==-2);
other.sync=true;
a.flush(); assert(contexts[1].interval==1 && contexts[2].interval==-2);
a._cglWindow=0;
int swaps=contexts[1].swaps;
a.flush(); assert(contexts[1].swaps==swaps);
a._cglWindow=1; fail=true;
a.flush(); assert(contexts[1].swaps==swaps && current==2);
fail=false; skip=true;
a.flush(); assert(contexts[1].swaps==swaps);
skip=false; current=0;
a.flush(); assert(current==0);
current=1; a.flush(); assert(current==1);
root.children.clear();
assert(metalSwapInterval(&root)==-1);
}
'''
self.run_cpp(fixture)
def run_cpp(self, fixture):
with tempfile.TemporaryDirectory() as directory:
path = Path(directory)
(path/'check.cpp').write_text(fixture)
result = subprocess.run(['c++', '-std=c++17', str(path/'check.cpp'), '-o', str(path/'check')], capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stderr)
subprocess.run([str(path/'check')], check=True, timeout=10)
+100
View File
@@ -0,0 +1,100 @@
import json
import os
import re
import subprocess
import sys
import unittest
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
def extract_fhs_profile(flake_text: str) -> str:
"""Extract the FHS shell profile, substituting inert paths for Nix values."""
match = re.search(r"profile\s*=\s*''(.*?)'';", flake_text, re.DOTALL)
if not match:
raise ValueError("Could not find profile in flake.nix")
raw_profile = match.group(1)
# Nix multi-line strings: (?<!'')\$\{...\} is interpolation, ''$ is escaped $
profile_script = re.sub(r"(?<!'')\$\{([^}]+)\}", r"/nix/store/mock-\1", raw_profile)
profile_script = profile_script.replace("''$", "$")
return profile_script
class NixFontsConfigTest(unittest.TestCase):
"""Check packaged font configuration and isolation from host overrides."""
def test_flake_font_configuration(self):
"""Require bundled text fonts, user font support, and ordered sanitization."""
flake_text = (REPO_ROOT / "flake.nix").read_text(encoding="utf-8")
# Flake must bundle both font families in darlingFontsConf
self.assertIn("pkgs.liberation_ttf", flake_text)
self.assertIn("pkgs.dejavu_fonts", flake_text)
# makeFontsConf includes store fontconfig config directory
self.assertIn('"${pkgs.fontconfig.out}/etc/fonts/conf.d"', flake_text)
# Legacy ~/.fonts XML fragment included in darlingFontsConf
self.assertIn("<dir>~/.fonts</dir>", flake_text)
# FHS profile unsets foreign/sysroot fontconfig vars before exporting package FONTCONFIG_FILE
self.assertIn("unset FONTCONFIG_PATH FONTCONFIG_SYSROOT", flake_text)
self.assertIn("export FONTCONFIG_FILE=${darlingFontsConf}", flake_text)
unset_pos = flake_text.index("unset FONTCONFIG_PATH FONTCONFIG_SYSROOT")
export_pos = flake_text.index("export FONTCONFIG_FILE=${darlingFontsConf}")
self.assertLess(unset_pos, export_pos, "unset must happen before export FONTCONFIG_FILE")
def test_fhs_profile_hostile_environment_sanitization(self):
"""Clear hostile fontconfig overrides while preserving user XDG settings."""
flake_text = (REPO_ROOT / "flake.nix").read_text(encoding="utf-8")
profile_script = extract_fhs_profile(flake_text)
hostile_envs = [
{
"FONTCONFIG_SYSROOT": "/not/a/real/host/sysroot",
"FONTCONFIG_PATH": "/foreign/host/etc/fonts",
},
{
"FONTCONFIG_SYSROOT": "",
"FONTCONFIG_PATH": "/foreign/host/etc/fonts",
},
]
for hostile_font_env in hostile_envs:
with self.subTest(hostile_font_env=hostile_font_env):
test_env = dict(hostile_font_env)
test_env.update({
"HOME": "/tmp/mock-home",
"XDG_DATA_HOME": "/tmp/mock-xdg data with spaces",
"XDG_CONFIG_HOME": "/tmp/mock-xdg config with spaces",
"UNRELATED_USER_VAR": "preserve_this_value",
"PATH": os.environ.get("PATH", "/bin:/usr/bin"),
})
dump_cmd = (
f"{profile_script}\n"
f'"{sys.executable}" -c \'import os, json; print(json.dumps(dict(os.environ)))\''
)
proc = subprocess.run(
["bash", "-c", dump_cmd],
env=test_env,
capture_output=True,
text=True,
check=True,
)
resulting_env = json.loads(proc.stdout)
self.assertNotIn("FONTCONFIG_SYSROOT", resulting_env)
self.assertNotIn("FONTCONFIG_PATH", resulting_env)
self.assertEqual(
resulting_env.get("FONTCONFIG_FILE"),
"/nix/store/mock-darlingFontsConf",
)
self.assertEqual(resulting_env.get("XDG_DATA_HOME"), "/tmp/mock-xdg data with spaces")
self.assertEqual(resulting_env.get("XDG_CONFIG_HOME"), "/tmp/mock-xdg config with spaces")
self.assertEqual(resulting_env.get("UNRELATED_USER_VAR"), "preserve_this_value")
if __name__ == "__main__":
unittest.main()
+10 -2
View File
@@ -440,6 +440,7 @@ class SessionTests(unittest.TestCase):
self.assertFalse((root / 'other-prefix').exists())
def test_first_run_eof_is_actionable_and_desktop_requests_terminal(self):
"""Report missing terminal input without setup and package a terminal launcher."""
with tempfile.TemporaryDirectory(prefix='nix-session-test-') as directory:
root = Path(directory)
(root / 'scripts').mkdir()
@@ -453,7 +454,8 @@ class SessionTests(unittest.TestCase):
self.assertIn('terminal', result.stderr.lower())
self.assertFalse((root / 'build').exists())
self.assertIn('Terminal=true', (ROOT / 'flake.nix').read_text())
self.assertIn('checks.${system}.packaging', (ROOT / 'flake.nix').read_text())
self.assertIn('packaging = pkgs.runCommand "darling-lol-packaging-tests"',
(ROOT / 'flake.nix').read_text())
def test_rootless_update_refuses_live_marker_without_build_or_stop(self):
with tempfile.TemporaryDirectory(prefix='nix-update-idle-') as directory:
@@ -491,6 +493,9 @@ class SessionTests(unittest.TestCase):
path.chmod(0o755)
(scripts / 'nix-state.py').write_text('import os, sys\nwith open(os.environ["TEST_LOG"], "a") as f: f.write(sys.argv[1]+"\\n")\n')
(tools / 'stop-darling-runtime.py').write_text('import os\nwith open(os.environ["TEST_LOG"], "a") as f: f.write("stop\\n")\n')
(root / 'tools').mkdir()
(root / 'tools/configure-darling-platform.py').write_text(
'import os, sys\nwith open(os.environ["TEST_LOG"], "a") as f: f.write("identity " + " ".join(sys.argv[1:]) + "\\n")\n')
for name in ['cmake', 'sudo', 'nix-store']:
path = bin_dir / name
path.write_text('#!/bin/sh\necho ' + name + ' >> "$TEST_LOG"\n' +
@@ -502,12 +507,15 @@ class SessionTests(unittest.TestCase):
result = run('sh', str(scripts / 'update.sh'), env=env)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(log.read_text().splitlines(),
['nix-store', 'invalidate-base', 'build', 'stop', 'cmake', 'stamp-base', 'overlays'])
['nix-store', 'invalidate-base', 'build', 'stop', 'cmake', 'stamp-base', 'overlays',
# The shared serial/UUID replacement writes the prefix, so Darling is stopped first.
'stop', 'identity --replace-known-defaults --write'])
log.write_text('')
env['INSTALL_EXIT'] = '23'
self.assertEqual(run('sh', str(scripts / 'update.sh'), env=env).returncode, 23)
self.assertNotIn('stamp-base', log.read_text())
self.assertNotIn('overlays', log.read_text())
self.assertNotIn('identity', log.read_text())
self.assertNotIn('sudo', log.read_text())
def test_rootless_update_never_uses_sudo_and_stamps_only_after_success(self):
+46
View File
@@ -0,0 +1,46 @@
"""Check that the patched Cocotron file panels always end their modal session and never throw on Open."""
import unittest
import test_runtime_compatibility as sources
def body(source, signature):
return source.split(signature + ' {', 1)[1].split('\n}', 1)[0]
class FilePanelCloseChecks(unittest.TestCase):
patched = sources.CompatibilityChecks.patched
def save_panel(self):
return self.patched('cocotron', 'AppKit/NSSavePanel.subproj/NSSavePanel.m')
def open_panel(self):
return self.patched('cocotron', 'AppKit/NSSavePanel.subproj/NSOpenPanel.m')
def test_both_buttons_dismiss_through_one_helper(self):
source = self.save_panel()
dismiss = body(source, '- (void) _dismissWithCode: (NSModalResponse) code')
self.assertIn('[NSApp modalWindow] == self', dismiss)
self.assertIn('stopModalWithCode: code', dismiss)
self.assertIn('orderOut', dismiss)
self.assertIn('_dismissWithCode: NSCancelButton', body(source, '- (IBAction) _cancel: (id) sender'))
self.assertIn('_dismissWithCode: NSOKButton', body(source, '- (IBAction) _selectFile: (id) sender'))
def test_open_without_a_selection_cannot_throw(self):
# Nothing selected used to hand nil to -_setFilename:, and NSOpenPanel boxed it in @[ ... ].
self.assertNotIn('@[ filename ]];', self.open_panel().replace('[filename length] > 0 ? @[ filename ] : @[]', ''))
select = body(self.save_panel(), '- (IBAction) _selectFile: (id) sender')
self.assertNotIn('itemAtRow: [_outlineView selectedRow]', select)
self.assertIn('@catch', select)
self.assertIn('NSCancelButton', select.split('@catch', 1)[1])
def test_open_panel_honours_what_it_may_choose(self):
accept = body(self.open_panel(), '- (NSArray *) _acceptablePaths')
self.assertIn('_canChooseDirectories', accept)
self.assertIn('_canChooseFiles', accept)
def test_escape_cancels(self):
self.assertIn('[self _cancel: sender]', body(self.save_panel(), '- (void) cancelOperation: (id) sender'))
if __name__ == '__main__':
unittest.main()
+161
View File
@@ -0,0 +1,161 @@
"""Test the opt-in partial client-tree recovery with fake /proc entries."""
import importlib.util
import io
import os
from pathlib import Path
import tempfile
import unittest
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location(
'recover_stale_client', ROOT / 'tools/recover-stale-client.py')
recover_stale_client = importlib.util.module_from_spec(spec)
spec.loader.exec_module(recover_stale_client)
GAME = '/Applications/League of Legends.app/Contents/LoL/LeagueofLegends'
CLIENT = '/Users/Shared/Riot Games/Riot Client.app/Contents/MacOS/RiotClientServices'
class RecoverStaleClientTests(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
self.proc = self.root / 'proc'
self.proc.mkdir()
(self.proc / 'uptime').write_text('1000 0\n')
self.prefix = self.root / '.darling'
def process(self, pid, comm, argv, env=None, executable=None, age=120):
folder = self.proc / str(pid)
folder.mkdir()
(folder / 'comm').write_text(comm + '\n')
(folder / 'cmdline').write_bytes(
(argv[0] if executable is None else executable).encode() + b'\0' +
b''.join(arg.encode() + b'\0' for arg in argv[1:]))
ticks = os.sysconf('SC_CLK_TCK')
fields = ['S'] + ['0'] * 18 + [str(int((1000 - age) * ticks))]
(folder / 'stat').write_text(f'{pid} ({comm}) ' + ' '.join(fields) + '\n')
if env is not None:
(folder / 'environ').write_bytes(env)
return folder
def client_env(self, prefix=None):
prefix = self.prefix if prefix is None else prefix
return b'%s=%s\0' % (
recover_stale_client.SOCK_VARIABLE,
os.fsencode(prefix / recover_stale_client.SOCK_NAME),
)
def run_recover(self, window=False, on_kill=None):
killed = []
def kill(pid, signum):
killed.append((pid, signum))
if on_kill is not None:
on_kill(pid, signum)
out = io.StringIO()
with patch.object(recover_stale_client, 'visible_client_window',
return_value=window):
result = recover_stale_client.recover(
self.prefix, proc_root=self.proc, window_check=lambda: window,
kill=kill, sleep=lambda _seconds: None, out=out)
return result, killed, out.getvalue()
def test_no_darlingserver_does_nothing(self):
self.process(10, 'mldr', ['/sbin/launchd'])
result, killed, output = self.run_recover()
self.assertEqual((result, killed), (0, []))
self.assertIn('no darlingserver', output)
def test_game_is_never_touched(self):
self.process(10, 'darlingserver', ['darlingserver'])
self.process(11, 'mldr', [GAME])
result, killed, output = self.run_recover()
self.assertEqual((result, killed), (0, []))
self.assertIn('game running', output)
def test_visible_window_does_nothing(self):
self.process(10, 'darlingserver', ['darlingserver'])
self.process(11, 'mldr', [CLIENT], self.client_env())
result, killed, output = self.run_recover(window=True)
self.assertEqual((result, killed), (0, []))
self.assertIn('client window present', output)
def test_stale_client_is_killed_but_runtime_is_preserved(self):
self.process(10, 'darlingserver', ['darlingserver'])
self.process(11, 'mldr', ['/sbin/launchd'])
self.process(12, 'mldr', [CLIENT], self.client_env())
result, killed, output = self.run_recover()
self.assertEqual(result, 0)
self.assertEqual([pid for pid, _sig in killed], [12, 12])
self.assertIn('stale client tree', output)
def test_other_prefix_and_game_are_preserved(self):
self.process(10, 'darlingserver', ['darlingserver'])
self.process(11, 'mldr', [CLIENT], self.client_env(self.root / 'other'))
self.process(12, 'mldr', [GAME], self.client_env())
result, killed, output = self.run_recover()
self.assertEqual((result, killed), (0, []))
self.assertIn('game running', output)
def test_runtime_process_names_are_not_killed(self):
self.process(10, 'darlingserver', ['darlingserver'])
self.process(11, 'mldr', ['/sbin/launchd'])
self.process(12, 'mldr', [CLIENT], self.client_env())
result, killed, _output = self.run_recover()
self.assertEqual(result, 0)
self.assertNotIn(10, [pid for pid, _sig in killed])
self.assertNotIn(11, [pid for pid, _sig in killed])
def test_pid_identity_is_rechecked_before_sigkill(self):
self.process(10, 'darlingserver', ['darlingserver'])
self.process(12, 'mldr', [CLIENT], self.client_env())
def reuse_pid(pid, signum):
if signum == recover_stale_client.signal.SIGTERM:
(self.proc / str(pid) / 'cmdline').write_bytes(b'/usr/bin/editor\0')
result, killed, _output = self.run_recover(on_kill=reuse_pid)
self.assertEqual(result, 0)
self.assertEqual(killed, [(12, recover_stale_client.signal.SIGTERM)])
def test_young_client_is_preserved(self):
self.process(10, 'darlingserver', ['darlingserver'])
self.process(12, 'mldr', [CLIENT], self.client_env(),
age=recover_stale_client.MIN_AGE_SECONDS - 1)
result, killed, output = self.run_recover()
self.assertEqual((result, killed), (0, []))
self.assertIn('no stale client processes', output)
def test_missing_net_client_list_is_inconclusive(self):
with patch.object(recover_stale_client.subprocess, 'check_output',
return_value='_NET_CLIENT_LIST: not found.\n'):
self.assertTrue(recover_stale_client.visible_client_window())
def test_empty_client_list_is_no_window(self):
with patch.object(recover_stale_client.subprocess, 'check_output',
return_value='_NET_CLIENT_LIST(WINDOW): window id #\n'):
self.assertFalse(recover_stale_client.visible_client_window())
def test_missing_wm_class_is_inconclusive(self):
with patch.object(recover_stale_client.subprocess, 'check_output',
side_effect=[
'_NET_CLIENT_LIST(WINDOW): window id # 0x10\n',
'WM_CLASS: not found.\n',
]):
self.assertTrue(recover_stale_client.visible_client_window())
def test_riot_client_shell_is_a_visible_window(self):
with patch.object(recover_stale_client.subprocess, 'check_output',
side_effect=[
'_NET_CLIENT_LIST(WINDOW): window id # 0x10\n',
'WM_CLASS(STRING) = "RiotClientServices", "RiotClientServices"\n',
]):
self.assertTrue(recover_stale_client.visible_client_window())
if __name__ == '__main__':
unittest.main()
+151
View File
@@ -0,0 +1,151 @@
"""Cleanup scope regressions: fake proc/prefix trees and mocked signals only."""
import contextlib
import importlib.util
import io
import os
from pathlib import Path
import tempfile
import unittest
from unittest.mock import MagicMock, Mock, patch
SCRIPT = Path(__file__).resolve().parents[1] / 'tools/ensure-darling-runtime.py'
class RuntimeCleanupScopeTests(unittest.TestCase):
def setUp(self):
temporary = tempfile.TemporaryDirectory(prefix='cleanup-scope-')
self.addCleanup(temporary.cleanup)
self.root = Path(temporary.name)
self.proc = self.root / 'proc'
self.proc.mkdir()
self.prefix = self.root / 'selected prefix'
self.other = self.root / 'unrelated prefix'
self.shm = self.root / 'shm'
for folder in (self.prefix / 'private/tmp', self.other / 'private/tmp', self.shm):
folder.mkdir(parents=True)
# Guard signals before import; no real process may ever be signalled.
self.kill = self.enterContext(patch('os.kill'))
spec = importlib.util.spec_from_file_location('cleanup_scope', SCRIPT)
assert spec is not None and spec.loader is not None
self.cleanup = importlib.util.module_from_spec(spec)
spec.loader.exec_module(self.cleanup)
self.stderr = self.enterContext(contextlib.redirect_stderr(io.StringIO()))
self.enterContext(contextlib.redirect_stdout(io.StringIO()))
self.enterContext(patch.dict(os.environ, {'DPREFIX': str(self.prefix)}))
self.enterContext(patch.object(self.cleanup, 'Path', side_effect=self.fake_path))
# Its default Path('/proc') is bound at definition time, before patching Path.
running = self.cleanup.any_server_running
self.enterContext(patch.object(self.cleanup, 'any_server_running',
side_effect=lambda proc_root=None: running(
self.proc if proc_root is None else proc_root)))
def fake_path(self, value):
# Never inspect host /proc or remove host shared-memory files.
return {'/proc': self.proc, '/dev/shm': self.shm}.get(str(value), Path(value))
def process(self, pid, *, comm='launchd', argv=('/sbin/launchd',), state='S'):
folder = self.proc / str(pid)
folder.mkdir()
(folder / 'comm').write_text(comm + '\n')
(folder / 'cmdline').write_bytes(b'\0'.join(arg.encode() for arg in argv) + b'\0')
(folder / 'status').write_text(f'State:\t{state} (fixture)\n')
return folder
def test_direct_cleanup_entry_points_preserve_ambiguous_processes(self):
self.process(101)
self.process(102, comm='chrome_crashpad', argv=(
'/Applications/Riot Client.app/Contents/Frameworks/chrome_crashpad_handler',))
self.cleanup.stop_orphaned_launchd(self.proc)
self.cleanup.stop_riot_crashpad(self.proc)
self.kill.assert_not_called()
self.assertIn('prefix ownership', self.stderr.getvalue())
self.assertIn('launchd candidate PIDs 101', self.stderr.getvalue())
self.assertIn('Riot crashpad candidate PIDs 102', self.stderr.getvalue())
def test_clean_start_is_silent(self):
self.cleanup.main()
self.assertEqual(self.stderr.getvalue(), '')
self.kill.assert_not_called()
def test_unrelated_processes_are_silent(self):
self.process(110, comm='chrome_crashpad', argv=(
'/opt/google/chrome/chrome_crashpad_handler', '--annotation=riot'))
self.process(111, comm='unrelated', argv=('/usr/bin/tool', '/sbin/launchd'))
self.process(112, comm='unrelated', argv=('/usr/bin/tool',
'/Applications/Riot Client.app/chrome_crashpad_handler'))
self.cleanup.main()
self.assertEqual(self.stderr.getvalue(), '')
self.kill.assert_not_called()
def test_foreign_owned_candidates_are_silent(self):
self.process(113)
self.process(114, comm='chrome_crashpad', argv=(
'/Applications/Riot Client.app/chrome_crashpad_handler',))
with patch.object(Path, 'stat', return_value=Mock(st_uid=os.getuid() + 1)):
self.cleanup.stop_orphaned_launchd(self.proc)
self.cleanup.stop_riot_crashpad(self.proc)
self.assertEqual(self.stderr.getvalue(), '')
self.kill.assert_not_called()
def test_main_preserves_processes_from_another_prefix_without_a_server(self):
self.process(101)
self.process(102, comm='chrome_crashpad', argv=(
str(self.other / 'Applications/Riot Client.app/crashpad_handler'),))
selected = self.prefix / 'private/tmp/.com.riotgames.selected'
selected.write_text('stale')
unrelated = self.other / 'private/tmp/.com.riotgames.other'
unrelated.write_text('preserve')
shared = self.shm / 'darling-buffer-fixture'
shared.write_text('stale')
self.cleanup.main()
self.kill.assert_not_called()
self.assertFalse(selected.exists())
self.assertFalse(shared.exists())
self.assertEqual(unrelated.read_text(), 'preserve')
def test_any_live_server_preserves_locks_and_shared_buffers(self):
self.process(103, comm='darlingserver', argv=('darlingserver',))
lock = self.prefix / 'private/tmp/.com.riotgames.lock'
lock.write_text('active')
shared = self.shm / 'darling-buffer-fixture'
shared.write_text('active')
self.cleanup.main()
self.kill.assert_not_called()
self.assertTrue(lock.exists())
self.assertTrue(shared.exists())
def test_unreadable_process_list_fails_closed(self):
hidden = MagicMock()
hidden.name = '104'
(hidden / 'comm').read_text.side_effect = PermissionError('hidden')
proc = Mock()
proc.iterdir.return_value = [hidden]
self.assertTrue(self.cleanup.any_server_running(proc))
self.kill.assert_not_called()
def test_dead_marker_is_recovered_only_in_the_selected_prefix(self):
self.process(105, state='Z')
marker = self.prefix / '.init.pid'
marker.write_text('105')
other = self.other / '.init.pid'
other.write_text('105')
self.cleanup.main()
self.assertFalse(marker.exists())
recovered = list(self.prefix.glob('.init.pid.stale-105-*'))
self.assertEqual(len(recovered), 1)
self.assertEqual(recovered[0].read_text(), '105')
self.assertEqual(other.read_text(), '105')
self.kill.assert_not_called()
def test_live_marker_is_not_replaced(self):
self.process(106)
marker = self.prefix / '.init.pid'
marker.write_text('106')
self.cleanup.main()
self.assertEqual(marker.read_text(), '106')
self.kill.assert_not_called()
if __name__ == '__main__':
unittest.main()
+1 -1
View File
@@ -38,7 +38,7 @@ class CompatibilityChecks(unittest.TestCase):
patch = patch_text.split(marker, 1)[1].split('\ndiff --git ', 1)[0]
with tempfile.TemporaryDirectory() as folder:
target = Path(folder) / path
target.parent.mkdir(parents=True)
target.parent.mkdir(parents=True, exist_ok=True)
if original is not None:
target.write_bytes(original)
subprocess.run(['patch', '--silent', '-p1', '-d', folder], input=marker + patch + ("" if patch.endswith("\n") else "\n"),
+169
View File
@@ -0,0 +1,169 @@
"""Offline contracts for NSSavePanel's unsupported Finder-tag compatibility."""
import json
from pathlib import Path
import re
import runpy
import shutil
import subprocess
import tempfile
import unittest
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[1]
IMPLEMENTATION = 'AppKit/NSSavePanel.subproj/NSSavePanel.m'
HEADER = 'AppKit/include/AppKit/NSSavePanel.h'
PROBE_SOURCE = 'tools/riot-save-panel-tag-check.m'
BUILD_HELPER = 'tools/build-riot-save-panel-tag-check.py'
def added_source(path):
marker = f'diff --git a/{path} b/{path}\n'
section = (ROOT / 'patches/cocotron.patch').read_text().split(marker, 1)[1]
section = section.split('\ndiff --git ', 1)[0]
return '\n'.join(line[1:] for line in section.splitlines()
if line.startswith('+') and not line.startswith('+++'))
def extract_patch(path):
marker = f'diff --git a/{path} b/{path}\n'
patch_text = (ROOT / 'patches/cocotron.patch').read_text()
if marker not in patch_text:
raise AssertionError(f'Missing patch section for {path}')
section = patch_text.split(marker, 1)[1].split('\ndiff --git ', 1)[0]
return marker + section + '\n'
def method(source, signature):
match = re.search(re.escape(signature) + r'\s*\{([^}]+)\}', source)
if match is None:
raise AssertionError(f'Missing implementation: {signature}')
return match.group(1)
class SavePanelTagTests(unittest.TestCase):
def test_tag_names_setter_accepts_unsupported_metadata_without_storing_it(self):
body = method(added_source(IMPLEMENTATION), '- (void) setTagNames: (NSArray *) names')
self.assertIn('(void)names;', body)
self.assertNotIn('retain', body)
self.assertNotIn('copy', body)
def test_tag_names_getter_returns_an_empty_array_not_nil(self):
body = method(added_source(IMPLEMENTATION), '- (NSArray *) tagNames')
self.assertIn('return [NSArray array];', body)
def test_public_header_declares_both_tag_name_methods(self):
header = added_source(HEADER)
self.assertIn('- (void) setTagNames: (NSArray *) names;', header)
self.assertIn('- (NSArray *) tagNames;', header)
def test_existing_tag_field_and_modal_fixes_are_retained(self):
source = added_source(IMPLEMENTATION)
self.assertIn('- (void) setShowsTagField: (BOOL) flag', source)
self.assertIn('- (BOOL) showsTagField', source)
self.assertIn('- (void) _dismissWithCode: (NSModalResponse) code', source)
self.assertNotIn('setShowsTags:', source)
def test_patch_applies_cleanly_to_pinned_upstream_cocotron(self):
if not shutil.which('patch'):
self.skipTest('patch executable required')
manifest = json.loads((ROOT / 'upstream/manifest.json').read_text())
component = next(c for c in manifest['components'] if c['patch'] == 'patches/cocotron.patch')
repo = ROOT / 'build/darling-src' / component['path']
if not (repo / '.git').exists():
self.skipTest('prepared Darling sources required')
revision = component['revision']
for relpath in [IMPLEMENTATION, HEADER]:
filename = Path(relpath).name
original = subprocess.check_output(['git', '-C', str(repo), 'show', f'{revision}:{relpath}'])
with tempfile.TemporaryDirectory() as td:
work_file = Path(td) / filename
work_file.write_bytes(original)
patch_file = Path(td) / f'{filename}.patch'
patch_file.write_text(extract_patch(relpath))
res = subprocess.run(
['patch', '--dry-run', '--fuzz=0', str(work_file), str(patch_file)],
capture_output=True,
text=True,
)
self.assertEqual(res.returncode, 0, f'Patch failed to apply to {relpath}: {res.stderr}\n{res.stdout}')
def test_extracted_method_bodies_compile_with_clang(self):
clang = shutil.which('clang')
if not clang:
self.skipTest('clang not available')
impl = added_source(IMPLEMENTATION)
setter_body = method(impl, '- (void) setTagNames: (NSArray *) names')
getter_body = method(impl, '- (NSArray *) tagNames')
snippet = f'''
@interface NSObject
+ (instancetype)alloc;
- (instancetype)init;
@end
@interface NSArray : NSObject
+ (instancetype)array;
@end
@interface NSSavePanel : NSObject
- (void) setTagNames: (NSArray *) names;
- (NSArray *) tagNames;
@end
@implementation NSSavePanel
- (void) setTagNames: (NSArray *) names {{{setter_body}}}
- (NSArray *) tagNames {{{getter_body}}}
@end
'''
with tempfile.NamedTemporaryFile(suffix='.m', mode='w') as f:
f.write(snippet)
f.flush()
res = subprocess.run(
[clang, '-Qunused-arguments', '-x', 'objective-c', '-fsyntax-only', '-Werror', f.name],
capture_output=True,
text=True,
)
self.assertEqual(res.returncode, 0, f'Clang syntax check failed: {res.stderr}')
def test_builder_compiles_and_links_probe_without_embedding_shim(self):
source = ROOT / BUILD_HELPER
self.assertTrue(source.exists(), f'Missing build helper: {BUILD_HELPER}')
with tempfile.TemporaryDirectory() as temporary:
project = Path(temporary)
driver = project / 'tools' / source.name
driver.parent.mkdir()
driver.write_text(source.read_text())
framework = project / 'build/darling-src/build/src/external/cocotron/AppKit'
cmake = framework / 'CMakeFiles/X11_backend.dir'
cmake.mkdir(parents=True)
(cmake / 'flags.make').write_text('C_DEFINES = -DTEST\nC_INCLUDES = -Itest\nC_FLAGS = -O0\n')
calls = []
with patch('subprocess.run', side_effect=lambda argv, **kw: calls.append((argv, kw))):
runpy.run_path(str(driver), run_name='__main__')
probe_name = 'riot-save-panel-tag-check'
compiles = [argv for argv, _ in calls if str(project / f'tools/{probe_name}.m') in argv]
self.assertEqual(len(compiles), 1, 'probe must be compiled')
self.assertEqual(compiles[0][compiles[0].index('-o') + 1], str(project / f'build/{probe_name}.o'))
links = [argv for argv, _ in calls if str(project / f'build/{probe_name}') in argv]
self.assertEqual(len(links), 1, 'probe must be linked')
self.assertIn(str(project / f'build/{probe_name}.o'), links[0])
self.assertIn('AppKit', links[0])
for argv, _ in calls:
for arg in argv:
self.assertNotIn('compat', arg)
def test_probe_declares_only_and_implements_no_shim(self):
source = (ROOT / PROBE_SOURCE).read_text()
self.assertIn('@interface NSSavePanel (RiotTagProbeDeclarations)', source)
self.assertIn('- (void)setTagNames:(NSArray *)names;', source)
self.assertIn('- (NSArray *)tagNames;', source)
self.assertIn('- (void)setShowsTagField:(BOOL)value;', source)
self.assertIn('- (BOOL)showsTagField;', source)
self.assertNotIn('@implementation NSSavePanel', source, 'probe must not contain compatibility shim')
self.assertIn('checkPanel([NSSavePanel class])', source)
self.assertIn('checkPanel([NSOpenPanel class])', source)
if __name__ == '__main__':
unittest.main()
+36
View File
@@ -0,0 +1,36 @@
"""Check that the patched X11 backend cannot re-map a window AppKit has hidden."""
import unittest
import test_runtime_compatibility as sources
def body(source, signature):
return source.split(signature + ' {', 1)[1].split('\n}', 1)[0]
class HiddenWindowChecks(unittest.TestCase):
patched = sources.CompatibilityChecks.patched
def test_restack_and_make_key_map_only_visible_windows(self):
source = self.patched('cocotron', 'AppKit/X11.backend/X11Window.m')
self.assertIn('[_delegate isVisible]', body(source, '- (void) ensureMappedIfVisible'))
for signature in ('- (void) placeAboveWindow: (NSInteger) otherNumber',
'- (void) placeBelowWindow: (NSInteger) otherNumber', '- (void) makeKey'):
method = body(source, signature)
self.assertIn('[self ensureMappedIfVisible]', method, signature)
self.assertNotIn('[self ensureMapped]', method, signature)
def test_ordering_marks_window_visible_before_placing_it(self):
source = self.patched('cocotron', 'AppKit/NSWindow.m')
ordering = source.split('relativeTo: (NSInteger) relativeTo\n{', 1)[1].split('\n}', 1)[0]
for call in ('placeAboveWindow', 'placeBelowWindow'):
self.assertLess(ordering.index('_isVisible = YES'), ordering.index(call))
def test_hiding_reaches_the_platform_window_when_already_not_visible(self):
source = self.patched('cocotron', 'AppKit/NSWindow.m')
method = body(source, '- (void) setIsVisible: (BOOL) visible')
self.assertIn('_isVisible == visible && visible', method)
self.assertIn('hideWindow', method)
if __name__ == '__main__':
unittest.main()
+164
View File
@@ -0,0 +1,164 @@
"""Compile the patched VRR eligibility and drawable ownership methods with inert fixtures."""
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
import test_runtime_compatibility as sources
def body(source, signature):
return source.split(signature + ' {', 1)[1].split('\n}', 1)[0]
@unittest.skipUnless(shutil.which('c++'), 'C++ compiler required')
class VrrChecks(unittest.TestCase):
patched = sources.CompatibilityChecks.patched
def run_cpp(self, source):
with tempfile.TemporaryDirectory() as directory:
path = Path(directory)
(path/'check.cpp').write_text('#include <cstddef>\n' + source)
result = subprocess.run(['c++', '-std=c++17', str(path/'check.cpp'), '-o', str(path/'check')], capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stderr)
subprocess.run([str(path/'check')], check=True, timeout=10)
def test_hints_only_allow_vrr_for_fullscreen_parent_presentation(self):
source = self.patched('cocotron', 'AppKit/X11.backend/X11Window.m')
method = body(source, '- (void) updateLayerPresentationHints: (BOOL) fullscreen')
getter = body(source, '- (void *) layerDrawableFor: (id) owner')
acquire = body(source, '- (void) acquireLayerDrawable: (id) owner').replace('[self updateLayerPresentationHints: _fullscreenRequested]', 'hints(_fullscreenRequested)')
release = body(source, '- (void) releaseLayerDrawable: (id) owner').replace('[self updateLayerPresentationHints: _fullscreenRequested]', 'hints(_fullscreenRequested)')
self.run_cpp(r'''
#include <cassert>
#include <cstring>
using BOOL=bool;
constexpr auto nil=nullptr;
constexpr int False=0, XA_CARDINAL=6, PropModeReplace=0;
static bool game=true;
static int adaptive=-1,bypass=-1,calls=0;
static bool X11IsLeagueGameWindow(int,int,int) { return game; }
static const char* XInternAtom(int,const char* name,int) { return name; }
static int XChangeProperty(int,int,const char* name,int type,int bits,int mode,unsigned char* data,int count) {
assert(type==XA_CARDINAL && bits==32 && mode==PropModeReplace && count==1);
int value=*(unsigned long*)data; ++calls;
if(!strcmp(name,"_VARIABLE_REFRESH")) adaptive=value;
else { assert(!strcmp(name,"_NET_WM_BYPASS_COMPOSITOR")); bypass=value; }
return 0;
}
struct Window {
int _display=1,_window=1,_delegate=1;
void* _layerDrawableOwner=nullptr;
void* _cglWindow=(void*)3; bool _hasAlpha=false,_fullscreenRequested=true;
void hints(BOOL fullscreen) {
''' + method + '\n }\n void* drawable(void* owner) {' + getter + '\n}\n void acquire(void* owner) {' + acquire + '\n}\n void release(void* owner) {' + release + r'''
}
};
int main() {
Window w;
w.hints(true); assert(adaptive==0 && bypass==2);
w._layerDrawableOwner=&w;
w.hints(true); assert(adaptive==1 && bypass==0);
w.hints(false); assert(adaptive==0 && bypass==0);
w._layerDrawableOwner=nullptr;
w.hints(true); assert(adaptive==0 && bypass==2);
int before=calls; game=false; w.hints(true); assert(calls==before);
assert(!w.drawable(&w)); game=true;
int a,b;
assert(w.drawable(&a)==(void*)3);
w.acquire(&a); assert(w.drawable(&a)==(void*)3 && !w.drawable(&b));
w.acquire(&b); assert(w._layerDrawableOwner==&a);
w.release(&b); assert(w._layerDrawableOwner==&a);
w.release(&a); assert(!w._layerDrawableOwner && w.drawable(&b)==(void*)3);
w._hasAlpha=true; assert(!w.drawable(&a));
}
''')
def test_subwindows_borrow_only_when_visible_borderless_and_covering_parent(self):
source = self.patched('cocotron', 'AppKit/X11.backend/X11SubWindow.m')
method = body(source, '- (void *) sharedCGLWindow')
replacements = {'[_parent frame]':'_parent->frame', '[_parent styleMask]':'_parent->style',
'[_parent layerDrawableFor: self]':'_parent->drawable(this)',
'[_parent acquireLayerDrawable: self]':'_parent->acquire(this)',
'[_parent releaseLayerDrawable: self]':'_parent->release(this)'}
for old,new in replacements.items():
method=method.replace(old,new)
self.run_cpp(r'''
#include <cassert>
using BOOL=bool;
struct CGRect { struct {double x,y;} origin; struct {double width,height;} size; };
static CGRect CGRectMake(double x,double y,double w,double h) {return {{x,y},{w,h}};}
static bool CGRectEqualToRect(CGRect a,CGRect b) {return a.origin.x==b.origin.x && a.origin.y==b.origin.y && a.size.width==b.size.width && a.size.height==b.size.height;}
constexpr int NSTitledWindowMask=1;
static bool mapped;
static void XMapWindow(int,int) {mapped=true;}
static void XUnmapWindow(int,int) {mapped=false;}
struct Parent {
CGRect frame=CGRectMake(0,0,800,600); int style=0; bool eligible=true;
void* owner=nullptr; void* surface=this;
void* drawable(void* requester) {return eligible && (!owner || owner==requester) ? surface : nullptr;}
void acquire(void* requester) {assert(!owner); owner=requester;}
void release(void* requester) {assert(owner==requester); owner=nullptr;}
};
struct Child {
Parent* _parent; CGRect _drawableFrame=CGRectMake(0,0,800,600);
BOOL _visible=true,_usingParentDrawable=false,_allowsParentDrawable=true; int _display=1,_window=2;
void* shared() {
''' + method + r'''
}
};
int main() {
Parent p; Child a{&p}; Child b{&p};
assert(a.shared()==p.surface && !mapped && p.owner==&a);
assert(a.shared()==p.surface); // Repeated lookup does not reacquire.
assert(b.shared()==nullptr && mapped); // A second view cannot share ownership.
a._visible=false; assert(!a.shared() && !mapped && !p.owner);
a._visible=true; assert(a.shared()==p.surface);
a._drawableFrame.size.width=400;
assert(!a.shared() && mapped && !p.owner);
a._drawableFrame=CGRectMake(0,0,800,600); p.style=NSTitledWindowMask;
assert(!a.shared() && mapped);
p.style=0; p.eligible=false; assert(!a.shared() && mapped);
p.eligible=true; a._allowsParentDrawable=false; assert(!a.shared() && mapped);
a._allowsParentDrawable=true; a._drawableFrame.origin.x=1; assert(!a.shared() && mapped);
a._drawableFrame.origin.x=0; assert(a.shared()==p.surface && !mapped);
}
''')
def test_switching_surfaces_destroys_only_owned_child_drawables(self):
source = self.patched('cocotron', 'QuartzCore/CALayerContext.m')
method = body(source, '- (void) updateDrawable')
method=method.replace('[_subwindow setAllowsParentDrawable: hasMetalLayer(_layer)]', '_subwindow->allow(hasMetalLayer(_layer))')
method=method.replace('[_subwindow sharedCGLWindow]', '_subwindow->shared').replace('[_subwindow nativeWindow]', '_subwindow->native')
self.run_cpp(r'''
#include <cassert>
using BOOL=bool;
using CGLContextObj=int;
static int current=0,destroyed=0,created=0;
static void* destroyedSurface;
static int CGLGetCurrentContext() {return current;}
static void CGLSetCurrentContext(int c) {current=c;}
static void CGLDestroyWindow(void* surface) {assert(surface==(void*)10); destroyedSurface=surface; ++destroyed;}
static void* CGLGetWindow(void*) {++created; return (void*)10;}
static void CGLContextMakeCurrentAndAttachToWindow(int c,void*) {current=c;}
static bool hasMetalLayer(int layer) {return layer!=0;}
struct Subwindow {void* shared=nullptr; void* native=(void*)2; void allow(bool enabled) {assert(enabled);} };
struct Context {
Subwindow* _subwindow; int _layer=1; int _glContext=1; void* _cglWindow=nullptr; bool _ownsCglWindow=false;
void update() {
''' + method.replace('CGLSetCurrentContext(NULL)', 'CGLSetCurrentContext(0)') + r'''
}
};
int main() {
Subwindow sub; Context c{&sub};
c.update(); assert(created==1 && c._ownsCglWindow); // Ordinary clients still get a child.
c.update(); assert(created==1 && destroyed==0);
current=1; sub.shared=(void*)20;
c.update(); assert(destroyed==1 && destroyedSurface==(void*)10 && !c._ownsCglWindow && current==1);
c.update(); assert(destroyed==1);
sub.shared=(void*)30; c.update(); assert(destroyed==1 && c._cglWindow==(void*)30);
sub.shared=nullptr; c.update(); assert(created==2 && destroyed==1 && c._ownsCglWindow);
current=2; sub.shared=(void*)20; c.update(); assert(current==2 && destroyed==2);
c._subwindow=nullptr; c.update(); assert(destroyed==2);
}
''')
+1 -1
View File
@@ -10,5 +10,5 @@ OBJDUMP="$(command -v llvm-objdump || true)"
file "$BIN" | tee "$OUT/file.txt"
[ -n "$OTOOL" ] && { "$OTOOL" -hv "$BIN" > "$OUT/headers.txt" 2>&1; "$OTOOL" -L "$BIN" > "$OUT/linked-libs.txt" 2>&1; echo "wrote headers + linked-libs"; } || echo "no otool/llvm-otool found"
[ -n "$OBJDUMP" ] && "$OBJDUMP" --macho --dylibs-used "$BIN" > "$OUT/dylibs.txt" 2>&1 || true
strings -a "$BIN" | grep -iE "Metal|MTL|Vanguard|vgc|CEF|Chromium|RiotClient|NSApplication|LSOpen|CFBundle" | sort -u | head -100 | tee "$OUT/strings-of-interest.txt"
strings -a "$BIN" | { grep -iE "Metal|MTL|CEF|Chromium|RiotClient|NSApplication|LSOpen|CFBundle" || test "$?" -eq 1; } | sort -u | head -100 | tee "$OUT/strings-of-interest.txt"
echo "done -> $OUT/"
+1 -1
View File
@@ -12,7 +12,7 @@ for line in (framework / 'CMakeFiles/AppKit.dir/flags.make').read_text().splitli
name, value = line.split(' = ', 1)
flags[name] = shlex.split(value)
link = shlex.split((framework / 'CMakeFiles/AppKit.dir/link.txt').read_text())
for name in ['NSResponder', 'NSApplication', 'NSWindow', 'NSDisplay', 'NSView', 'NSThemeFrame', 'NSTextInput', 'NSBitmapImageRep', 'NSEvent.subproj/NSEvent_mouse']:
for name in ['NSResponder', 'NSApplication', 'NSWindow', 'NSDisplay', 'NSView', 'NSThemeFrame', 'NSTextInput', 'NSBitmapImageRep', 'NSEvent.subproj/NSEvent', 'NSEvent.subproj/NSEvent_mouse']:
obj = project / f'build/riot-{Path(name).name}.o'
subprocess.run(['clang', *flags['C_DEFINES'], *flags['C_INCLUDES'], *flags['C_FLAGS'],
'-O3', '-march=native', '-mtune=generic', '-Wno-macro-redefined', '-c',
+17 -8
View File
@@ -43,14 +43,16 @@ if matrix_obj in link:
link[link.index(matrix_obj)]=str(obj)
else:
link.append(str(obj))
# The default-output unit must be recompiled too: its SetProperty refuses kAudioOutputUnitProperty_CurrentDevice unless patched.
obj=project/'build/riot-DefaultOutputAU.o'
subprocess.run(['clang++',*component_flags['CXX_DEFINES'],*component_flags['CXX_INCLUDES'],
*component_flags['CXX_FLAGS'],'-O2','-c',str(project/'build/darling-src/src/CoreAudio/CoreAudioComponent/DefaultOutputAU.cpp'),
'-o',str(obj)],check=True)
default_obj='CMakeFiles/CoreAudioComponent.dir/DefaultOutputAU.cpp.o'
assert default_obj in link, 'DefaultOutputAU object missing from the link line'
link[link.index(default_obj)]=str(obj)
# The AUHAL subclasses must be recompiled too: they share AUHAL.h's layout and vtable, and the default-output
# unit's SetProperty refuses kAudioOutputUnitProperty_CurrentDevice unless patched.
for name in ['DefaultOutputAU','SystemOutputAU']:
obj=project/f'build/riot-{name}.o'
subprocess.run(['clang++',*component_flags['CXX_DEFINES'],*component_flags['CXX_INCLUDES'],
*component_flags['CXX_FLAGS'],'-O2','-c',str(project/f'build/darling-src/src/CoreAudio/CoreAudioComponent/{name}.cpp'),
'-o',str(obj)],check=True)
default_obj=f'CMakeFiles/CoreAudioComponent.dir/{name}.cpp.o'
assert default_obj in link, f'{name} object missing from the link line'
link[link.index(default_obj)]=str(obj)
link[link.index('-o')+1]=str(project/'build/riot-CoreAudioComponent')
subprocess.run(link,cwd=component,check=True)
toolbox=build/'src/CoreAudio/AudioToolbox'
@@ -90,3 +92,10 @@ subprocess.run(['clang++',*cpp_flags['CXX_DEFINES'],*cpp_flags['CXX_INCLUDES'],
subprocess.run(['clang++','-target','x86_64-apple-macosx11.0','-fuse-ld=lld','-nostdlib',
'-isysroot','@DARLING_SDK@',str(obj),'-lSystem','-lc++',
str(project/'build/riot-AudioToolbox'),'-o',str(project/'build/riot-audio-graph-check')],check=True)
obj=project/'build/riot-audio-input-check.o'
subprocess.run(['clang++',*cpp_flags['CXX_DEFINES'],*cpp_flags['CXX_INCLUDES'],
*cpp_flags['CXX_FLAGS'],'-O2','-c',str(project/'tools/riot-audio-input-check.cpp'),'-o',str(obj)],check=True)
subprocess.run(['clang++','-target','x86_64-apple-macosx11.0','-fuse-ld=lld','-nostdlib',
'-isysroot','@DARLING_SDK@',str(obj),'-lSystem','-lc++','-lobjc','-framework','CoreAudio',
'-framework','AudioToolbox','-framework','AVFoundation','-o',str(project/'build/riot-audio-input-check')],check=True)
+7 -6
View File
@@ -10,12 +10,13 @@ for line in (folder / 'CMakeFiles/CoreGraphics.dir/flags.make').read_text().spli
if line.startswith('C_') and ' = ' in line:
key, value = line.split(' = ', 1)
flags[key] = shlex.split(value)
obj = root / 'build/riot-CGDirectDisplay.o'
subprocess.run(['clang', *flags['C_DEFINES'], *flags['C_INCLUDES'], *flags['C_FLAGS'],
'-O2', '-Wno-macro-redefined', '-c',
str(root / 'build/darling-src/src/external/cocotron/CoreGraphics/CGDirectDisplay.m'),
'-o', str(obj)], check=True)
link = shlex.split((folder / 'CMakeFiles/CoreGraphics.dir/link.txt').read_text())
link[link.index('CMakeFiles/CoreGraphics.dir/CGDirectDisplay.m.o')] = str(obj)
for name in ('CGDirectDisplay', 'CGSubWindow'):
obj = root / f'build/riot-{name}.o'
subprocess.run(['clang', *flags['C_DEFINES'], *flags['C_INCLUDES'], *flags['C_FLAGS'],
'-O2', '-Wno-macro-redefined', '-c',
str(root / f'build/darling-src/src/external/cocotron/CoreGraphics/{name}.m'),
'-o', str(obj)], check=True)
link[link.index(f'CMakeFiles/CoreGraphics.dir/{name}.m.o')] = str(obj)
link[link.index('-o') + 1] = str(root / 'build/riot-CoreGraphics')
subprocess.run(link, cwd=folder, check=True)
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
"""Build the owned NSOpenPanel modal-session check (issue #85)."""
from pathlib import Path
import json
import shlex
import subprocess
root = Path(__file__).resolve().parent.parent
folder = root / 'build/darling-src/build/src/external/cocotron/AppKit'
config = root / 'build/config.json'
sdk = json.loads(config.read_text())['sdk'] if config.exists() else '/usr/local/libexec/darling'
flags = {}
for line in (folder / 'CMakeFiles/X11_backend.dir/flags.make').read_text().splitlines():
if line.startswith('C_') and ' = ' in line:
key, value = line.split(' = ', 1)
flags[key] = shlex.split(value)
obj = root / 'build/riot-openpanel-check.o'
subprocess.run(['clang', *flags['C_DEFINES'], *flags['C_INCLUDES'], *flags['C_FLAGS'],
'-O2', '-fblocks', '-UNDEBUG', '-Wno-macro-redefined', '-c', str(root / 'tools/riot-openpanel-check.m'),
'-o', str(obj)], check=True)
subprocess.run(['clang', '-target', 'x86_64-apple-macosx11.0', '-fuse-ld=lld', '-nostdlib',
'-isysroot', sdk, str(obj), '-lSystem', '-lobjc',
'-framework', 'AppKit', '-framework', 'CoreFoundation', '-framework', 'Foundation',
'-o', str(root / 'build/riot-openpanel-check')], check=True)
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
"""Build the standalone NSSavePanel Finder-tag compatibility check."""
from pathlib import Path
import json
import shlex
import subprocess
root = Path(__file__).resolve().parent.parent
folder = root / 'build/darling-src/build/src/external/cocotron/AppKit'
config = root / 'build/config.json'
sdk = json.loads(config.read_text())['sdk'] if config.exists() else '/usr/local/libexec/darling'
flags = {}
for line in (folder / 'CMakeFiles/X11_backend.dir/flags.make').read_text().splitlines():
if line.startswith('C_') and ' = ' in line:
key, value = line.split(' = ', 1)
flags[key] = shlex.split(value)
obj = root / 'build/riot-save-panel-tag-check.o'
subprocess.run(['clang', *flags['C_DEFINES'], *flags['C_INCLUDES'], *flags['C_FLAGS'],
'-O2', '-fblocks', '-UNDEBUG', '-Wno-macro-redefined', '-c', str(root / 'tools/riot-save-panel-tag-check.m'),
'-o', str(obj)], check=True)
subprocess.run(['clang', '-target', 'x86_64-apple-macosx11.0', '-fuse-ld=lld', '-nostdlib',
'-isysroot', sdk, str(obj), '-lSystem', '-lobjc',
'-framework', 'AppKit', '-framework', 'CoreFoundation', '-framework', 'Foundation',
'-o', str(root / 'build/riot-save-panel-tag-check')], check=True)
+21 -2
View File
@@ -14,7 +14,7 @@ for line in (framework / 'CMakeFiles/X11_backend.dir/flags.make').read_text().sp
key, value = line.split(' = ', 1)
flags[key] = shlex.split(value)
link = shlex.split((framework / 'CMakeFiles/X11_backend.dir/link.txt').read_text())
for name in ('X11Display', 'X11Window'):
for name in ('X11Display', 'X11Window', 'X11SubWindow'):
obj = project / f'build/riot-{name}.o'
subprocess.run(['clang', *flags['C_DEFINES'], *flags['C_INCLUDES'], *flags['C_FLAGS'], '-O3', '-march=native', '-mtune=generic', '-Wno-macro-redefined', '-c', str(project / f'build/darling-src/src/external/cocotron/AppKit/X11.backend/{name}.m'), '-o', str(obj)], check=True)
link[link.index(f'CMakeFiles/X11_backend.dir/X11.backend/{name}.m.o')] = str(obj)
@@ -48,4 +48,23 @@ subprocess.run(['clang', *flags['C_DEFINES'], *flags['C_INCLUDES'], *flags['C_FL
str(project / 'tools/riot-fullscreen-geometry-check.m'), '-o', str(probe)], check=True)
subprocess.run(['clang', '-target', 'x86_64-apple-macosx11.0', '-fuse-ld=lld',
'-nostdlib', '-isysroot', sdk, str(probe), '-lSystem', '-lobjc', '-framework', 'Foundation',
'-o', str(project / 'build/riot-fullscreen-geometry-check')], check=True)
'-o', str(project / 'build/riot-fullscreen-geometry-check')], check=True)
# Query the actual native hints after Cocoa title/style changes, without mapping windows.
probe = project / 'build/riot-window-decorations-check.o'
subprocess.run(['clang', *flags['C_DEFINES'], *flags['C_INCLUDES'], *flags['C_FLAGS'],
'-O3', '-march=native', '-mtune=generic', '-UNDEBUG', '-Wno-macro-redefined', '-c',
str(project / 'tools/riot-window-decorations-check.m'), '-o', str(probe)], check=True)
subprocess.run(['clang', '-target', 'x86_64-apple-macosx11.0', '-fuse-ld=lld',
'-nostdlib', '-isysroot', sdk, str(probe), '-lSystem', '-lobjc', '-framework', 'AppKit',
'-framework', 'Foundation', '-framework', 'CoreGraphics',
'-o', str(project / 'build/riot-window-decorations-check')], check=True)
# Match native AppKit's local event monitor dispatch semantics.
probe = project / 'build/riot-event-monitors-check.o'
subprocess.run(['clang', *flags['C_DEFINES'], *flags['C_INCLUDES'], *flags['C_FLAGS'],
'-O3', '-march=native', '-mtune=generic', '-Wno-macro-redefined', '-c',
str(project / 'tools/riot-event-monitors-check.m'), '-o', str(probe)], check=True)
subprocess.run(['clang', '-target', 'x86_64-apple-macosx11.0', '-fuse-ld=lld',
'-nostdlib', '-isysroot', sdk, str(probe), '-lSystem', '-lobjc', '-framework', 'AppKit',
'-framework', 'Foundation', '-o', str(project / 'build/riot-event-monitors-check')], check=True)
+183
View File
@@ -0,0 +1,183 @@
#!/usr/bin/env python3
"""Remove orphaned client-in-game helpers from an earlier launcher run.
The close/hide helpers are long-lived watch processes. A launcher can end
while they remain, and a later run starts another helper, so several copies
watch the same prefix. This opt-in preflight removes only helpers that belong
to this prefix and whose parent is init/systemd: the launcher that started
them has already exited and reparented them. It never signals a helper whose
parent is still alive, the current launcher, darlingserver, the game,
Riot/League/CEF, or a process of another prefix.
It fails closed: an unreadable command line, environment, stat entry or
parent leaves that process alone. Enable it with
RCLOL_CLEAN_STALE_HELPERS=1; the launcher runs it before starting its own
helper.
"""
import argparse
import os
import signal
import sys
import time
from pathlib import Path
HELPER_NAMES = ('close-league-client-in-game.py',
'hide-league-client-in-game.py')
REAPER_NAMES = ('init', 'systemd')
TERM_GRACE = 3.0
def target_prefix():
"""The prefix this launcher owns, or None when it cannot be determined."""
value = os.environ.get('DPREFIX', str(Path.home() / '.darling'))
prefix = Path(value).expanduser()
return prefix if prefix.is_absolute() else None
def process_info(proc):
"""Return (state, ppid, start_ticks), or None when stat is unreadable."""
try:
fields = (proc / 'stat').read_text().rsplit(')', 1)[1].split()
if len(fields) < 20:
return None
return fields[0], int(fields[1]), int(fields[19])
except (OSError, ValueError, IndexError):
return None
def parent_is_reaper(ppid, proc_root):
"""True when the parent is PID 1 or a systemd/init user manager."""
if ppid == 1:
return True
try:
comm = (proc_root / str(ppid) / 'comm').read_text().strip()
except OSError:
return False
return comm in REAPER_NAMES
def helper_identity(proc, prefix, proc_root):
"""Return the start ticks of an orphaned helper of prefix, or None.
The script name must be an exact argument, and the executable must be a
Python interpreter. This avoids matching an editor or a log viewer that
happens to have the helper name in its arguments. DPREFIX is inherited by
the helper from run-riot-client.sh; a missing or different value belongs
to another install and is preserved.
"""
try:
if proc.stat().st_uid != os.getuid():
return None
raw = (proc / 'cmdline').read_bytes()
argv = [part.decode(errors='replace') for part in raw.split(b'\0') if part]
if len(argv) < 2 or not os.path.basename(argv[0]).startswith(('python', 'pypy')):
return None
if not any(os.path.basename(arg) in HELPER_NAMES for arg in argv[1:]):
return None
environment = dict(
item.split(b'=', 1)
for item in (proc / 'environ').read_bytes().split(b'\0')
if b'=' in item
)
raw_prefix = environment.get(b'DPREFIX')
if raw_prefix is None:
return None
helper_prefix = Path(os.fsdecode(raw_prefix)).expanduser()
if not helper_prefix.is_absolute():
return None
helper_prefix = helper_prefix.resolve()
if helper_prefix != prefix:
return None
info = process_info(proc)
if info is None or info[0] == 'Z':
return None
if not parent_is_reaper(info[1], proc_root):
return None
return info[2]
except FileNotFoundError:
return None
except (OSError, RuntimeError, ValueError):
return None
def clean(prefix, proc_root=Path('/proc'), kill=os.kill, sleep=time.sleep,
out=sys.stdout, dry_run=False):
"""Terminate orphaned helpers for prefix; return 0 on every normal path."""
if prefix is None or not prefix.is_absolute():
print('clean-stale-helpers: unusable DPREFIX: no action', file=out, flush=True)
return 1
try:
prefix = prefix.expanduser().resolve()
except (OSError, RuntimeError):
print('clean-stale-helpers: unusable DPREFIX: no action', file=out, flush=True)
return 1
try:
entries = list(proc_root.iterdir())
except OSError:
print('clean-stale-helpers: unreadable /proc: no action', file=out, flush=True)
return 0
helpers = {}
for proc in entries:
if not proc.name.isdigit() or int(proc.name) == os.getpid():
continue
start_ticks = helper_identity(proc, prefix, proc_root)
if start_ticks is not None:
helpers[int(proc.name)] = start_ticks
if not helpers:
print('clean-stale-helpers: no orphaned helpers; nothing to do',
file=out, flush=True)
return 0
pids = sorted(helpers)
action = 'would remove' if dry_run else 'removing'
print('clean-stale-helpers: %s %d orphaned helper(s): %s'
% (action, len(pids), ','.join(str(pid) for pid in pids)),
file=out, flush=True)
if dry_run:
return 0
for pid, start_ticks in helpers.items():
proc = proc_root / str(pid)
if helper_identity(proc, prefix, proc_root) != start_ticks:
continue
try:
kill(pid, signal.SIGTERM)
except OSError:
continue
sleep(TERM_GRACE)
for pid, start_ticks in helpers.items():
proc = proc_root / str(pid)
if helper_identity(proc, prefix, proc_root) != start_ticks:
continue
try:
kill(pid, signal.SIGKILL)
except OSError:
pass
return 0
def main():
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('--prefix', type=Path,
help='prefix whose helpers should be checked')
parser.add_argument('--dry-run', action='store_true',
help='report what would be removed without signalling')
args = parser.parse_args()
if os.environ.get('RCLOL_CLEAN_STALE_HELPERS') != '1':
print('clean-stale-helpers: disabled; set RCLOL_CLEAN_STALE_HELPERS=1',
flush=True)
return 0
prefix = args.prefix or target_prefix()
if prefix is None or not prefix.is_absolute():
print('clean-stale-helpers: unusable DPREFIX: no action',
file=sys.stderr, flush=True)
return 1
return clean(prefix, dry_run=args.dry_run)
if __name__ == '__main__':
sys.exit(main())
+110
View File
@@ -0,0 +1,110 @@
#!/usr/bin/env python3
"""Resolve the client-in-game mode from League's local preferences.
The public launcher switch is RCLOL_CLIENT_IN_GAME_TRICKS=1. It reads
`lol-user-experience` from LCULocalPreferences.yaml:
- potatoModeEnabled must be true (client optimizations enabled);
- closeLeagueClientDuringGame true -> close the client UI while a match runs;
- closeLeagueClientDuringGame false -> hide the client windows instead;
- missing or invalid closeLeagueClientDuringGame or potatoModeEnabled -> no action
(none).
Only the named `lol-user-experience` section is considered, so identical keys
in another section cannot select a helper. This helper only selects a mode; it
does not change preferences or files.
"""
import sys
from pathlib import Path
SECTION = 'lol-user-experience'
CLOSE_KEY = 'closeLeagueClientDuringGame'
OPTIMIZATION_KEY = 'potatoModeEnabled'
TRUE_VALUES = {'true', 'yes', '1'}
FALSE_VALUES = {'false', 'no', '0'}
def parse_bool(value):
"""Return True/False/None for one YAML scalar, ignoring a trailing comment."""
value = value.strip()
if not value:
return None
if value[0] in ('"', "'"):
quote = value[0]
end = value.find(quote, 1)
if end == -1:
return None
scalar = value[1:end]
remainder = value[end + 1:]
if remainder and not remainder[0].isspace():
return None
remainder = remainder.strip()
if remainder and not remainder.startswith('#'):
return None
else:
scalar = value
for index, char in enumerate(scalar):
if char == '#' and (index == 0 or scalar[index - 1].isspace()):
scalar = scalar[:index].rstrip()
break
scalar = scalar.lower()
if scalar in TRUE_VALUES:
return True
if scalar in FALSE_VALUES:
return False
return None
def read_bool(path, key, section=SECTION):
"""Return True/False for the last key in section, or None when invalid.
OSError/UnicodeError is raised for an unreadable file so callers can fail
closed instead of treating a read race as a missing preference.
"""
lines = Path(path).read_text().splitlines()
in_section = False
value = None
for line in lines:
stripped = line.strip()
if not stripped or stripped.startswith('#'):
continue
if not line.startswith((' ', '\t')):
if stripped == section + ':':
in_section = True
elif in_section:
break
continue
if not in_section or not stripped.startswith(key + ':'):
continue
value = parse_bool(stripped.split(':', 1)[1])
return value
def mode(path):
try:
optimization = read_bool(path, OPTIMIZATION_KEY)
except (OSError, UnicodeError):
return 'none'
if optimization is not True:
return 'none'
try:
close = read_bool(path, CLOSE_KEY)
except (OSError, UnicodeError):
return 'none'
if close is True:
return 'close'
if close is False:
return 'hide'
return 'none'
def main(argv=None):
argv = sys.argv[1:] if argv is None else argv
path = argv[0] if argv else ''
print(mode(path))
return 0
if __name__ == '__main__':
sys.exit(main())
+187
View File
@@ -0,0 +1,187 @@
#!/usr/bin/env python3
"""Create and install the GNOME / FreeDesktop desktop entry and launcher icon."""
import os
import shutil
import subprocess
from pathlib import Path
PROJECT_ROOT = Path("@PROJECT_ROOT@")
HOST_HOME = Path("@HOST_HOME@")
# Marks a launcher entry created by this project. Previous versions pointed
# Exec at this checkout's desktop-run.sh, so an entry without that marker
# belongs to someone else and is left alone.
LEGACY_RUN_SCRIPT = "scripts/desktop-run.sh"
# Distinctive fragments of the artwork the previous helper wrote.
LEGACY_SVG_MARKERS = ('id="goldGrad"', 'M172 108 L242 108')
# Characters that force Exec quoting, per the Desktop Entry specification.
EXEC_RESERVED = set(' \t\n"\'\\><~|&;$*?#()`')
def escape_string(value: str) -> str:
"""Escape a value of Desktop Entry type ``string``."""
return (value.replace("\\", "\\\\").replace("\t", "\\t")
.replace("\n", "\\n").replace("\r", "\\r"))
def quote_exec_argument(value: str) -> str:
"""Escape and quote one Exec argument as the specification requires."""
escaped = value.replace("%", "%%")
if not any(char in EXEC_RESERVED for char in escaped):
return escaped
escaped = "".join("\\" + char if char in '"`$\\' else char for char in escaped)
return f'"{escaped}"'
def legacy_entry_owned(path: Path) -> bool:
"""Return True when a launcher entry was created by this project."""
marker = str(PROJECT_ROOT / LEGACY_RUN_SCRIPT)
try:
text = path.read_text(errors="ignore")
except OSError:
# A dangling symlink still counts when it points at this checkout.
try:
text = os.readlink(path)
except OSError:
return False
return marker in text or marker.replace("%", "%%") in text
def remove_legacy_entry(path: Path) -> bool:
"""Remove a previous launcher entry only when this project created it."""
if not (path.is_symlink() or path.exists()):
return False
if not legacy_entry_owned(path):
return False
try:
path.unlink()
except OSError:
return False
return True
def legacy_svg_owned(path: Path) -> bool:
"""Return True when an icon is the artwork the previous helper wrote."""
try:
text = path.read_text(errors="ignore")
except OSError:
return False
return all(marker in text for marker in LEGACY_SVG_MARKERS)
def shortcut_directories() -> list[Path]:
"""Return the desktop directories that hold launcher shortcuts."""
directories: list[Path] = []
try:
result = subprocess.run(["xdg-user-dir", "DESKTOP"], capture_output=True, text=True, check=False)
if result.returncode == 0 and result.stdout.strip():
path = Path(result.stdout.strip())
if path.is_dir():
directories.append(path)
except Exception:
pass
for candidate in [HOST_HOME / "Desktop"]:
if candidate.is_dir() and candidate not in directories:
directories.append(candidate)
return directories
def main():
icons_base = HOST_HOME / ".local/share/icons"
apps_base = HOST_HOME / ".local/share/applications"
scalable_dir = icons_base / "hicolor/scalable/apps"
png_dir = icons_base / "hicolor/128x128/apps"
scalable_dir.mkdir(parents=True, exist_ok=True)
png_dir.mkdir(parents=True, exist_ok=True)
apps_base.mkdir(parents=True, exist_ok=True)
source_svg = PROJECT_ROOT / "darling-lol.svg"
source_png = PROJECT_ROOT / "darling-lol.png"
if not source_svg.is_file() or not source_png.is_file():
raise SystemExit("launcher icon is missing: expected darling-lol.svg and darling-lol.png")
# Install the project's original icon under a neutral name. Do not extract
# or install an icon from the game/client installation.
shutil.copyfile(source_svg, scalable_dir / "darling-launcher.svg")
shutil.copyfile(source_png, png_dir / "darling-launcher.png")
# Remove artifacts created by older versions of this helper. Only files
# proven to be ours are deleted: an entry that pointed at this checkout's
# desktop-run.sh, and the SVG with the old artwork. The old PNG was
# extracted from the client and cannot be verified, so it is removed only
# when one of those proofs succeeded.
owned = remove_legacy_entry(apps_base / "league-of-legends.desktop")
desktop_dirs = shortcut_directories()
for directory in desktop_dirs:
owned = remove_legacy_entry(directory / "league-of-legends.desktop") or owned
legacy_svgs = (scalable_dir / "league-of-legends.svg", icons_base / "league-of-legends.svg")
if any(legacy_svg_owned(path) for path in legacy_svgs):
owned = True
if owned:
for legacy_icon in (
*legacy_svgs,
icons_base / "league-of-legends.png",
icons_base / "hicolor/512x512/apps/league-of-legends.png",
):
try:
legacy_icon.unlink(missing_ok=True)
except OSError:
pass
# Create the desktop entry. Keep StartupWMClass: Darling's AppKit sets
# WM_CLASS from -[NSProcessInfo processName], which is the basename of
# argv[0], and the launcher starts .../RiotClientServices. It is an
# interoperability identifier, not a user-visible name.
# Terminal stays false here because this entry runs desktop-run.sh, which
# saves session output in build/desktop-launch.log; the packaged entry runs
# the session directly and therefore needs a terminal.
exec_cmd = quote_exec_argument(str(PROJECT_ROOT / LEGACY_RUN_SCRIPT))
project_path = escape_string(str(PROJECT_ROOT))
desktop_content = f"""[Desktop Entry]
Version=1.0
Type=Application
Name=Darling Launcher
GenericName=Game
Comment=Unofficial launcher for the macOS game client via Darling
Exec={exec_cmd}
Path={project_path}
Icon=darling-launcher
Terminal=false
Categories=Game;
Keywords=Darling;Launcher;Compatibility;
StartupWMClass=RiotClientServices
StartupNotify=false
"""
desktop_file = apps_base / "darling-launcher.desktop"
desktop_file.write_text(desktop_content)
os.chmod(desktop_file, 0o755)
print(f"Created application launcher: {desktop_file}")
for directory in desktop_dirs:
desktop_shortcut = directory / "darling-launcher.desktop"
desktop_shortcut.write_text(desktop_content)
os.chmod(desktop_shortcut, 0o755)
gio = shutil.which("gio")
if gio:
subprocess.run([gio, "set", str(desktop_shortcut), "metadata::trusted", "true"], check=False)
print(f"Created desktop shortcut: {desktop_shortcut}")
# Refresh icon and desktop databases
update_desktop = shutil.which("update-desktop-database")
if update_desktop:
subprocess.run([update_desktop, str(apps_base)], check=False)
update_icons = shutil.which("gtk-update-icon-cache")
if update_icons:
subprocess.run([update_icons, "-f", "-t", str(icons_base / "hicolor")], check=False)
print("GNOME application launcher and icon installed successfully.")
if __name__ == "__main__":
main()
+32 -25
View File
@@ -2,7 +2,7 @@
"""Clear a dead Darling server's stale PID marker, and stale shared buffers once no server runs."""
import os
from pathlib import Path
import signal
import sys
import time
def recover_marker(prefix):
marker = prefix / '.init.pid'
@@ -38,39 +38,46 @@ def any_server_running(proc_root=Path('/proc')):
pass
return False
def stop_orphaned_launchd(proc_root=Path('/proc')):
"""A guest launchd that outlived its darlingserver cannot be shut down with `darling shutdown`
and makes the base install (tools/shutdown-user.sh) refuse to continue."""
def _matching_pids(kind, proc_root):
"""Find same-user candidates by guest executable; this does not establish ownership."""
uid = os.getuid()
for proc in proc_root.iterdir():
if not proc.name.isdigit():
continue
try:
if proc.stat().st_uid != uid or (proc / 'cmdline').read_bytes().rstrip(b'\0') != b'/sbin/launchd':
if proc.stat().st_uid != uid:
continue
os.kill(int(proc.name), signal.SIGKILL)
print(f'Stopped orphaned Darling launchd PID {proc.name}', flush=True)
argv = (proc / 'cmdline').read_bytes()
if kind == 'launchd':
matches = argv.rstrip(b'\0') == b'/sbin/launchd'
else:
executable = argv.split(b'\0', 1)[0].decode(errors='replace')
matches = (proc / 'comm').read_text().startswith('chrome_crashpad') and any(
bundle in executable for bundle in (
'/Riot Client.app/', '/League of Legends.app/',
'/League of Legends (TM) Client.app/'))
if matches:
yield proc.name
except (OSError, ValueError):
pass
continue
def stop_orphaned_launchd(proc_root=Path('/proc')):
"""Warn about launchd candidates without assuming prefix ownership or signalling them."""
pids = list(_matching_pids('launchd', proc_root))
if pids:
print(f'Preserving launchd candidate PIDs {", ".join(pids)}: prefix ownership '
'cannot be proved. If setup is blocked, shut down the original Darling '
'session or inspect the leftover processes manually.', file=sys.stderr, flush=True)
def stop_riot_crashpad(proc_root=Path('/proc')):
"""A Riot crash handler outliving its server holds the old session's ports; spare every other app's."""
uid = os.getuid()
for proc in proc_root.iterdir():
if not proc.name.isdigit():
continue
try:
if not (proc / 'comm').read_text().startswith('chrome_crashpad') or proc.stat().st_uid != uid:
continue
argv = (proc / 'cmdline').read_bytes().split(b'\0')
executable = argv[0].decode(errors='replace')
# Match the executable's bundle, not arbitrary arguments (a browser may mention Riot).
if any(bundle in executable for bundle in (
'/Riot Client.app/', '/League of Legends.app/', '/League of Legends (TM) Client.app/'
)):
os.kill(int(proc.name), signal.SIGTERM)
except (OSError, ValueError):
pass
"""Warn about Riot crashpad candidates without assuming prefix ownership or signalling them."""
pids = list(_matching_pids('crashpad', proc_root))
if pids:
print(f'Preserving Riot crashpad candidate PIDs {", ".join(pids)}: prefix ownership '
'cannot be proved. Use the original session to shut down leftover helpers.',
file=sys.stderr, flush=True)
def remove_owned(paths):
uid = os.getuid()
+425
View File
@@ -0,0 +1,425 @@
#!/usr/bin/env python3
"""Opt-in: hide the League client UI while a match is running.
The launcher's `RCLOL_CLIENT_IN_GAME_TRICKS=1` mode selects this helper when
the client's own close-during-game preference is false. The low-level
`RCLOL_HIDE_CLIENT_IN_GAME=1` switch remains available for direct launches. It
hides the managed X11 windows for `LeagueClientUx` and `Riot Client`, and shows
them again when the game process exits. The Riot client, League backend, CEF
helpers and game keep running.
This is launcher/window management only. It does not patch client binaries,
CEF, anti-cheat or DRM, and it never hides the game window. It is off by
default, fails closed, and is intended for X11/Xwayland desktops.
The game is attributed to this prefix through the loader's
`__mldr_sockpath`, because guest processes do not carry `DPREFIX`. If proc,
ownership or window information cannot be read, no window is touched.
Diagnose one observation with:
python3 tools/hide-league-client-in-game.py --once
Enable it for a launcher run with:
RCLOL_HIDE_CLIENT_IN_GAME=1 ./scripts/run.sh
"""
import argparse
import ctypes
import os
import re
import signal
import subprocess
import sys
import time
from pathlib import Path
GAME_NAME = 'LeagueofLegends'
SOCK_VARIABLE = b'__mldr_sockpath'
SOCK_NAME = '.darlingserver.sock'
POLL_SECONDS = 2.0
IDLE_SECONDS = 600
TARGET_CLASSES = ('leagueclientux', 'riot client')
def target_prefix():
"""The prefix this launcher owns, or None when it cannot be determined."""
value = os.environ.get('DPREFIX', str(Path.home() / '.darling'))
prefix = Path(value).expanduser()
return prefix if prefix.is_absolute() else None
def process_state(proc):
try:
return (proc / 'stat').read_text().rsplit(')', 1)[1].split()[0]
except (OSError, IndexError):
return None
def command_names(proc):
try:
raw = (proc / 'cmdline').read_bytes()
except OSError:
return []
return [
os.path.basename(part.decode(errors='replace'))
for part in raw.split(b'\0')
if part
]
def game_running(prefix, proc_root=Path('/proc')):
"""True/False for a game of this prefix; None when /proc is unreliable.
The game executable is matched by its exact file name. The process must
carry the loader socket of this prefix, so a game from another install is
never considered. Any unreadable candidate makes the result None (fail
closed).
"""
owner = (prefix / SOCK_NAME).parent.resolve()
try:
entries = list(proc_root.iterdir())
except OSError:
return None
for proc in entries:
if not proc.name.isdigit() or process_state(proc) in ('Z', None):
continue
try:
if proc.stat().st_uid != os.getuid():
continue
if GAME_NAME not in command_names(proc):
continue
environment = dict(
item.split(b'=', 1)
for item in (proc / 'environ').read_bytes().split(b'\0')
if b'=' in item
)
socket = environment.get(SOCK_VARIABLE)
if socket is None:
continue
if Path(os.fsdecode(socket)).parent.resolve() != owner:
continue
return True
except FileNotFoundError:
if proc.exists():
return None
continue
except (OSError, ValueError):
return None
return False
def xprop_root():
try:
listing = subprocess.check_output(
['xprop', '-root', '_NET_CLIENT_LIST'], text=True, timeout=5
)
except (OSError, subprocess.SubprocessError):
return []
return re.findall(r'0x[0-9a-fA-F]+', listing)
def xprop_value(window, prop):
try:
return subprocess.check_output(
['xprop', '-id', window, prop], text=True, timeout=5
)
except (OSError, subprocess.SubprocessError):
return ''
def window_class(window):
value = xprop_value(window, 'WM_CLASS').lower()
return value if '=' in value else ''
def window_pid(window):
match = re.search(r'=\s*(\d+)', xprop_value(window, '_NET_WM_PID'))
return int(match.group(1)) if match else None
def _socket_from_process(proc):
try:
environment = dict(
item.split(b'=', 1)
for item in (proc / 'environ').read_bytes().split(b'\0')
if b'=' in item
)
except (OSError, ValueError):
return None
return environment.get(SOCK_VARIABLE)
def host_socket_for_guest(guest_pid, proc_root=Path('/proc')):
"""Find the host process for a guest X11 PID and return its loader socket.
Darling's X11 window stores the guest PID in _NET_WM_PID, while the
process visible in /proc is the host loader. NSpid carries both IDs. The
direct /proc/<pid> case is checked too for a native process.
"""
direct = proc_root / str(guest_pid)
if direct.exists():
socket = _socket_from_process(direct)
if socket is not None:
return socket
sockets = set()
try:
entries = list(proc_root.iterdir())
except OSError:
return None
for proc in entries:
if not proc.name.isdigit():
continue
try:
status = (proc / 'status').read_text()
except OSError:
continue
for line in status.splitlines():
if not line.startswith('NSpid:'):
continue
if str(guest_pid) not in line.split()[1:]:
continue
socket = _socket_from_process(proc)
if socket is not None:
sockets.add(socket)
return sockets.pop() if len(sockets) == 1 else None
def window_belongs_to_prefix(window, prefix):
pid = window_pid(window)
if pid is None:
return False
socket = host_socket_for_guest(pid)
if socket is None:
return False
try:
return Path(os.fsdecode(socket)).parent.resolve() == (prefix / SOCK_NAME).parent.resolve()
except OSError:
return False
def target_windows(prefix, class_cache=None):
"""Managed client windows for this prefix; the game window is never selected.
WM_CLASS is cached only when non-empty. The cache is pruned when a window
leaves _NET_CLIENT_LIST; empty results are retried because a class can be
set after the window appears.
"""
current = []
for raw in xprop_root():
try:
current.append((int(raw, 16), raw))
except ValueError:
continue
current_ids = {window for window, _raw in current}
if class_cache is not None:
for stale in set(class_cache) - current_ids:
del class_cache[stale]
found = []
for window, raw in current:
classes = class_cache.get(window) if class_cache is not None else None
if not classes:
classes = window_class(raw)
if classes and class_cache is not None:
class_cache[window] = classes
if not classes or not any(name in classes for name in TARGET_CLASSES):
continue
if window_belongs_to_prefix(raw, prefix):
found.append(window)
return sorted(set(found))
class X11:
def __init__(self):
self.lib = ctypes.CDLL('libX11.so.6')
self.lib.XOpenDisplay.restype = ctypes.c_void_p
self.lib.XOpenDisplay.argtypes = [ctypes.c_char_p]
self.lib.XUnmapWindow.argtypes = [ctypes.c_void_p, ctypes.c_ulong]
self.lib.XMapRaised.argtypes = [ctypes.c_void_p, ctypes.c_ulong]
self.lib.XSync.argtypes = [ctypes.c_void_p, ctypes.c_int]
self.lib.XCloseDisplay.argtypes = [ctypes.c_void_p]
error_type = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p)
self._error_handler = error_type(lambda _display, _event: 0)
self.lib.XSetErrorHandler.argtypes = [error_type]
self.lib.XSetErrorHandler.restype = ctypes.c_void_p
self.lib.XSetErrorHandler(self._error_handler)
self.display = self.lib.XOpenDisplay(None)
if not self.display:
raise RuntimeError('cannot open DISPLAY')
def unmap(self, window):
self.lib.XUnmapWindow(self.display, window)
self.lib.XSync(self.display, 0)
def show(self, window):
self.lib.XMapRaised(self.display, window)
self.lib.XSync(self.display, 0)
def close(self):
self.lib.XCloseDisplay(self.display)
class Watcher:
"""Hide while a match is running, restore on end, uncertainty or exit."""
def __init__(self, prefix, x11, window_source=target_windows,
state_source=game_running, sleep=time.sleep, out=sys.stdout,
clock=time.monotonic):
self.prefix = prefix
self.x11 = x11
self.window_source = window_source
self.state_source = state_source
self.sleep = sleep
self.out = out
self.clock = clock
self.hidden = set()
self.class_cache = {}
self.reported_no_window = False
self.seen = False
self.idle_since = None
def _log(self, message, stream=None):
try:
print(message, file=self.out if stream is None else stream, flush=True)
except Exception:
# A closed launcher pipe must not prevent window restoration.
pass
def _show_all(self, reason):
if not self.hidden:
return
self._log(f'hide-league-client-in-game: {reason}; showing the client')
for window in sorted(self.hidden):
try:
self.x11.show(window)
except Exception as error:
self._log(f'hide-league-client-in-game: cannot show 0x{window:x}: {error}',
sys.stderr)
continue
self._log(f'hide-league-client-in-game: shown 0x{window:x}')
self.hidden.clear()
def _hide_new(self):
windows = self.window_source(self.prefix, self.class_cache)
if not windows and not self.hidden and not self.reported_no_window:
self._log('hide-league-client-in-game: no managed client window; not hiding')
self.reported_no_window = True
for window in windows:
if window in self.hidden:
continue
self.hidden.add(window)
try:
self.x11.unmap(window)
except Exception as error:
self.hidden.discard(window)
self._log(f'hide-league-client-in-game: cannot hide 0x{window:x}: {error}',
sys.stderr)
continue
self._log(f'hide-league-client-in-game: hidden 0x{window:x}')
def _windows_present(self):
try:
return bool(self.window_source(self.prefix, self.class_cache))
except Exception:
# Uncertainty must not turn into an automatic exit.
return True
def run(self, max_steps=None):
steps = 0
while True:
now = self.clock()
state = self.state_source(self.prefix)
if state is None:
self._show_all('unreadable /proc state')
elif state:
self.seen = True
self.idle_since = None
if not self.hidden and self.reported_no_window:
self.reported_no_window = False
self._hide_new()
else:
self._show_all('the match ended')
self.reported_no_window = False
if self._windows_present():
self.seen = True
self.idle_since = None
elif self.seen:
if self.idle_since is None:
self.idle_since = now
if now - self.idle_since >= IDLE_SECONDS:
self._log('hide-league-client-in-game: no client or match for '
f'{IDLE_SECONDS}s: leaving')
return 0
steps += 1
if max_steps is not None and steps >= max_steps:
return 0
self.sleep(POLL_SECONDS)
def restore(self):
self._show_all('exiting')
def main(argv=None):
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('--detach', action='store_true',
help='leave the launcher session so a terminal hang-up cannot end it')
parser.add_argument('--once', action='store_true',
help='one game observation and exit (no window changes)')
args = parser.parse_args(argv)
tricks = os.environ.get('RCLOL_CLIENT_IN_GAME_TRICKS') == '1'
if not args.once and not tricks and os.environ.get('RCLOL_CLOSE_CLIENT_IN_GAME') == '1':
print('hide-league-client-in-game: ignored; RCLOL_CLOSE_CLIENT_IN_GAME=1 takes precedence',
file=sys.stderr, flush=True)
return 0
if not args.once and not tricks and os.environ.get('RCLOL_HIDE_CLIENT_IN_GAME') != '1':
print('hide-league-client-in-game: disabled; set RCLOL_HIDE_CLIENT_IN_GAME=1 or '
'RCLOL_CLIENT_IN_GAME_TRICKS=1', flush=True)
return 0
prefix = target_prefix()
if prefix is None:
print('hide-league-client-in-game: unusable DPREFIX: no action',
file=sys.stderr, flush=True)
return 1
if args.once:
state = game_running(prefix)
print(f'hide-league-client-in-game: match={"unreadable" if state is None else "running" if state else "absent"}',
flush=True)
return 0
if args.detach:
try:
os.setsid()
except OSError:
pass
try:
x11 = X11()
except Exception as error:
print(f'hide-league-client-in-game: cannot open X11: {error}',
file=sys.stderr, flush=True)
return 1
watcher = Watcher(prefix, x11)
def stop(_signum, _frame):
raise KeyboardInterrupt
for signum in (signal.SIGTERM, signal.SIGINT, signal.SIGHUP):
signal.signal(signum, stop)
optout = ('RCLOL_CLIENT_IN_GAME_TRICKS=0' if tricks
else 'RCLOL_HIDE_CLIENT_IN_GAME=0')
print('hide-league-client-in-game: watching %s for a running match; '
'opt out with %s' % (prefix, optout), flush=True)
try:
watcher.run()
except KeyboardInterrupt:
pass
finally:
watcher.restore()
x11.close()
return 0
if __name__ == '__main__':
sys.exit(main())
+242
View File
@@ -0,0 +1,242 @@
#!/usr/bin/env python3
"""Partially recover a live Darling runtime with a stale client tree.
This is opt-in through RCLOL_RECOVER_STALE_CLIENT=1. It only acts when all
of these are true:
- a darlingserver is running;
- no League game process is running;
- no managed Riot/League client window is visible;
- one or more Riot/League client, CEF or crash-handler processes at least 60
seconds old are still present for this prefix.
It terminates only those client processes with SIGTERM/SIGKILL. The
darlingserver, launchd/mldr services, sockets and .init.pid stay intact so the
next launcher run can reuse the runtime. It never patches files or the game.
"""
import math
import os
import re
import signal
import subprocess
import sys
import time
from pathlib import Path
GAME_NAME = 'LeagueofLegends'
WINDOW_CLASSES = ('leagueclientux', 'riot client', 'riotclientservices')
MIN_AGE_SECONDS = 60
CLIENT_MARKERS = (
'/Applications/League of Legends.app',
'/Applications/Riot Client.app',
'/Users/Shared/Riot Games/Riot Client.app',
'RiotClientServices',
'Riot Client',
'LeagueClient',
'LeagueClientUx',
'LeagueCrashHandler',
)
RUNTIME_NAMES = ('darlingserver', 'darling')
SOCK_VARIABLE = b'__mldr_sockpath'
SOCK_NAME = '.darlingserver.sock'
def target_prefix():
value = os.environ.get('DPREFIX', str(Path.home() / '.darling'))
prefix = Path(value).expanduser()
return prefix if prefix.is_absolute() else None
def command_names(proc):
try:
raw = (proc / 'cmdline').read_bytes()
except OSError:
return []
return [
os.path.basename(part.decode(errors='replace'))
for part in raw.split(b'\0')
if part
]
def command_text(proc):
try:
raw = (proc / 'cmdline').read_bytes()
except OSError:
return ''
return b' '.join(part for part in raw.split(b'\0') if part).decode(
errors='replace')
def process_state(proc):
try:
return (proc / 'stat').read_text().rsplit(')', 1)[1].split()[0]
except (OSError, IndexError):
return None
def server_running(proc_root=Path('/proc')):
try:
entries = list(proc_root.iterdir())
except OSError:
return False
for proc in entries:
if not proc.name.isdigit():
continue
try:
if (proc / 'comm').read_text().strip() == 'darlingserver':
return True
except OSError:
pass
return False
def game_running(proc_root=Path('/proc')):
for proc in proc_root.iterdir() if proc_root.exists() else ():
if not proc.name.isdigit():
continue
names = command_names(proc)
if GAME_NAME in names:
return True
return False
def visible_client_window():
"""Return True when a managed client window is present.
A missing xprop/property or display is treated as 'cannot prove there is no
window' so we do not kill a possibly working client. xprop exits zero and
prints "not found" for a property the window manager did not set.
"""
try:
listing = subprocess.check_output(
['xprop', '-root', '_NET_CLIENT_LIST'], text=True, timeout=5
)
except (OSError, subprocess.SubprocessError):
return True
lowered = listing.lower()
if '_net_client_list' not in lowered or 'not found' in lowered:
return True
for raw in re.findall(r'0x[0-9a-fA-F]+', listing):
try:
classes = subprocess.check_output(
['xprop', '-id', raw, 'WM_CLASS'], text=True, timeout=5
).lower()
except (OSError, subprocess.SubprocessError):
return True
if 'not found' in classes or '=' not in classes:
return True
if any(name in classes for name in WINDOW_CLASSES):
return True
return False
def client_identity(prefix, pid, proc_root=Path('/proc')):
"""Start ticks of a live stale client for prefix, or None when not eligible."""
proc = proc_root / str(pid)
if process_state(proc) in ('Z', None):
return None
owner = (prefix / SOCK_NAME).parent.resolve()
try:
if proc.stat().st_uid != os.getuid():
return None
names = command_names(proc)
if GAME_NAME in names or any(name in RUNTIME_NAMES for name in names):
return None
text = command_text(proc)
if not any(marker in text for marker in CLIENT_MARKERS):
return None
environment = dict(
item.split(b'=', 1)
for item in (proc / 'environ').read_bytes().split(b'\0')
if b'=' in item
)
socket = environment.get(SOCK_VARIABLE)
if socket is None:
return None
if Path(os.fsdecode(socket)).parent.resolve() != owner:
return None
uptime = float((proc_root / 'uptime').read_text().split()[0])
ticks = os.sysconf('SC_CLK_TCK')
if not math.isfinite(uptime) or uptime < 0 or ticks <= 0:
return None
# Field 22 follows a comm field that may contain spaces/parentheses.
start_ticks = int((proc / 'stat').read_text().rsplit(')', 1)[1].split()[19])
if start_ticks < 0 or uptime - start_ticks / ticks < MIN_AGE_SECONDS:
return None
return start_ticks
except (OSError, ValueError, IndexError):
return None
def client_pids(prefix, proc_root=Path('/proc')):
"""Client/CEF PIDs belonging to prefix, excluding Darling and the game."""
found = []
try:
entries = list(proc_root.iterdir())
except OSError:
return []
for proc in entries:
if proc.name.isdigit() and client_identity(prefix, proc.name, proc_root) is not None:
found.append(int(proc.name))
return sorted(found)
def recover(prefix, proc_root=Path('/proc'), window_check=visible_client_window,
kill=os.kill, sleep=time.sleep, out=sys.stdout):
if not server_running(proc_root):
print('recover-stale-client: no darlingserver; normal startup', file=out, flush=True)
return 0
if game_running(proc_root):
print('recover-stale-client: game running; no action', file=out, flush=True)
return 0
if window_check():
print('recover-stale-client: client window present; no action', file=out, flush=True)
return 0
identities = {}
for pid in client_pids(prefix, proc_root):
start_ticks = client_identity(prefix, pid, proc_root)
if start_ticks is not None:
identities[pid] = start_ticks
if not identities:
print('recover-stale-client: no stale client processes; no action', file=out, flush=True)
return 0
if window_check():
print('recover-stale-client: client window appeared; no action', file=out, flush=True)
return 0
print('recover-stale-client: stale client tree without a window; '
'terminating %d process(es)' % len(identities), file=out, flush=True)
for pid, start_ticks in identities.items():
if client_identity(prefix, pid, proc_root) != start_ticks:
continue
try:
kill(pid, signal.SIGTERM)
except OSError:
pass
sleep(4)
for pid, start_ticks in identities.items():
if client_identity(prefix, pid, proc_root) != start_ticks:
continue
try:
kill(pid, signal.SIGKILL)
except OSError:
pass
return 0
def main():
if os.environ.get('RCLOL_RECOVER_STALE_CLIENT') != '1':
print('recover-stale-client: disabled; set RCLOL_RECOVER_STALE_CLIENT=1',
flush=True)
return 0
prefix = target_prefix()
if prefix is None:
print('recover-stale-client: unusable DPREFIX; no action',
file=sys.stderr, flush=True)
return 1
return recover(prefix)
if __name__ == '__main__':
sys.exit(main())
+179
View File
@@ -0,0 +1,179 @@
// Microphone path used by voice chat (Vivox/Chromium): AVFoundation audio authorization, the
// input device's channels, and an AUHAL input unit delivering recorded frames through
// AudioUnitRender(bus 1). Samples are only counted, never stored or printed.
#include <AudioToolbox/AudioUnit.h>
#include <CoreAudio/AudioHardware.h>
#include <objc/message.h>
#include <objc/runtime.h>
#include <dispatch/dispatch.h>
#include <atomic>
#include <cstdio>
#include <cstring>
#include <pthread.h>
#include <unistd.h>
extern "C" void* const AVMediaTypeAudio;
extern "C" void* const AVMediaTypeVideo;
static AudioUnit unit;
static std::atomic<unsigned> callbacks{0}, renderErrors{0}, nonIncreasing{0}, zeroFrames{0}, badBuffers{0};
static std::atomic<unsigned long long> totalFrames{0};
static double lastSample=-1;
static bool planar;
static unsigned interleavedChannels=1;
static float samples[2][2*4096];
static OSStatus input(void*,AudioUnitRenderActionFlags* flags,const AudioTimeStamp* time,UInt32 bus,UInt32 frames,AudioBufferList*) {
++callbacks;
if(!frames || frames>4096) {++zeroFrames;return noErr;}
if(!(time->mFlags&kAudioTimeStampSampleTimeValid) || time->mSampleTime<=lastSample) ++nonIncreasing;
lastSample=time->mSampleTime;
unsigned char storage[sizeof(AudioBufferList)+sizeof(AudioBuffer)];
auto* list=(AudioBufferList*)storage;
list->mNumberBuffers=planar?2:1;
for(unsigned b=0;b<list->mNumberBuffers;++b) {
list->mBuffers[b].mNumberChannels=planar?1:interleavedChannels;
list->mBuffers[b].mDataByteSize=frames*sizeof(float)*list->mBuffers[b].mNumberChannels;
list->mBuffers[b].mData=samples[b];
}
AudioUnitRenderActionFlags renderFlags=0;
OSStatus status=AudioUnitRender(unit,&renderFlags,time,bus,frames,list);
if(status) ++renderErrors;
else for(unsigned b=0;b<list->mNumberBuffers;++b)
if(list->mBuffers[b].mDataByteSize!=frames*sizeof(float)*list->mBuffers[b].mNumberChannels) ++badBuffers;
totalFrames+=frames;
return noErr;
}
static int authorization() {
Class device=objc_getClass("AVCaptureDevice");
if(!device) {printf("AUDIO_INPUT_AUTH class=0\n");return 1;}
SEL status=sel_registerName("authorizationStatusForMediaType:");
auto query=(long(*)(id,SEL,void*))objc_msgSend;
long audio=query((id)device,status,AVMediaTypeAudio),video=query((id)device,status,AVMediaTypeVideo);
// macOS calls the handler on another queue, never on the requesting thread inside the call.
// Shared with the handler's thread, so atomic; read only after the handler signals.
static std::atomic<int> granted{-1};
static std::atomic<bool> synchronous{false};
const pthread_t caller=pthread_self();
dispatch_semaphore_t done=dispatch_semaphore_create(0);
auto request=(void(*)(id,SEL,void*,void(^)(BOOL)))objc_msgSend;
request((id)device,sel_registerName("requestAccessForMediaType:completionHandler:"),AVMediaTypeAudio,^(BOOL value) {
synchronous=pthread_equal(pthread_self(),caller)!=0;granted=value;dispatch_semaphore_signal(done);
});
long waited=dispatch_semaphore_wait(done,dispatch_time(DISPATCH_TIME_NOW,2*NSEC_PER_SEC));
printf("AUDIO_INPUT_AUTH audio=%ld video=%ld request_granted=%d async=%d\n",audio,video,(int)granted,!waited && !synchronous);
fflush(stdout);
return audio!=3 || video!=2 || waited || granted!=1 || synchronous;
}
static int device(AudioDeviceID* out) {
AudioObjectPropertyAddress p={kAudioHardwarePropertyDefaultInputDevice,kAudioObjectPropertyScopeGlobal,kAudioObjectPropertyElementMaster};
AudioDeviceID id=kAudioObjectUnknown;UInt32 size=sizeof(id);
OSStatus status=AudioObjectGetPropertyData(kAudioObjectSystemObject,&p,0,nullptr,&size,&id);
if(status || id==kAudioObjectUnknown) {printf("AUDIO_INPUT_DEVICE status=%d\n",status);return 1;}
unsigned channels[2]={0,0};
for(unsigned i=0;i<2;++i) {
AudioObjectPropertyAddress c={kAudioDevicePropertyStreamConfiguration,
i?kAudioObjectPropertyScopeOutput:kAudioObjectPropertyScopeInput,kAudioObjectPropertyElementMaster};
unsigned char storage[256]={};size=sizeof(storage);
if(AudioObjectGetPropertyData(id,&c,0,nullptr,&size,storage)) return 2;
auto* list=(AudioBufferList*)storage;
for(unsigned b=0;b<list->mNumberBuffers;++b) channels[i]+=list->mBuffers[b].mNumberChannels;
}
AudioObjectPropertyAddress s={kAudioDevicePropertyStreams,kAudioObjectPropertyScopeInput,kAudioObjectPropertyElementMaster};
UInt32 streams=0;
status=AudioObjectGetPropertyDataSize(id,&s,0,nullptr,&streams);
AudioObjectPropertyAddress d={kAudioHardwarePropertyDevices,kAudioObjectPropertyScopeGlobal,kAudioObjectPropertyElementMaster};
AudioDeviceID devices[16];size=sizeof(devices);
bool listed=false;
if(!AudioObjectGetPropertyData(kAudioObjectSystemObject,&d,0,nullptr,&size,devices))
for(unsigned i=0;i<size/sizeof(AudioDeviceID);++i) listed|=devices[i]==id;
printf("AUDIO_INPUT_DEVICE input_channels=%u output_channels=%u input_streams=%u listed=%d\n",
channels[0],channels[1],(unsigned)(streams/sizeof(AudioStreamID)),listed);
fflush(stdout);
*out=id;
return channels[0]!=2 || channels[1]!=0 || status || !streams || !listed;
}
static int record(AudioDeviceID id,bool nonInterleaved,unsigned channels,unsigned milliseconds) {
AudioComponentDescription description={kAudioUnitType_Output,kAudioUnitSubType_HALOutput,kAudioUnitManufacturer_Apple,0,0};
AudioComponent component=AudioComponentFindNext(nullptr,&description);
if(!component || AudioComponentInstanceNew(component,&unit) || !unit) return 1;
planar=nonInterleaved;interleavedChannels=channels;callbacks=0;renderErrors=0;nonIncreasing=0;zeroFrames=0;badBuffers=0;totalFrames=0;lastSample=-1;
UInt32 on=1,off=0;
if(AudioUnitSetProperty(unit,kAudioOutputUnitProperty_EnableIO,kAudioUnitScope_Input,1,&on,sizeof(on))) return 2;
if(AudioUnitSetProperty(unit,kAudioOutputUnitProperty_EnableIO,kAudioUnitScope_Output,0,&off,sizeof(off))) return 3;
// Vivox (the interleaved stereo run) sets the capture device on element 1.
const AudioUnitElement deviceElement=channels==2?1:0;
if(AudioUnitSetProperty(unit,kAudioOutputUnitProperty_CurrentDevice,kAudioUnitScope_Global,deviceElement,&id,sizeof(id))) return 4;
AudioDeviceID current=0;UInt32 size=sizeof(current);
if(AudioUnitGetProperty(unit,kAudioOutputUnitProperty_CurrentDevice,kAudioUnitScope_Global,deviceElement,&current,&size) || current!=id) return 5;
AudioStreamBasicDescription format=nonInterleaved
? AudioStreamBasicDescription{44100,kAudioFormatLinearPCM,kAudioFormatFlagIsFloat|kAudioFormatFlagIsPacked|kAudioFormatFlagIsNonInterleaved,4,1,4,2,32,0}
: channels==2
// Vivox's recording format: interleaved Float32 stereo at the device rate.
? AudioStreamBasicDescription{44100,kAudioFormatLinearPCM,kAudioFormatFlagIsFloat|kAudioFormatFlagIsPacked,8,1,8,2,32,0}
: AudioStreamBasicDescription{48000,kAudioFormatLinearPCM,kAudioFormatFlagIsFloat|kAudioFormatFlagIsPacked,4,1,4,1,32,0};
OSStatus status=AudioUnitSetProperty(unit,kAudioUnitProperty_StreamFormat,kAudioUnitScope_Output,1,&format,sizeof(format));
if(status) {printf("AUDIO_INPUT_FORMAT status=%d\n",status);return 6;}
UInt32 frames=480;
if(AudioUnitSetProperty(unit,kAudioDevicePropertyBufferFrameSize,kAudioUnitScope_Global,0,&frames,sizeof(frames))) return 7;
AURenderCallbackStruct callback={input,nullptr};
if(AudioUnitSetProperty(unit,kAudioOutputUnitProperty_SetInputCallback,kAudioUnitScope_Global,0,&callback,sizeof(callback))) return 8;
if(AudioUnitInitialize(unit)) return 9;
status=AudioOutputUnitStart(unit);
if(status) {printf("AUDIO_INPUT_START status=%d\n",status);return 10;}
usleep(milliseconds*1000);
OSStatus stopped=AudioOutputUnitStop(unit);
unsigned count=callbacks;
usleep(100000);
bool quiet=callbacks==count;
AudioUnitUninitialize(unit);
AudioComponentInstanceDispose(unit);
double seconds=double(totalFrames)/format.mSampleRate;
printf("AUDIO_INPUT_RECORD planar=%d channels=%u rate=%.0f callbacks=%u frames=%llu seconds=%.3f render_errors=%u bad_buffers=%u "
"nonincreasing=%u zero_frames=%u stop_status=%d quiet_after_stop=%d\n",nonInterleaved,(unsigned)format.mChannelsPerFrame,format.mSampleRate,count,
(unsigned long long)totalFrames,seconds,(unsigned)renderErrors,(unsigned)badBuffers,(unsigned)nonIncreasing,
(unsigned)zeroFrames,stopped,quiet);
fflush(stdout);
// Startup latency aside, most of the recording time must have been delivered.
return !count || renderErrors || badBuffers || nonIncreasing || zeroFrames || stopped || !quiet
|| seconds<milliseconds/2000.0;
}
// Vivox's playback unit sets interleaved Float32 stereo at 32 kHz on input scope element 0;
// only the format is checked, nothing is played.
static int playbackFormat() {
AudioComponentDescription description={kAudioUnitType_Output,kAudioUnitSubType_HALOutput,kAudioUnitManufacturer_Apple,0,0};
AudioComponent component=AudioComponentFindNext(nullptr,&description);
AudioUnit playback=nullptr;
if(!component || AudioComponentInstanceNew(component,&playback) || !playback) return 1;
AudioStreamBasicDescription format={32000,kAudioFormatLinearPCM,kAudioFormatFlagIsFloat|kAudioFormatFlagIsPacked,8,1,8,2,32,0};
OSStatus status=AudioUnitSetProperty(playback,kAudioUnitProperty_StreamFormat,kAudioUnitScope_Input,0,&format,sizeof(format));
AudioStreamBasicDescription unsignedFormat={44100,kAudioFormatLinearPCM,kAudioFormatFlagIsPacked,4,1,4,2,16,0};
OSStatus rejected=AudioUnitSetProperty(playback,kAudioUnitProperty_StreamFormat,kAudioUnitScope_Input,0,&unsignedFormat,sizeof(unsignedFormat));
AudioComponentInstanceDispose(playback);
printf("AUDIO_PLAYBACK_FORMAT interleaved_status=%d unsigned_status=%d\n",(int)status,(int)rejected);
fflush(stdout);
return status!=noErr || rejected==noErr;
}
int main() {
int failures=0;
failures+=authorization()!=0;
AudioDeviceID id=kAudioObjectUnknown;
if(device(&id)) return 100+failures;
int result=record(id,false,1,1000);
if(result) printf("AUDIO_INPUT_RECORD failed step=%d\n",result);
failures+=result!=0;
result=record(id,true,2,400);
if(result) printf("AUDIO_INPUT_RECORD failed step=%d planar=1\n",result);
failures+=result!=0;
result=record(id,false,2,400);
if(result) printf("AUDIO_INPUT_RECORD failed step=%d interleaved_stereo=1\n",result);
failures+=result!=0;
failures+=playbackFormat()!=0;
printf("AUDIO_INPUT_CHECK failures=%d\n",failures);
return failures;
}
-202
View File
@@ -1,202 +0,0 @@
#!/usr/bin/env python3
"""Create and install the GNOME / FreeDesktop desktop entry and launcher icon."""
import os
import shutil
import subprocess
import sys
from pathlib import Path
PROJECT_ROOT = Path("@PROJECT_ROOT@")
HOST_HOME = Path("@HOST_HOME@")
DPREFIX = Path("@DPREFIX@")
SVG_ICON_CONTENT = """<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
<defs>
<linearGradient id="bgGrad" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#091428"/>
<stop offset="50%" stop-color="#0a1c36"/>
<stop offset="100%" stop-color="#030811"/>
</linearGradient>
<linearGradient id="borderGrad" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#f0e6d2"/>
<stop offset="40%" stop-color="#c8aa6e"/>
<stop offset="80%" stop-color="#785a28"/>
<stop offset="100%" stop-color="#c89b3c"/>
</linearGradient>
<linearGradient id="goldGrad" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#fff2c6"/>
<stop offset="25%" stop-color="#f0e6d2"/>
<stop offset="50%" stop-color="#c8aa6e"/>
<stop offset="85%" stop-color="#9a7a35"/>
<stop offset="100%" stop-color="#785a28"/>
</linearGradient>
<linearGradient id="goldHighlight" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" stop-color="#ffffff" stop-opacity="0.6"/>
<stop offset="100%" stop-color="#c8aa6e" stop-opacity="0"/>
</linearGradient>
<filter id="glow" x="-20%" y="-20%" width="140%" height="140%">
<feGaussianBlur stdDeviation="6" result="blur"/>
<feComposite in="SourceGraphic" in2="blur" operator="over"/>
</filter>
<filter id="shadow" x="-20%" y="-20%" width="140%" height="140%">
<feDropShadow dx="0" dy="8" stdDeviation="14" flood-color="#000000" flood-opacity="0.85"/>
</filter>
</defs>
<!-- Background Shield / Squircle -->
<rect x="24" y="24" width="464" height="464" rx="104" fill="url(#bgGrad)" stroke="url(#borderGrad)" stroke-width="12" filter="url(#shadow)"/>
<rect x="40" y="40" width="432" height="432" rx="90" fill="none" stroke="#c8aa6e" stroke-width="2" stroke-opacity="0.4"/>
<!-- Crest Emblem -->
<g filter="url(#glow)">
<path d="M172 108 L242 108 L242 316 L364 316 L352 388 L156 388 L156 124 Z"
fill="url(#goldGrad)" stroke="#463714" stroke-width="3"/>
<path d="M 180 120 L 230 120 L 230 250 L 180 200 Z"
fill="url(#goldHighlight)"/>
<path d="M 242 328 L 348 328 L 340 376 L 172 376 L 172 356 L 242 356 Z"
fill="#c8aa6e" opacity="0.45"/>
<polygon points="256,76 264,96 284,96 268,108 274,128 256,116 238,128 244,108 228,96 248,96" fill="#f0e6d2"/>
</g>
</svg>
"""
def extract_best_png_from_icns(icns_path: Path) -> bytes | None:
"""Extract the highest-resolution embedded PNG from an Apple ICNS file."""
try:
data = icns_path.read_bytes()
if not data.startswith(b"icns"):
return None
offset = 8
best_png = None
best_len = 0
while offset + 8 <= len(data):
size = int.from_bytes(data[offset + 4 : offset + 8], "big")
if size < 8 or offset + size > len(data):
break
chunk = data[offset + 8 : offset + size]
if chunk.startswith(b"\x89PNG\r\n\x1a\n") and len(chunk) > best_len:
best_png = chunk
best_len = len(chunk)
offset += size
return best_png
except Exception:
return None
def find_candidate_icns() -> Path | None:
"""Find any available Riot or League .icns icon files."""
candidates = [
*list((PROJECT_ROOT / "build/installer").glob("*League of Legends*.app/Contents/Resources/*.icns")),
*list(DPREFIX.glob("Users/Shared/Riot Games/Riot Client.app/Contents/Resources/*.icns")),
*list(DPREFIX.glob("Applications/Riot Client.app/Contents/Resources/*.icns")),
*list(DPREFIX.glob("Applications/League of Legends.app/Contents/Resources/*.icns")),
]
for c in candidates:
if c.is_file() and c.stat().st_size > 1024:
return c
return None
def main():
icons_base = HOST_HOME / ".local/share/icons"
apps_base = HOST_HOME / ".local/share/applications"
desktop_dir = HOST_HOME / "Desktop"
scalable_dir = icons_base / "hicolor/scalable/apps"
png_dir = icons_base / "hicolor/512x512/apps"
scalable_dir.mkdir(parents=True, exist_ok=True)
png_dir.mkdir(parents=True, exist_ok=True)
apps_base.mkdir(parents=True, exist_ok=True)
# 1. Install scalable SVG icon
svg_target = scalable_dir / "league-of-legends.svg"
svg_target.write_text(SVG_ICON_CONTENT)
shutil.copyfile(svg_target, icons_base / "league-of-legends.svg")
# 2. Extract or generate PNG icon
png_target = png_dir / "league-of-legends.png"
icns_file = find_candidate_icns()
extracted = False
if icns_file:
png_data = extract_best_png_from_icns(icns_file)
if png_data:
png_target.write_bytes(png_data)
shutil.copyfile(png_target, icons_base / "league-of-legends.png")
extracted = True
print(f"Extracted official icon from {icns_file.name} to {png_target}")
if not extracted and not png_target.exists():
# Try to rasterize SVG via rsvg-convert or magick
rsvg = shutil.which("rsvg-convert")
magick = shutil.which("magick") or shutil.which("convert")
if rsvg:
subprocess.run([rsvg, "-w", "512", "-h", "512", str(svg_target), "-o", str(png_target)], check=False)
if png_target.exists():
shutil.copyfile(png_target, icons_base / "league-of-legends.png")
elif magick:
subprocess.run([magick, "-background", "none", "-resize", "512x512", str(svg_target), str(png_target)], check=False)
if png_target.exists():
shutil.copyfile(png_target, icons_base / "league-of-legends.png")
# 3. Create .desktop file
run_script = PROJECT_ROOT / "scripts/desktop-run.sh"
exec_path = str(run_script).replace("%", "%%")
exec_cmd = f'"{exec_path}"' if " " in exec_path else exec_path
desktop_content = f"""[Desktop Entry]
Version=1.0
Type=Application
Name=League of Legends
GenericName=MOBA Game
Comment=Play League of Legends on Linux with darling-lol
Exec={exec_cmd}
Path={PROJECT_ROOT}
Icon=league-of-legends
Terminal=false
Categories=Game;ActionGame;StrategyGame;
Keywords=riot;league;lol;darling;games;
StartupWMClass=Riot Client
StartupNotify=false
"""
desktop_file = apps_base / "league-of-legends.desktop"
desktop_file.write_text(desktop_content)
os.chmod(desktop_file, 0o755)
print(f"Created application launcher: {desktop_file}")
target_desktop_dirs = []
try:
res = subprocess.run(["xdg-user-dir", "DESKTOP"], capture_output=True, text=True, check=False)
if res.returncode == 0 and res.stdout.strip():
d = Path(res.stdout.strip())
if d.is_dir() and d not in target_desktop_dirs:
target_desktop_dirs.append(d)
except Exception:
pass
for cand in [HOST_HOME / "Desktop"]:
if cand.is_dir() and cand not in target_desktop_dirs:
target_desktop_dirs.append(cand)
for ddir in target_desktop_dirs:
desktop_shortcut = ddir / "league-of-legends.desktop"
desktop_shortcut.write_text(desktop_content)
os.chmod(desktop_shortcut, 0o755)
gio = shutil.which("gio")
if gio:
subprocess.run([gio, "set", str(desktop_shortcut), "metadata::trusted", "true"], check=False)
print(f"Created desktop shortcut: {desktop_shortcut}")
# 4. Refresh icon and desktop databases
update_desktop = shutil.which("update-desktop-database")
if update_desktop:
subprocess.run([update_desktop, str(apps_base)], check=False)
update_icons = shutil.which("gtk-update-icon-cache")
if update_icons:
subprocess.run([update_icons, "-f", "-t", str(icons_base / "hicolor")], check=False)
print("GNOME application launcher and icon installed successfully.")
if __name__ == "__main__":
main()
+98
View File
@@ -0,0 +1,98 @@
/* Local event dispatch regression; also runs unchanged against native AppKit.
* No global input, client hooks, account access, or mapped windows. */
#import <AppKit/AppKit.h>
static NSMutableString *calls;
static int failures;
@interface MonitorTestWindow : NSWindow
@end
@implementation MonitorTestWindow
- (void) sendEvent: (NSEvent *) event {
[calls appendFormat: @"W%ld", (long)[event type]];
}
@end
static void expectCalls(NSString *name, NSString *expected) {
BOOL ok = [calls isEqual: expected];
printf("%s %s got=%s expected=%s\n", ok ? "PASS" : "FAIL",
[name UTF8String], [calls UTF8String], [expected UTF8String]);
failures += !ok;
[calls setString: @""];
}
/* AppKit does not promise an order between independent registrations. Native
* ordering can change with block addresses, even on the same OS build. */
static void expectBoth(NSString *name) {
NSString *expected = [calls isEqual: @"ABW1"] ? @"ABW1" : @"BAW1";
expectCalls(name, expected);
}
int main(void) {
@autoreleasepool {
[NSApplication sharedApplication];
calls = [NSMutableString new];
NSWindow *window = [[MonitorTestWindow alloc]
initWithContentRect: NSMakeRect(100, 100, 300, 200)
styleMask: 0 backing: NSBackingStoreBuffered defer: NO];
NSEvent *down = [NSEvent mouseEventWithType: NSLeftMouseDown
location: NSMakePoint(10, 10) modifierFlags: 0 timestamp: 0
windowNumber: [window windowNumber] context: nil
eventNumber: 1 clickCount: 1 pressure: 1];
NSEvent *up = [NSEvent mouseEventWithType: NSLeftMouseUp
location: NSMakePoint(10, 10) modifierFlags: 0 timestamp: 0
windowNumber: [window windowNumber] context: nil
eventNumber: 2 clickCount: 1 pressure: 0];
id a = [NSEvent addLocalMonitorForEventsMatchingMask: NSLeftMouseDownMask
handler: ^NSEvent *(NSEvent *event) {
[calls appendString: @"A"]; return event;
}];
id b = [NSEvent addLocalMonitorForEventsMatchingMask: NSLeftMouseDownMask
handler: ^NSEvent *(NSEvent *event) {
[calls appendString: @"B"]; return event;
}];
[NSApp sendEvent: down]; expectBoth(@"multiple-monitors");
[NSApp sendEvent: up]; expectCalls(@"mask-filter", @"W2");
[NSEvent removeMonitor: b];
[NSApp sendEvent: down]; expectCalls(@"remove", @"AW1");
[NSEvent removeMonitor: a];
b = [NSEvent addLocalMonitorForEventsMatchingMask: NSLeftMouseDownMask
handler: ^NSEvent *(NSEvent *event) {
[calls appendString: @"B"]; return nil;
}];
[NSApp sendEvent: down]; expectCalls(@"consume", @"B");
[NSEvent removeMonitor: b];
b = [NSEvent addLocalMonitorForEventsMatchingMask: NSLeftMouseDownMask
handler: ^NSEvent *(NSEvent *event) {
[calls appendString: @"B"]; return up;
}];
[NSApp sendEvent: down]; expectCalls(@"replace-event", @"BW2");
[NSEvent removeMonitor: b];
__block id selfRemoving;
selfRemoving = [NSEvent addLocalMonitorForEventsMatchingMask: NSLeftMouseDownMask
handler: ^NSEvent *(NSEvent *event) {
[calls appendString: @"S"];
[NSEvent removeMonitor: selfRemoving]; return event;
}];
[NSApp sendEvent: down]; expectCalls(@"self-remove", @"SW1");
[NSApp sendEvent: down]; expectCalls(@"self-remove-next", @"W1");
__block id pendingA, pendingB;
pendingA = [NSEvent addLocalMonitorForEventsMatchingMask: NSLeftMouseDownMask
handler: ^NSEvent *(NSEvent *event) {
[calls appendString: @"A"];
[NSEvent removeMonitor: pendingB]; return event;
}];
pendingB = [NSEvent addLocalMonitorForEventsMatchingMask: NSLeftMouseDownMask
handler: ^NSEvent *(NSEvent *event) {
[calls appendString: @"B"];
[NSEvent removeMonitor: pendingA]; return event;
}];
[NSApp sendEvent: down]; expectBoth(@"remove-pending-snapshot");
[NSApp sendEvent: down]; expectCalls(@"remove-pending-next", @"W1");
[window release];
[calls release];
}
return failures ? 1 : 0;
}
+41 -4
View File
@@ -8,6 +8,14 @@
#import <OpenGL/gl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
extern "C" void _dispatch_main_queue_callback_4CF(void *);
@interface PresentationCheckWindow : NSWindow
@end
@implementation PresentationCheckWindow
- (BOOL)canBecomeKeyWindow { return YES; }
@end
static void verifyPresentation(bool value, const char* message) {
if (!value) { fprintf(stderr, "FAIL: %s\n", message); exit(1); }
@@ -18,7 +26,12 @@ static void pump(NSApplication* app) {
NSEvent* event = [app nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast]
inMode:NSDefaultRunLoopMode dequeue:YES];
if (event) [app sendEvent:event];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.005]];
// A timed NSRunLoop wait can miss its deadline on Darling when the
// X connection is quiet. Parent presentation no longer supplies child
// Expose events to wake it; service sources without a blocking wait.
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.0, true);
_dispatch_main_queue_callback_4CF(nullptr);
usleep(1000);
}
}
int main() {
@@ -35,6 +48,7 @@ int main() {
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
verifyPresentation(device != nil, "device");
CAMetalLayer* layer = [CAMetalLayer layer];
verifyPresentation(layer.displaySyncEnabled == YES, "VSync enabled by default");
layer.device = device;
layer.drawableSize = CGSizeMake(160,96);
layer.frame = CGRectMake(0,0,160,96);
@@ -52,12 +66,17 @@ int main() {
} else {
view.layer = layer;
}
NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(50,50,160,96)
styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO];
window.title = @"Metal presentation check";
const bool parentDrawable = getenv("RIOT_PRESENTATION_PARENT") != nullptr;
NSWindow* window = [[PresentationCheckWindow alloc] initWithContentRect:NSMakeRect(50,50,160,96)
styleMask:(parentDrawable ? NSBorderlessWindowMask : NSTitledWindowMask) backing:NSBackingStoreBuffered defer:parentDrawable];
window.title = parentDrawable ? @"Presentation (TM) Client" : @"Metal presentation check";
window.contentView = view;
[window makeKeyAndOrderFront:nil];
pump(app);
if (parentDrawable) {
void *borrowed = [[(CALayerContext*)[layer _context] subwindow] sharedCGLWindow];
verifyPresentation(borrowed != nullptr, "full-window game layer borrows managed parent drawable");
}
id<MTLCommandQueue> queue = [device newCommandQueue];
const unsigned frameCount = captureTest ? 130u : getenv("RIOT_PRESENTATION_STRESS") ? 120u : 10u;
for (unsigned frame = 0; frame < frameCount; ++frame) {
@@ -66,6 +85,7 @@ int main() {
verifyPresentation(flag != nullptr, "request second bounded capture");
fclose(flag);
}
layer.displaySyncEnabled = (frame % 3) != 1;
@autoreleasepool {
id<CAMetalDrawable> drawable = [layer nextDrawable];
verifyPresentation(drawable != nil, "drawable after late window/context attachment");
@@ -82,6 +102,23 @@ int main() {
[commands commit];
[commands waitUntilCompleted];
pump(app);
GLint interval = -1;
CGLGetParameter([(CALayerContext*)[layer _context] glContext], kCGLCPSwapInterval, &interval);
verifyPresentation(interval == (layer.displaySyncEnabled ? 1 : 0), "Metal VSync reaches window swap interval");
if (parentDrawable) {
void *borrowed = [[(CALayerContext*)[layer _context] subwindow] sharedCGLWindow];
verifyPresentation(borrowed != nullptr, "parent drawable remains borrowed");
if (frame == 3 && getenv("RIOT_PRESENTATION_RESIZE")) {
CALayerContext* context = (CALayerContext*)[layer _context];
CGRect original = [view frame];
[context setFrame:CGRectMake(0,0,original.size.width / 2,original.size.height)];
[context render]; [context flush];
verifyPresentation([[context subwindow] sharedCGLWindow] == nullptr, "partial view falls back to child drawable");
[context setFrame:original];
[context render]; [context flush];
verifyPresentation([[context subwindow] sharedCGLWindow] != nullptr, "restored view borrows parent drawable again");
}
}
}
}
CGLContextObj previous = CGLGetCurrentContext();
+27 -1
View File
@@ -48,8 +48,34 @@ int main(void) {
XEvent map={0};map.type=KeymapNotify;[display postXEvent:&map];expectModifier(0x37,0);
key(display,KeyPress,66,0);expectModifier(0x39,NSAlphaShiftKeyMask);
key(display,KeyRelease,66,LockMask);expectModifier(0x39,NSAlphaShiftKeyMask);
// GNOME overview: Super press delivered, release swallowed, no focus change.
// The next event's server state lacks Mod4, so Command must be released first.
key(display,KeyPress,133,LockMask);expectModifier(0x37,NSAlphaShiftKeyMask|NSCommandKeyMask);
NSUInteger before=[events count];
key(display,KeyPress,50,LockMask);
assert([events count]==before+2);
NSEvent *released=[events objectAtIndex:before];
assert([released keyCode]==0x37 && [released modifierFlags]==NSAlphaShiftKeyMask);
expectModifier(0x38,NSAlphaShiftKeyMask|NSShiftKeyMask);
// A modifier that is still held stays held.
key(display,KeyPress,133,LockMask|ShiftMask);expectModifier(0x37,NSAlphaShiftKeyMask|NSShiftKeyMask|NSCommandKeyMask);
before=[events count];
key(display,KeyRelease,50,LockMask|ShiftMask|Mod4Mask);
assert([events count]==before+1);
expectModifier(0x38,NSAlphaShiftKeyMask|NSCommandKeyMask);
// Right Alt is Mod1 (Option) on US layouts and Mod5 (AltGr) elsewhere; the
// backend reads the server map, so take whichever it reported and check it
// is still held, and reported once, when Command goes up.
key(display,KeyPress,108,LockMask|Mod4Mask);
NSUInteger rightAlt=[[events lastObject] modifierFlags]&~(NSUInteger)(NSAlphaShiftKeyMask|NSCommandKeyMask);
assert(rightAlt==NSAlternateKeyMask || rightAlt==NSFunctionKeyMask);
unsigned int rightAltMask=rightAlt==NSAlternateKeyMask ? Mod1Mask : Mod5Mask;
before=[events count];
key(display,KeyRelease,133,LockMask|Mod4Mask|rightAltMask);
assert([events count]==before+1);
expectModifier(0x37,NSAlphaShiftKeyMask|rightAlt);
method_setImplementation(method,original);
puts("PASS Super=Command, Alt=Option, both Command keys, post-transition flags, focus-loss release, missed-release reconciliation, Caps Lock");
puts("PASS Super=Command, Alt=Option, both Command keys, post-transition flags, focus-loss release, missed-release reconciliation, Caps Lock, swallowed Super release, layout-mapped Right Alt");
[events release];
}
return 0;
+201
View File
@@ -0,0 +1,201 @@
/* Standalone AppKit regression for issue #85: the panel's own Open/Cancel
* buttons must end runModal. Drives only its own NSOpenPanel; no Riot/League
* client is launched or contacted and no external input is generated.
*
* riot-openpanel-check --auto cancel|open-selected|open-none
* riot-openpanel-check --interactive
*/
#import <AppKit/AppKit.h>
#include <dispatch/dispatch.h>
#include <objc/runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static NSOpenPanel *panel;
static NSString *tempDir, *subDir;
static const char *mode;
static BOOL interactive;
static BOOL panelVisibleAtTrigger;
/* Plain C storage: an autoreleased NSString kept here would be freed by the
* modal loop's pools before the result is reported (and the watchdog thread
* reads it too). */
static char triggerNote[160] = "";
static const double kTriggerDelay = 1.5, kWatchdog = 15.0;
static NSButton *findButton(NSView *view, SEL action) {
if ([view isKindOfClass:[NSButton class]] && [(NSButton *)view action] == action)
return (NSButton *)view;
for (NSView *sub in [view subviews]) {
NSButton *found = findButton(sub, action);
if (found) return found;
}
return nil;
}
static NSOutlineView *findOutline(NSView *view) {
if ([view isKindOfClass:[NSOutlineView class]]) return (NSOutlineView *)view;
for (NSView *sub in [view subviews]) {
NSOutlineView *found = findOutline(sub);
if (found) return found;
}
return nil;
}
static void press(SEL action, const char *name) {
NSButton *button = findButton([panel contentView], action);
if (button) {
snprintf(triggerNote, sizeof triggerNote, "%s via button", name);
[button performClick:nil];
} else {
snprintf(triggerNote, sizeof triggerNote, "%s via direct action (button not found)", name);
[panel performSelector:action withObject:nil];
}
}
static char selectNote[320] = "";
static BOOL selectionOK = YES;
static NSString *urlPath(id item) {
NSString *path = [item isKindOfClass:[NSURL class]] ? [item path] : nil;
while ([path length] > 1 && [path hasSuffix:@"/"])
path = [path substringToIndex:[path length] - 1];
return path;
}
/* The panel's tree is rooted at "/" and is not navigated to the directory
* being shown, so expand each component of subDir from the root, then select
* its row. Records diagnostics in selectNote. */
static BOOL selectSubfolder(void) {
NSOutlineView *outline = findOutline([panel contentView]);
if (!outline) { snprintf(selectNote, sizeof selectNote, "no_outline_view"); return NO; }
[outline reloadData];
NSString *prefix = @"";
NSInteger found = -1;
for (NSString *part in [subDir pathComponents]) {
if ([part isEqualToString:@"/"]) continue;
prefix = [prefix stringByAppendingFormat:@"/%@", part];
found = -1;
for (NSInteger row = 0; row < [outline numberOfRows]; row++) {
if ([urlPath([outline itemAtRow:row]) isEqualToString:prefix]) { found = row; break; }
}
if (found < 0) {
snprintf(selectNote, sizeof selectNote, "row_not_found at=%s rows=%ld",
[prefix UTF8String], (long)[outline numberOfRows]);
return NO;
}
if (![prefix isEqualToString:subDir]) [outline expandItem:[outline itemAtRow:found]];
}
[outline selectRowIndexes:[NSIndexSet indexSetWithIndex:found] byExtendingSelection:NO];
NSIndexSet *sel = [outline selectedRowIndexes];
NSInteger selRow = [sel firstIndex] == NSNotFound ? -1 : (NSInteger)[sel firstIndex];
id item = selRow >= 0 ? [outline itemAtRow:selRow] : nil;
NSString *itemPath = urlPath(item);
snprintf(selectNote, sizeof selectNote,
"target_row=%ld selected_count=%lu selected_row=%ld item_class=%s item_path=%s",
(long)found, (unsigned long)[sel count], (long)selRow,
item ? class_getName([item class]) : "nil", itemPath ? [itemPath UTF8String] : "(nil)");
return selRow == found;
}
@interface Trigger : NSObject
- (void)fire:(NSTimer *)timer;
@end
@implementation Trigger
- (void)fire:(NSTimer *)timer {
static BOOL done;
if (done) return;
done = YES;
panelVisibleAtTrigger = [panel isVisible];
if (!strcmp(mode, "cancel")) {
press(@selector(_cancel:), "cancel");
} else {
if (!strcmp(mode, "open-selected")) selectionOK = selectSubfolder();
press(@selector(_selectFile:), "open");
}
}
@end
int main(int argc, char **argv) {
setbuf(stdout, NULL);
if (argc == 2 && !strcmp(argv[1], "--interactive")) {
interactive = YES;
mode = "interactive";
} else if (argc == 3 && !strcmp(argv[1], "--auto") &&
(!strcmp(argv[2], "cancel") || !strcmp(argv[2], "open-selected") ||
!strcmp(argv[2], "open-none"))) {
mode = argv[2];
} else {
fprintf(stderr, "usage: %s --auto cancel|open-selected|open-none | --interactive\n", argv[0]);
return 2;
}
@autoreleasepool {
[NSApplication sharedApplication];
char templ[] = "/tmp/openpanel-check.XXXXXX";
tempDir = [[NSString stringWithUTF8String:mkdtemp(templ)] retain];
subDir = [[tempDir stringByAppendingPathComponent:@"subfolder"] retain];
[[NSFileManager defaultManager] createDirectoryAtPath:subDir
withIntermediateDirectories:YES attributes:nil error:NULL];
panel = [[NSOpenPanel openPanel] retain];
[panel setCanChooseDirectories:YES];
[panel setCanChooseFiles:NO];
[panel setAllowsMultipleSelection:NO];
[panel setDirectory:tempDir];
if (!interactive) {
/* Independent of the run loop: a hung runModal still reports. */
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kWatchdog * NSEC_PER_SEC)),
dispatch_get_global_queue(0, 0), ^{
printf("OPENPANEL_CHECK mode=%s result=FAIL problems=HANG "
"trigger=\"%s\" visible_at_trigger=%d\n",
mode, triggerNote, panelVisibleAtTrigger);
fflush(stdout);
_exit(3);
});
Trigger *trigger = [[Trigger alloc] init];
NSTimer *timer = [NSTimer timerWithTimeInterval:kTriggerDelay target:trigger
selector:@selector(fire:) userInfo:nil repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSModalPanelRunLoopMode];
} else {
printf("Interactive: pick the folder, or press Open/Cancel on the panel.\n");
}
NSInteger code = [panel runModal];
NSString *path = [[panel URL] path];
NSArray *urls = [panel URLs];
BOOL visible = [panel isVisible];
NSString *shown = path ? path : @"(none)";
if (interactive) {
printf("OPENPANEL_CHECK mode=interactive result=RETURNED code=%ld url=%s urls=%lu visible=%d\n",
(long)code, [shown UTF8String], (unsigned long)[urls count], visible);
return 0;
}
NSMutableArray *problems = [NSMutableArray array];
BOOL wantOpen = strcmp(mode, "cancel") != 0;
NSString *wantPath = !strcmp(mode, "open-selected") ? subDir : tempDir;
if (!panelVisibleAtTrigger) [problems addObject:@"panel_not_visible_at_trigger"];
if (wantOpen) {
if (code != NSOKButton) [problems addObject:@"code_not_ok"];
if (![path isEqualToString:wantPath]) [problems addObject:@"wrong_url"];
if ([urls count] != 1) [problems addObject:@"wrong_url_count"];
} else if (code != NSCancelButton) {
[problems addObject:@"code_not_cancel"];
}
if (visible) [problems addObject:@"still_visible"];
if (!selectionOK) [problems addObject:@"selection_failed"];
BOOL pass = [problems count] == 0;
printf("OPENPANEL_CHECK mode=%s result=%s code=%ld url=%s expected_url=%s visible=%d trigger=\"%s\"%s%s%s%s%s\n",
mode, pass ? "PASS" : "FAIL", (long)code, [shown UTF8String],
wantOpen ? [wantPath UTF8String] : "-", visible, triggerNote,
selectNote[0] ? " selection=\"" : "", selectNote, selectNote[0] ? "\"" : "",
pass ? "" : " problems=",
pass ? "" : [[problems componentsJoinedByString:@","] UTF8String]);
fflush(stdout);
return pass ? 0 : 1;
}
}
+3 -4
View File
@@ -25,10 +25,9 @@ with tempfile.TemporaryDirectory(prefix='darling-cleanup-check-') as folder:
process(104, 'unrelated', ['/usr/bin/unrelated', '/sbin/launchd'])
with patch.object(cleanup.os, 'kill') as kill:
cleanup.stop_riot_crashpad(root)
assert kill.call_args_list == [((102, cleanup.signal.SIGTERM),)]
kill.reset_mock()
kill.assert_not_called()
cleanup.stop_orphaned_launchd(root)
assert kill.call_args_list == [((103, cleanup.signal.SIGKILL),)]
kill.assert_not_called()
assert not cleanup.any_server_running(root)
process(105, 'darlingserver', ['darlingserver', '--prefix=another-prefix'])
assert cleanup.any_server_running(root)
@@ -58,4 +57,4 @@ with tempfile.TemporaryDirectory(prefix='darling-cleanup-check-') as folder:
crashpad.assert_not_called()
orphan.assert_not_called()
remove.assert_not_called()
print('RUNTIME_CLEANUP_OFFLINE pass=1 browser_preserved=1 other_prefix_preserved=1 foreign_owner_preserved=1 hidden_process_preserved=1 orphan_recovered=1')
print('RUNTIME_CLEANUP_OFFLINE pass=1 browser_preserved=1 other_prefix_preserved=1 foreign_owner_preserved=1 hidden_process_preserved=1 orphan_preserved=1')
+74
View File
@@ -0,0 +1,74 @@
#import <AppKit/NSApplication.h>
#import <AppKit/NSSavePanel.h>
#import <AppKit/NSOpenPanel.h>
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#include <stdio.h>
/* Declarations only: implementations must come from the loaded AppKit, not
* from linking a compatibility category directly into this probe. */
@interface NSSavePanel (RiotTagProbeDeclarations)
- (void)setShowsTagField:(BOOL)value;
- (BOOL)showsTagField;
- (void)setTagNames:(NSArray *)names;
- (NSArray *)tagNames;
@end
static BOOL emptyTags(NSSavePanel *panel) {
NSArray *tags = [panel tagNames];
return tags != nil && [tags isKindOfClass:[NSArray class]] && [tags count] == 0;
}
static BOOL checkPanel(Class panelClass) {
SEL selectors[] = {@selector(setShowsTagField:), @selector(showsTagField),
@selector(setTagNames:), @selector(tagNames)};
BOOL available = YES, inherited = YES, values = NO;
/* This stateless probe must work without panel initialization. Bare runtime
* allocation avoids NSWindow/nib/display setup; it does NOT test the chooser.
* Dispose without running NSWindow's deallocator on an uninitialized panel. */
NSSavePanel *panel = (NSSavePanel *)class_createInstance(panelClass, 0);
for (unsigned i = 0; i < sizeof(selectors) / sizeof(selectors[0]); ++i) {
Method base = class_getInstanceMethod([NSSavePanel class], selectors[i]);
Method method = class_getInstanceMethod(panelClass, selectors[i]);
available &= panel != nil && method != NULL && [panel respondsToSelector:selectors[i]];
inherited &= base != NULL && method != NULL &&
method_getImplementation(base) == method_getImplementation(method);
}
if (panelClass == [NSOpenPanel class])
inherited &= class_getSuperclass(panelClass) == [NSSavePanel class];
if (available) {
@try {
values = ![panel showsTagField] && emptyTags(panel);
[panel setShowsTagField:YES];
values &= ![panel showsTagField];
[panel setShowsTagField:NO];
values &= ![panel showsTagField];
NSMutableArray *names = [NSMutableArray arrayWithObject:@"probe-tag"];
[panel setTagNames:names];
[names addObject:@"second-tag"];
values &= emptyTags(panel);
[panel setTagNames:[NSArray array]];
values &= emptyTags(panel);
[panel setTagNames:nil];
values &= emptyTags(panel);
} @catch (NSException *exception) {
fprintf(stderr, "SAVE_PANEL_TAG exception=%s\n", [[exception name] UTF8String]);
values = NO;
}
}
if (panel != nil)
object_dispose(panel);
BOOL pass = available && inherited && values;
printf("SAVE_PANEL_TAG class=%s selectors=%d inherited=%d values=%d pass=%d\n",
class_getName(panelClass), available, inherited, values, pass);
return pass;
}
int main(void) {
@autoreleasepool {
BOOL save = checkPanel([NSSavePanel class]);
BOOL open = checkPanel([NSOpenPanel class]);
printf("SAVE_PANEL_TAG_CHECK pass=%d\n", save && open);
return save && open ? 0 : 1;
}
}
+86
View File
@@ -0,0 +1,86 @@
/* Standalone Cocoa/X11 regression: no client windows, hooks or input. */
#import <AppKit/AppKit.h>
#import <AppKit/NSDisplay.h>
#include <X11/Xlib.h>
#include <assert.h>
#include <dlfcn.h>
#include <stdio.h>
@protocol DecorationProbeDisplay
- (void *)display;
@end
@interface NSObject (DecorationProbe)
- (unsigned long)windowHandle;
- (void)recreateXWindowWithAlpha:(BOOL)alpha;
@end
static BOOL undecorated(NSWindow *window) {
void *xlib = dlopen("/usr/lib/native/libX11.dylib", RTLD_LAZY);
assert(xlib);
Atom (*intern)(Display *, const char *, Bool) = dlsym(xlib, "XInternAtom");
int (*sync)(Display *, Bool) = dlsym(xlib, "XSync");
int (*get)(Display *, Window, Atom, long, long, Bool, Atom,
Atom *, int *, unsigned long *, unsigned long *, unsigned char **) =
dlsym(xlib, "XGetWindowProperty");
int (*freeData)(void *) = dlsym(xlib, "XFree");
assert(intern && sync && get && freeData);
id native = [window platformWindow];
Display *display = (Display *)[(id<DecorationProbeDisplay>)[NSDisplay currentDisplay] display];
sync(display, False);
Atom type = None;
int format = 0;
unsigned long count = 0, remaining = 0;
unsigned char *data = NULL;
int status = get(display, [native windowHandle], intern(display, "_MOTIF_WM_HINTS", False),
0, 5, False, AnyPropertyType, &type, &format, &count, &remaining, &data);
assert(status == Success);
BOOL result = format == 32 && count >= 3 && data &&
(((unsigned long *)data)[0] & 2) && ((unsigned long *)data)[2] == 0;
if (data) freeData(data);
dlclose(xlib);
return result;
}
static void assertDecoration(NSWindow *window, BOOL expected, const char *name) {
BOOL actual = undecorated(window);
printf("WINDOW_DECORATION case=%s undecorated=%d expected=%d\n", name, actual, expected);
assert(actual == expected);
}
int main(void) {
setbuf(stdout, NULL);
@autoreleasepool {
[NSApplication sharedApplication];
NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(20, 20, 320, 180)
styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO];
assertDecoration(window, NO, "ordinary titled window");
[window setTitleVisibility:1];
assertDecoration(window, NO, "hidden title alone preserves frame");
[window setTitlebarAppearsTransparent:YES];
assertDecoration(window, YES, "hidden and transparent title removes frame");
[window setTitleVisibility:0];
assertDecoration(window, NO, "visible title restores frame");
[window setTitleVisibility:1];
[window setTitlebarAppearsTransparent:NO];
assertDecoration(window, NO, "opaque title restores frame");
[window setStyleMask:NSTexturedBackgroundWindowMask];
assertDecoration(window, YES, "untitled with extra flags");
[window setStyleMask:NSTitledWindowMask];
assertDecoration(window, NO, "titled style restored");
[window setStyleMask:NSBorderlessWindowMask];
assertDecoration(window, YES, "borderless after creation");
[window setStyleMask:NSTitledWindowMask];
[window setTitlebarAppearsTransparent:YES];
[(id)[window platformWindow] recreateXWindowWithAlpha:NO];
assertDecoration(window, YES, "recreated native window retains client chrome");
NSWindow *deferred = [[NSWindow alloc] initWithContentRect:NSMakeRect(20, 20, 320, 180)
styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:YES];
[deferred setTitleVisibility:1];
[deferred setTitlebarAppearsTransparent:YES];
assertDecoration(deferred, YES, "properties set before native creation");
puts("WINDOW_DECORATIONS_CHECK cases=10 pass=1");
// Windows stay unmapped: the probe never changes compositor focus.
}
return 0;
}
+39 -6
View File
@@ -9,15 +9,21 @@ if [ "${RCLOL_CORE_DUMPS:-0}" != 1 ]; then
fi
runner_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
. "$runner_dir/runtime-paths.sh"
# Opt-in partial recovery: if Darling is alive but a previous client tree is
# windowless, stop only that client/CEF tree and reuse the runtime. Never
# touches the game, darlingserver or the runtime sockets.
if [ "${RCLOL_RECOVER_STALE_CLIENT:-0}" = 1 ]; then
python3 "$runner_dir/recover-stale-client.py"
fi
if [ "${RCLOL_RECOVER_HIDDEN_CLIENT:-0}" = 1 ]; then
python3 "$runner_dir/recover-hidden-riot-client.py"
fi
# Opt-in: close the League client UI while a match runs. It keeps the CPU for the game
# and leaves the client the backend starts when the match ends as the only CEF instance;
# a second instance on the same profile never paints its window, which is the black
# window seen with Riot's own "Close client during game" option. Off by default.
if [ "${RCLOL_CLOSE_CLIENT_IN_GAME:-0}" = 1 ]; then
python3 "$runner_dir/close-league-client-in-game.py" --detach &
# Opt-in cleanup of helpers left by an earlier launcher. This runs before the
# current helper is started. It removes only helpers of this prefix whose
# parent is init/systemd, so a helper of a live launcher is not touched.
if [ "${RCLOL_CLEAN_STALE_HELPERS:-0}" = 1 ]; then
python3 "$runner_dir/clean-stale-helpers.py" --prefix "$prefix_dir" ||
echo 'clean-stale-helpers: cleanup failed; continuing' >&2
fi
# The bundled downloader rejects IPv6 CONNECT_TO addresses. Only Riot CDN
# AAAA lookups are suppressed; set this to 0 to retain the upstream resolver.
@@ -66,6 +72,33 @@ if [ -z "${RIOT_LAUNCHER_HOST:-}" ] && [ ! -e "$client" ]; then
ln -s "../Users/Shared/Riot Games/Riot Client.app" "$client"
fi
fi
# Opt-in automatic client-in-game handling. Start the watcher only after the
# installed-client check above: a failed installer launch must not leave a
# helper behind. The preference selector returns no action for missing or
# invalid close-during-game values.
if [ -z "${RIOT_LAUNCHER_HOST:-}" ]; then
if [ "${RCLOL_CLIENT_IN_GAME_TRICKS:-0}" = 1 ]; then
pref="$prefix_dir/Applications/League of Legends.app/Contents/LoL/Config/LCULocalPreferences.yaml"
mode=$(python3 "$runner_dir/client-in-game-tricks.py" "$pref" 2>/dev/null || echo none)
case "$mode" in
close)
echo 'client-in-game-tricks: closeLeagueClientDuringGame=true -> close helper' >&2
python3 "$runner_dir/close-league-client-in-game.py" --detach &
;;
hide)
echo 'client-in-game-tricks: closeLeagueClientDuringGame=false -> hide helper' >&2
python3 "$runner_dir/hide-league-client-in-game.py" --detach &
;;
*)
echo 'client-in-game-tricks: no action (client optimizations disabled or preferences missing/invalid)' >&2
;;
esac
elif [ "${RCLOL_CLOSE_CLIENT_IN_GAME:-0}" = 1 ]; then
python3 "$runner_dir/close-league-client-in-game.py" --detach &
elif [ "${RCLOL_HIDE_CLIENT_IN_GAME:-0}" = 1 ]; then
python3 "$runner_dir/hide-league-client-in-game.py" --detach &
fi
fi
A=${RIOT_LAUNCHER_HOST:-"$client/Contents/MacOS/RiotClientServices"}
# External XIM (for example Fcitx) consumes keys before Darling forwards them.
# Use Xlib's local input method; allow explicit testing of another modifier.
+2 -2
View File
@@ -57,7 +57,7 @@
"revision": "c8d38d16a9f613d300157bebbab2b9501bc0c274",
"repository": "https://github.com/darlinghq/darling-cocotron.git",
"patch": "patches/cocotron.patch",
"modified_files": 104,
"modified_files": 115,
"new_files": [
"QuartzCore/include/QuartzCore/CATransformLayer.h",
"AppKit/NSGeometryTrace.h"
@@ -274,7 +274,7 @@
"revision": "fa29287aa2f0115271e091f1031f53c9e024005d",
"repository": "https://github.com/darlinghq/darling-xnu.git",
"patch": "patches/xnu.patch",
"modified_files": 64,
"modified_files": 65,
"new_files": [
"darling/src/libsystem_kernel/emulation/include/common/cpu_topology.h",
"darling/src/libsystem_kernel/emulation/include/common/private_mutex.h",