@ohos-ports/playwright-browser-chromium 0.0.0-stage → 1.61.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +9 -2
- package/index.d.ts +17 -0
- package/index.js +15 -0
- package/index.mjs +15 -0
- package/install.js +47 -0
- package/ohos-shim/README.md +19 -0
- package/ohos-shim/run-chromium.sh +22 -0
- package/ohos-shim/sigsys_diag30.c +640 -0
- package/ohos-shim/sigsys_diag30.so +0 -0
- package/package.json +45 -4
- package/scripts/patch-playwright-core.js +174 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Portions Copyright (c) Microsoft Corporation.
|
|
190
|
+
Portions Copyright 2017 Google Inc.
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @playwright/browser-chromium
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This package automatically installs [Chromium](https://www.chromium.org/) browser for [Playwright](http://github.com/microsoft/playwright) library. If you want to write end-to-end tests, we recommend [@playwright/test](https://playwright.dev/docs/intro).
|
|
4
|
+
|
|
5
|
+
> **OpenHarmony (OHOS) port** (@ohos-ports): ships `ohos-shim/` (LD_PRELOAD
|
|
6
|
+
> interposer `sigsys_diag30.so` fixing seccomp SIGSYS / musl dl* crashes /
|
|
7
|
+
> HongMeng uname CHECK, plus `run-chromium.sh`) and a postinstall script that
|
|
8
|
+
> patches `playwright-core`'s platform registry for `openharmony` (with
|
|
9
|
+
> `CHROMIUM_PATH` fallback). On non-OHOS platforms it behaves exactly like
|
|
10
|
+
> upstream `@playwright/browser-chromium`.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export {};
|
package/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
package/index.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
package/install.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const path = require('path');
|
|
18
|
+
|
|
19
|
+
// OpenHarmony: playwright-core@1.61.x has no "openharmony" platform entry, so
|
|
20
|
+
// require('playwright-core/lib/coreBundle') would throw
|
|
21
|
+
// "Unsupported platform: openharmony" at module init and the browser install
|
|
22
|
+
// would be silently skipped. Apply the platform patch (openharmony -> linux
|
|
23
|
+
// registry, hostPlatform debian12-<arch>, CHROMIUM_PATH + ohos-shim launch
|
|
24
|
+
// support) before loading coreBundle. Idempotent, non-fatal.
|
|
25
|
+
try {
|
|
26
|
+
if (process.platform === 'openharmony') {
|
|
27
|
+
const { apply, ensureShimBinary } = require('./scripts/patch-playwright-core');
|
|
28
|
+
const playwrightRoot = path.dirname(
|
|
29
|
+
require.resolve('playwright-core/package.json', { paths: [__dirname] }));
|
|
30
|
+
apply({ playwrightRoot });
|
|
31
|
+
ensureShimBinary(path.join(__dirname, 'ohos-shim'));
|
|
32
|
+
}
|
|
33
|
+
} catch (e) {
|
|
34
|
+
// Non-fatal: patching must never break package installation.
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let install;
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
if (!require('playwright-core/lib/coreBundle').utils.isLikelyNpxGlobal())
|
|
41
|
+
install = require('playwright-core/lib/coreBundle').registry.installBrowsersForNpmInstall;
|
|
42
|
+
} catch (e) {
|
|
43
|
+
// Dev build, don't install browsers by default.
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (install)
|
|
47
|
+
install(['chromium', 'chromium-headless-shell', 'ffmpeg']);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# OHOS runtime shim for @playwright/browser-chromium
|
|
2
|
+
|
|
3
|
+
On OpenHarmony the (musl) Chromium binary requires this LD_PRELOAD shim to
|
|
4
|
+
run and render. Round-3 root cause of renderer crash/hang:
|
|
5
|
+
|
|
6
|
+
OHOS uname().release = "HongMeng Kernel 1.10.0"
|
|
7
|
+
Chromium SysInfo::OperatingSystemVersionNumbers:
|
|
8
|
+
CHECK(sscanf(utsbuf.release, "%d.%d", ...) == 2)
|
|
9
|
+
sscanf returns 0 -> ImmediateCrash (brk) -> renderer crash/spin loop.
|
|
10
|
+
|
|
11
|
+
sigsys_diag30.so (build: clang -shared -fPIC -O2 sigsys_diag30.c -o sigsys_diag30.so):
|
|
12
|
+
1. uname() interposer: sysname "Linux", release "5.10.0-hongmeng".
|
|
13
|
+
2. SIGSYS (seccomp RET_TRAP) emulation: eventfd2->pipe2, landlock 444/445 -> 0.
|
|
14
|
+
3. Crash-handler skip for OHOS musl dlsym/dladdr1 NULL-deref sites +
|
|
15
|
+
in-memory ld-musl dlsym trampoline patch (NULL name -> return 0).
|
|
16
|
+
4. musl/kernel sigaction layout conversion.
|
|
17
|
+
|
|
18
|
+
Usage: ./run-chromium.sh <chromium-binary> --dump-dom about:blank
|
|
19
|
+
Verified: --dump-dom exits 0 with correct DOM, 3/3 stable runs (2026-09-23).
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# HarmonyOS (OHOS) runtime shim launcher for the bundled musl Chromium.
|
|
3
|
+
# Fixes: (1) seccomp SIGSYS traps (eventfd2/landlock emulation)
|
|
4
|
+
# (2) OHOS musl dlsym/dladdr1 NULL-deref (ld-musl trampoline patch)
|
|
5
|
+
# (3) uname() spoof: "HongMeng Kernel 1.10.0" -> "Linux 5.10.0"
|
|
6
|
+
# (Chromium SysInfo CHECK(sscanf(release,"%d.%d")==2) brk-crash)
|
|
7
|
+
# Usage: run-chromium.sh <path-to-chromium> [chromium args...]
|
|
8
|
+
set -e
|
|
9
|
+
DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
10
|
+
CHROME="$1"; shift
|
|
11
|
+
SO="$DIR/sigsys_diag30.so"
|
|
12
|
+
[ -f "$SO" ] || clang -shared -fPIC -O2 -o "$SO" "$DIR/sigsys_diag30.c"
|
|
13
|
+
export LD_LIBRARY_PATH="$(dirname "$CHROME"):${LD_LIBRARY_PATH}"
|
|
14
|
+
export LD_PRELOAD="$SO"
|
|
15
|
+
if [ -z "${FONTCONFIG_FILE}" ]; then
|
|
16
|
+
if [ -f "$DIR/fonts.conf" ]; then
|
|
17
|
+
export FONTCONFIG_FILE="$DIR/fonts.conf"
|
|
18
|
+
elif [ -f "$(dirname "$CHROME")/fonts.conf" ]; then
|
|
19
|
+
export FONTCONFIG_FILE="$(dirname "$CHROME")/fonts.conf"
|
|
20
|
+
fi
|
|
21
|
+
fi
|
|
22
|
+
exec "$CHROME" --headless --no-sandbox --disable-gpu --disable-dev-shm-usage "$@"
|
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
// sigsys_diag30.c - round-3 preload v5: diag29 + syscall interposition logging
|
|
2
|
+
// - line-buffered single-write logging; log fd auto-reopen with inode check
|
|
3
|
+
// - SIGSYS emulation (eventfd2->pipe2, landlock 444/445->0, else ENOSYS)
|
|
4
|
+
// - crash dump with pc_off, fp-chain walk + stack scan (locate CHECK caller)
|
|
5
|
+
// - after 8 crash-skips: restore SIG_DFL and die (no infinite spin)
|
|
6
|
+
// - sigaction layout conversion, dladdr/dlvsym guards, ld-musl dlsym patch
|
|
7
|
+
// NOTE: do NOT export dlsym/dladdr/sysconf (BUG-2 relro assert).
|
|
8
|
+
#define _GNU_SOURCE
|
|
9
|
+
#include <string.h>
|
|
10
|
+
#include <stdlib.h>
|
|
11
|
+
#include <stdio.h>
|
|
12
|
+
#include <stdarg.h>
|
|
13
|
+
#include <unistd.h>
|
|
14
|
+
#include <signal.h>
|
|
15
|
+
#include <errno.h>
|
|
16
|
+
#include <fcntl.h>
|
|
17
|
+
#include <dlfcn.h>
|
|
18
|
+
#include <time.h>
|
|
19
|
+
#include <poll.h>
|
|
20
|
+
#include <sys/mman.h>
|
|
21
|
+
#include <sys/ucontext.h>
|
|
22
|
+
#include <sys/syscall.h>
|
|
23
|
+
#include <sys/socket.h>
|
|
24
|
+
#include <sys/epoll.h>
|
|
25
|
+
#include <sys/uio.h>
|
|
26
|
+
#include <sys/stat.h>
|
|
27
|
+
#include <netinet/in.h>
|
|
28
|
+
#include <sys/un.h>
|
|
29
|
+
|
|
30
|
+
struct mc {
|
|
31
|
+
unsigned long fault_address;
|
|
32
|
+
unsigned long regs[31];
|
|
33
|
+
unsigned long sp, pc, pstate;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
#define LOG_PATH "/storage/Users/currentUser/tmp/chromium-flat/sigsys_diag.log"
|
|
37
|
+
|
|
38
|
+
static int g_logfd = -1;
|
|
39
|
+
static dev_t g_dev; static ino_t g_ino;
|
|
40
|
+
static long g_start_ms = -1;
|
|
41
|
+
static volatile unsigned g_lines = 0;
|
|
42
|
+
#define MAX_LINES 80000
|
|
43
|
+
|
|
44
|
+
static char g_line[1200];
|
|
45
|
+
static int g_len = 0;
|
|
46
|
+
static int g_drop = 0;
|
|
47
|
+
|
|
48
|
+
static long now_ms(void)
|
|
49
|
+
{
|
|
50
|
+
struct timespec ts;
|
|
51
|
+
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
52
|
+
return (long)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static void ensure_fd(void)
|
|
56
|
+
{
|
|
57
|
+
if (g_logfd >= 0) {
|
|
58
|
+
struct stat st;
|
|
59
|
+
if (fstat(g_logfd, &st) == 0 && st.st_dev == g_dev && st.st_ino == g_ino)
|
|
60
|
+
return;
|
|
61
|
+
close(g_logfd);
|
|
62
|
+
g_logfd = -1;
|
|
63
|
+
}
|
|
64
|
+
int fd = (int)syscall(SYS_openat, AT_FDCWD, LOG_PATH,
|
|
65
|
+
O_WRONLY | O_CREAT | O_APPEND, 0644);
|
|
66
|
+
if (fd >= 0) {
|
|
67
|
+
struct stat st;
|
|
68
|
+
if (fstat(fd, &st) == 0) { g_dev = st.st_dev; g_ino = st.st_ino; }
|
|
69
|
+
g_logfd = fd;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static void lflush(void)
|
|
74
|
+
{
|
|
75
|
+
ensure_fd();
|
|
76
|
+
if (g_logfd >= 0 && g_len > 0)
|
|
77
|
+
syscall(SYS_write, g_logfd, g_line, (size_t)g_len);
|
|
78
|
+
g_len = 0;
|
|
79
|
+
}
|
|
80
|
+
static void lput(const char *s, int n)
|
|
81
|
+
{
|
|
82
|
+
if (g_len + n > (int)sizeof(g_line) - 2) { g_drop = 1; return; }
|
|
83
|
+
memcpy(g_line + g_len, s, (size_t)n);
|
|
84
|
+
g_len += n;
|
|
85
|
+
}
|
|
86
|
+
static void lstr(const char *s) { lput(s, (int)strlen(s)); }
|
|
87
|
+
static void lhex(unsigned long v)
|
|
88
|
+
{
|
|
89
|
+
char buf[18];
|
|
90
|
+
buf[0] = '0'; buf[1] = 'x';
|
|
91
|
+
for (int i = 0; i < 16; i++) {
|
|
92
|
+
int d = (v >> ((15 - i) * 4)) & 0xF;
|
|
93
|
+
buf[2 + i] = d < 10 ? '0' + d : 'a' + d - 10;
|
|
94
|
+
}
|
|
95
|
+
lput(buf, 18);
|
|
96
|
+
}
|
|
97
|
+
static void ldec(long v)
|
|
98
|
+
{
|
|
99
|
+
char buf[24]; int i = 23;
|
|
100
|
+
int neg = v < 0; if (neg) v = -v;
|
|
101
|
+
if (v == 0) buf[i--] = '0';
|
|
102
|
+
while (v) { buf[i--] = '0' + v % 10; v /= 10; }
|
|
103
|
+
if (neg) buf[i--] = '-';
|
|
104
|
+
lput(buf + i + 1, 23 - i);
|
|
105
|
+
}
|
|
106
|
+
static int lbegin(const char *tag)
|
|
107
|
+
{
|
|
108
|
+
if (g_lines++ > MAX_LINES) return 0;
|
|
109
|
+
if (g_len) lflush();
|
|
110
|
+
g_drop = 0;
|
|
111
|
+
ldec((long)getpid());
|
|
112
|
+
lstr(" [");
|
|
113
|
+
ldec(now_ms() - g_start_ms);
|
|
114
|
+
lstr("ms] ");
|
|
115
|
+
lstr(tag);
|
|
116
|
+
return 1;
|
|
117
|
+
}
|
|
118
|
+
static void lend(void) { lstr(g_drop ? " ...\n" : "\n"); lflush(); }
|
|
119
|
+
|
|
120
|
+
static void hexline(const char *tag, unsigned long a, unsigned long b, unsigned long c, unsigned long d)
|
|
121
|
+
{
|
|
122
|
+
if (!lbegin(tag)) return;
|
|
123
|
+
lhex(a); lstr(" "); lhex(b); lstr(" "); lhex(c); lstr(" "); lhex(d);
|
|
124
|
+
lend();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static unsigned long g_cnt[64];
|
|
128
|
+
static int thr(int slot)
|
|
129
|
+
{
|
|
130
|
+
g_cnt[slot]++;
|
|
131
|
+
return g_cnt[slot] <= 24 || (g_cnt[slot] % 8192) == 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* ---------- SIGSYS emulation ---------- */
|
|
135
|
+
static void sigsys_handler(int sig, siginfo_t *si, void *ctx)
|
|
136
|
+
{
|
|
137
|
+
(void)sig;
|
|
138
|
+
struct mc *m = (struct mc *)&((ucontext_t *)ctx)->uc_mcontext;
|
|
139
|
+
long nr = si->si_syscall;
|
|
140
|
+
if (lbegin("SIGSYS nr=")) {
|
|
141
|
+
ldec(nr); lstr(" code="); ldec(si->si_code); lstr(" args=");
|
|
142
|
+
lhex(m->regs[0]); lstr(","); lhex(m->regs[1]); lstr(","); lhex(m->regs[2]);
|
|
143
|
+
lend();
|
|
144
|
+
}
|
|
145
|
+
if (nr == SYS_eventfd2) {
|
|
146
|
+
int fds[2] = {-1, -1};
|
|
147
|
+
long flags = m->regs[1];
|
|
148
|
+
long pflags = 0;
|
|
149
|
+
if (flags & 02000000) pflags |= 02000000;
|
|
150
|
+
if (flags & 04000) pflags |= 04000;
|
|
151
|
+
if (pipe2(fds, (int)pflags) == 0) {
|
|
152
|
+
m->regs[0] = (unsigned long)fds[0];
|
|
153
|
+
if (lbegin(" eventfd2->pipe2 fd=")) { ldec(fds[0]); lstr(","); ldec(fds[1]); lend(); }
|
|
154
|
+
} else {
|
|
155
|
+
m->regs[0] = (unsigned long)(-errno);
|
|
156
|
+
}
|
|
157
|
+
} else if (nr == 444) {
|
|
158
|
+
m->regs[0] = 0;
|
|
159
|
+
if (lbegin(" landlock_restrict_self fake 0")) lend();
|
|
160
|
+
} else if (nr == 445) {
|
|
161
|
+
m->regs[0] = 0;
|
|
162
|
+
if (lbegin(" landlock_add_rule fake 0")) lend();
|
|
163
|
+
} else {
|
|
164
|
+
m->regs[0] = (unsigned long)(-ENOSYS);
|
|
165
|
+
if (lbegin(" -> ENOSYS")) lend();
|
|
166
|
+
}
|
|
167
|
+
m->pc += 4;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/* ---------- crash context dump + skip ---------- */
|
|
171
|
+
static __thread int g_crash_count = 0;
|
|
172
|
+
|
|
173
|
+
static void text_range(unsigned long pc, unsigned long *cs, unsigned long *ce, char *tagline, int taglen)
|
|
174
|
+
{
|
|
175
|
+
FILE *mf = fopen("/proc/self/maps", "r");
|
|
176
|
+
if (!mf) return;
|
|
177
|
+
char line[512];
|
|
178
|
+
char fallback[512] = {0};
|
|
179
|
+
unsigned long fs = 0, fe = 0;
|
|
180
|
+
*cs = 0; *ce = 0;
|
|
181
|
+
while (fgets(line, sizeof(line), mf)) {
|
|
182
|
+
unsigned long s, e, off;
|
|
183
|
+
if (sscanf(line, "%lx-%lx %*s %lx", &s, &e, &off) != 3) continue;
|
|
184
|
+
if (!strstr(line, "r-xp")) continue;
|
|
185
|
+
if (pc >= s && pc < e) {
|
|
186
|
+
if (strstr(line, "chromium-flat/chromium")) {
|
|
187
|
+
*cs = s; *ce = e;
|
|
188
|
+
if (tagline) { strncpy(tagline, line, (size_t)taglen - 1); tagline[taglen-1] = 0; }
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
if (!fs) { fs = s; fe = e; if (tagline) strncpy(fallback, line, sizeof(fallback)-1); }
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
fclose(mf);
|
|
195
|
+
if (!*cs && fs) {
|
|
196
|
+
*cs = fs; *ce = fe;
|
|
197
|
+
if (tagline && fallback[0]) { strncpy(tagline, fallback, (size_t)taglen - 1); tagline[taglen-1] = 0; }
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/* /proc/self/mem pread is blocked on OHOS; use direct dereference instead */
|
|
202
|
+
static unsigned long g_stack_lo, g_stack_hi;
|
|
203
|
+
|
|
204
|
+
static int in_stack(unsigned long a)
|
|
205
|
+
{
|
|
206
|
+
return a >= g_stack_lo && a + 8 <= g_stack_hi;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
static void find_stack_range(unsigned long sp)
|
|
210
|
+
{
|
|
211
|
+
FILE *mf = fopen("/proc/self/maps", "r");
|
|
212
|
+
if (!mf) { g_stack_lo = sp & ~0xffful; g_stack_hi = g_stack_lo + 0x80000; return; }
|
|
213
|
+
char line[512];
|
|
214
|
+
unsigned long blo = 0, bhi = 0;
|
|
215
|
+
while (fgets(line, sizeof(line), mf)) {
|
|
216
|
+
unsigned long s, e;
|
|
217
|
+
if (sscanf(line, "%lx-%lx", &s, &e) != 2) continue;
|
|
218
|
+
if (sp >= s && sp < e) { blo = s; bhi = e; break; }
|
|
219
|
+
}
|
|
220
|
+
fclose(mf);
|
|
221
|
+
if (!blo) { blo = sp & ~0xffful; bhi = blo + 0x80000; }
|
|
222
|
+
g_stack_lo = blo; g_stack_hi = bhi;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
static void scan_stack(unsigned long sp, unsigned long cs, unsigned long ce, unsigned long fp)
|
|
226
|
+
{
|
|
227
|
+
(void)cs; (void)ce;
|
|
228
|
+
if (lbegin(" stack ")) { lhex(g_stack_lo); lstr("-"); lhex(g_stack_hi); lend(); }
|
|
229
|
+
for (int i = 0; i < 24; i++) {
|
|
230
|
+
unsigned long addr = sp + (unsigned long)i * 8;
|
|
231
|
+
if (!in_stack(addr)) break;
|
|
232
|
+
unsigned long v = *(volatile unsigned long *)addr;
|
|
233
|
+
if (lbegin(" spdump +")) { ldec(i * 8); lstr(" = "); lhex(v); lend(); }
|
|
234
|
+
}
|
|
235
|
+
unsigned long f = fp;
|
|
236
|
+
int links = 0;
|
|
237
|
+
for (int i = 0; i < 40 && f && in_stack(f); i++) {
|
|
238
|
+
volatile unsigned long *pf = (volatile unsigned long *)f;
|
|
239
|
+
unsigned long nextf = pf[0];
|
|
240
|
+
unsigned long ret = pf[1];
|
|
241
|
+
links++;
|
|
242
|
+
if (lbegin(" fpchain fp=")) { lhex(f); lstr(" ret="); lhex(ret); lend(); }
|
|
243
|
+
if (nextf <= f || !in_stack(nextf)) break;
|
|
244
|
+
f = nextf;
|
|
245
|
+
}
|
|
246
|
+
if (lbegin(" fpchain links=")) { ldec(links); lend(); }
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
static void die_for_real(int sig)
|
|
250
|
+
{
|
|
251
|
+
struct dsa_t { void *handler; unsigned long flags; void *restorer; unsigned long mask; } dsa;
|
|
252
|
+
memset(&dsa, 0, sizeof(dsa));
|
|
253
|
+
syscall(SYS_rt_sigaction, sig, &dsa, 0, (size_t)8);
|
|
254
|
+
syscall(SYS_kill, (long)getpid(), (long)sig);
|
|
255
|
+
for (;;) syscall(SYS_ppoll, 0, 0, 0, 0, (size_t)0);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
static void crash_handler(int sig, siginfo_t *si, void *ctx)
|
|
259
|
+
{
|
|
260
|
+
(void)si;
|
|
261
|
+
struct mc *m = (struct mc *)&((ucontext_t *)ctx)->uc_mcontext;
|
|
262
|
+
if (g_crash_count++ < 2) {
|
|
263
|
+
unsigned long cs = 0, ce = 0;
|
|
264
|
+
char tagline[512] = {0};
|
|
265
|
+
text_range(m->pc, &cs, &ce, tagline, (int)sizeof(tagline));
|
|
266
|
+
if (lbegin("CRASH sig=")) {
|
|
267
|
+
ldec(sig);
|
|
268
|
+
lstr(" fault_addr="); lhex(m->fault_address);
|
|
269
|
+
lstr(" pc="); lhex(m->pc);
|
|
270
|
+
lstr(" pc_off="); lhex(cs ? m->pc - cs : 0);
|
|
271
|
+
lstr(" lr="); lhex(m->regs[30]);
|
|
272
|
+
lstr(" lr_off="); lhex((cs && m->regs[30] >= cs && m->regs[30] < ce) ? m->regs[30] - cs : 0);
|
|
273
|
+
lstr(" sp="); lhex(m->sp);
|
|
274
|
+
lend();
|
|
275
|
+
}
|
|
276
|
+
if (lbegin(" mapline ")) { lstr(tagline); lend(); }
|
|
277
|
+
for (int i = 0; i < 31; i += 4)
|
|
278
|
+
hexline(" x", m->regs[i], i+1<31?m->regs[i+1]:0, i+2<31?m->regs[i+2]:0, i+3<31?m->regs[i+3]:0);
|
|
279
|
+
find_stack_range(m->sp);
|
|
280
|
+
scan_stack(m->sp, cs, ce, m->regs[29]);
|
|
281
|
+
}
|
|
282
|
+
if (g_crash_count >= 8) die_for_real(sig);
|
|
283
|
+
m->pc += 4;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/* ---------- sigaction interposer with layout conversion ---------- */
|
|
287
|
+
static int protected_signal(int s)
|
|
288
|
+
{
|
|
289
|
+
return s == SIGSYS || s == SIGSEGV || s == SIGTRAP || s == SIGILL ||
|
|
290
|
+
s == SIGBUS || s == SIGFPE || s == SIGABRT;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
|
|
294
|
+
{
|
|
295
|
+
if (protected_signal(signum) && act && (act->sa_handler == SIG_DFL || act->sa_handler == 0)) {
|
|
296
|
+
if (oldact) { memset(oldact, 0, sizeof(*oldact)); oldact->sa_handler = (void *)sigsys_handler; }
|
|
297
|
+
return 0;
|
|
298
|
+
}
|
|
299
|
+
unsigned long kbuf[4], obuf[4];
|
|
300
|
+
const unsigned long *m = (const unsigned long *)act;
|
|
301
|
+
kbuf[0] = act ? m[0] : 0;
|
|
302
|
+
kbuf[1] = act ? m[3] : 0;
|
|
303
|
+
kbuf[2] = act ? m[4] : 0;
|
|
304
|
+
kbuf[3] = act ? m[1] : 0;
|
|
305
|
+
int r = (int)syscall(SYS_rt_sigaction, signum, act ? kbuf : 0, oldact ? obuf : 0, (size_t)8);
|
|
306
|
+
if (r == 0 && oldact) {
|
|
307
|
+
unsigned long *o = (unsigned long *)oldact;
|
|
308
|
+
memset(o, 0, sizeof(*oldact));
|
|
309
|
+
o[0] = obuf[0]; o[1] = obuf[3]; o[3] = obuf[1]; o[4] = obuf[2];
|
|
310
|
+
}
|
|
311
|
+
return r;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/* ---------- dladdr/dladdr1 guards ---------- */
|
|
315
|
+
typedef int (*dladdr1_fn)(const void *, Dl_info *, void **, int);
|
|
316
|
+
static dladdr1_fn g_real_dladdr1;
|
|
317
|
+
|
|
318
|
+
int dladdr(const void *addr, Dl_info *info)
|
|
319
|
+
{
|
|
320
|
+
if (!info) { if (lbegin("dladdr(NULL info) guarded")) lend(); return 0; }
|
|
321
|
+
return dladdr1(addr, info, 0, 0);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
int dladdr1(const void *addr, Dl_info *info, void **extra, int flags)
|
|
325
|
+
{
|
|
326
|
+
if (!info) { if (lbegin("dladdr1(NULL info) guarded")) lend(); return 0; }
|
|
327
|
+
if (!g_real_dladdr1) g_real_dladdr1 = (dladdr1_fn)dlsym(RTLD_NEXT, "dladdr1");
|
|
328
|
+
if (g_real_dladdr1) return g_real_dladdr1(addr, info, extra, flags);
|
|
329
|
+
return 0;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
typedef void *(*dlvsym_fn)(void *, const char *, const char *);
|
|
333
|
+
static dlvsym_fn g_real_dlvsym;
|
|
334
|
+
|
|
335
|
+
void *dlvsym(void *handle, const char *name, const char *version)
|
|
336
|
+
{
|
|
337
|
+
if (!name) { if (lbegin("dlvsym(NULL name) guarded")) lend(); return 0; }
|
|
338
|
+
if (!g_real_dlvsym) g_real_dlvsym = (dlvsym_fn)dlsym(RTLD_NEXT, "dlvsym");
|
|
339
|
+
if (g_real_dlvsym) return g_real_dlvsym(handle, name, version);
|
|
340
|
+
return 0;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/* ---------- in-memory patch of ld-musl dlsym (from diag29) ---------- */
|
|
344
|
+
static unsigned long musl_base(void)
|
|
345
|
+
{
|
|
346
|
+
FILE *mf = fopen("/proc/self/maps", "r");
|
|
347
|
+
if (!mf) return 0;
|
|
348
|
+
char line[512];
|
|
349
|
+
unsigned long base = 0;
|
|
350
|
+
while (fgets(line, sizeof(line), mf)) {
|
|
351
|
+
if (strstr(line, "ld-musl-aarch64.so.1") && strstr(line, "r-xp")) {
|
|
352
|
+
unsigned long s, e, off;
|
|
353
|
+
if (sscanf(line, "%lx-%lx %*s %lx", &s, &e, &off) == 3)
|
|
354
|
+
base = s - off - 0x1000;
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
fclose(mf);
|
|
359
|
+
return base;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
static void patch_dlsym(void)
|
|
363
|
+
{
|
|
364
|
+
unsigned long base = musl_base();
|
|
365
|
+
if (!base) { if (lbegin("patch: no base")) lend(); return; }
|
|
366
|
+
unsigned long orig_dlsym = base + 0xb6e78;
|
|
367
|
+
unsigned long orig_hash = base + 0xaea24;
|
|
368
|
+
unsigned long hints[] = { base - 0x800000, base + 0x210000 + 0x800000,
|
|
369
|
+
base - 0x2000000, base + 0x210000 + 0x2000000 };
|
|
370
|
+
unsigned long tpage = 0;
|
|
371
|
+
for (unsigned i = 0; i < sizeof(hints)/sizeof(hints[0]) && !tpage; i++) {
|
|
372
|
+
void *p = mmap((void *)hints[i], 0x1000, PROT_READ | PROT_WRITE,
|
|
373
|
+
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
|
374
|
+
if (p == MAP_FAILED) continue;
|
|
375
|
+
long d0 = (long)((unsigned long)p) - (long)orig_dlsym;
|
|
376
|
+
long d1 = (long)((unsigned long)p) - (long)orig_hash;
|
|
377
|
+
if (d0 > 120*1024*1024 || d0 < -120*1024*1024 ||
|
|
378
|
+
d1 > 120*1024*1024 || d1 < -120*1024*1024) { munmap(p, 0x1000); continue; }
|
|
379
|
+
tpage = (unsigned long)p;
|
|
380
|
+
}
|
|
381
|
+
if (!tpage) { if (lbegin("patch: no tpage")) lend(); return; }
|
|
382
|
+
|
|
383
|
+
long jmp_shared = (long)(base + 0xaaac0) - (long)(tpage + 8);
|
|
384
|
+
unsigned int enc_shared = 0x14000000u | ((unsigned long)(jmp_shared >> 2) & 0x03FFFFFFu);
|
|
385
|
+
unsigned int t0[5] = {
|
|
386
|
+
0xb4000061u, 0xaa1e03e2u, enc_shared, 0xaa1f03e0u, 0xd65f03c0u
|
|
387
|
+
};
|
|
388
|
+
long back = (long)(orig_hash + 4) - (long)(tpage + 32 + 20);
|
|
389
|
+
unsigned int enc_back = 0x14000000u | ((unsigned long)(back >> 2) & 0x03FFFFFFu);
|
|
390
|
+
unsigned int t1[9] = {
|
|
391
|
+
0xf9400028u, 0xb5000068u, 0xaa1303e0u, 0x14000003u,
|
|
392
|
+
0xd503237fu, enc_back, 0xd503201fu, 0xaa1f03e0u, 0xd65f03c0u
|
|
393
|
+
};
|
|
394
|
+
unsigned int *tp = (unsigned int *)tpage;
|
|
395
|
+
for (int i = 0; i < 5; i++) tp[i] = t0[i];
|
|
396
|
+
for (int i = 0; i < 9; i++) tp[8 + i] = t1[i];
|
|
397
|
+
if (mprotect((void *)tpage, 0x1000, PROT_READ | PROT_EXEC) != 0) {
|
|
398
|
+
if (lbegin("patch: mprotect failed")) lend(); return;
|
|
399
|
+
}
|
|
400
|
+
__builtin___clear_cache((char *)tpage, (char *)tpage + 0x1000);
|
|
401
|
+
|
|
402
|
+
long f0 = (long)(tpage) - (long)orig_dlsym;
|
|
403
|
+
unsigned int e0 = 0x14000000u | ((unsigned long)(f0 >> 2) & 0x03FFFFFFu);
|
|
404
|
+
long f1 = (long)(tpage + 32) - (long)orig_hash;
|
|
405
|
+
unsigned int e1 = 0x14000000u | ((unsigned long)(f1 >> 2) & 0x03FFFFFFu);
|
|
406
|
+
|
|
407
|
+
int fd = (int)syscall(SYS_openat, AT_FDCWD, "/proc/self/mem", O_RDWR, 0);
|
|
408
|
+
if (fd < 0) { if (lbegin("patch: open mem failed")) lend(); return; }
|
|
409
|
+
ssize_t n1 = pwrite(fd, &e0, 4, (off_t)orig_dlsym);
|
|
410
|
+
ssize_t n2 = pwrite(fd, &e1, 4, (off_t)orig_hash);
|
|
411
|
+
close(fd);
|
|
412
|
+
__builtin___clear_cache((char *)orig_dlsym, (char *)orig_dlsym + 4);
|
|
413
|
+
__builtin___clear_cache((char *)orig_hash, (char *)orig_hash + 4);
|
|
414
|
+
if (lbegin("patched dlsym->T0 n=")) {
|
|
415
|
+
ldec((long)n1); lstr(" hash->T1 n="); ldec((long)n2);
|
|
416
|
+
lstr(" tpage="); lhex(tpage);
|
|
417
|
+
lend();
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/* ============ syscall interposition logging ============ */
|
|
422
|
+
|
|
423
|
+
static void log_fd_pair(const char *tag, int r0, int r1)
|
|
424
|
+
{
|
|
425
|
+
if (!lbegin(tag)) return;
|
|
426
|
+
ldec(r0); lstr(","); ldec(r1);
|
|
427
|
+
lend();
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
int poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
|
431
|
+
{
|
|
432
|
+
if (thr(0) && lbegin("poll n=")) {
|
|
433
|
+
ldec((long)nfds); lstr(" to="); ldec(timeout);
|
|
434
|
+
for (nfds_t i = 0; i < nfds && i < 4; i++) {
|
|
435
|
+
lstr(" fd"); ldec(fds[i].fd); lstr("/e"); ldec(fds[i].events);
|
|
436
|
+
}
|
|
437
|
+
lend();
|
|
438
|
+
}
|
|
439
|
+
int r;
|
|
440
|
+
if (timeout < 0) {
|
|
441
|
+
r = (int)syscall(SYS_ppoll, fds, nfds, NULL, 0, (size_t)0);
|
|
442
|
+
} else {
|
|
443
|
+
struct timespec ts = { timeout / 1000, (timeout % 1000) * 1000000L };
|
|
444
|
+
r = (int)syscall(SYS_ppoll, fds, nfds, &ts, 0, (size_t)0);
|
|
445
|
+
}
|
|
446
|
+
if (r == 0 && (timeout < 0 || timeout > 200) && thr(0)) {
|
|
447
|
+
if (lbegin("poll TIMEOUT n=")) {
|
|
448
|
+
ldec((long)nfds);
|
|
449
|
+
for (nfds_t i = 0; i < nfds && i < 4; i++) {
|
|
450
|
+
lstr(" fd"); ldec(fds[i].fd); lstr("/r"); ldec(fds[i].revents);
|
|
451
|
+
}
|
|
452
|
+
lend();
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return r;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *to, const sigset_t *sm)
|
|
459
|
+
{
|
|
460
|
+
if (thr(1) && lbegin("ppoll n=")) {
|
|
461
|
+
ldec((long)nfds); lstr(" to="); ldec(to ? (long)to->tv_sec : -99);
|
|
462
|
+
lend();
|
|
463
|
+
}
|
|
464
|
+
return (int)syscall(SYS_ppoll, fds, nfds, to, sm, (size_t)8);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
int epoll_wait(int epfd, struct epoll_event *ev, int maxev, int timeout)
|
|
468
|
+
{
|
|
469
|
+
if (thr(2) && lbegin("epoll_wait fd=")) {
|
|
470
|
+
ldec(epfd); lstr(" max="); ldec(maxev); lstr(" to="); ldec(timeout);
|
|
471
|
+
lend();
|
|
472
|
+
}
|
|
473
|
+
int r = (int)syscall(SYS_epoll_pwait, epfd, ev, maxev, timeout, 0, (size_t)8);
|
|
474
|
+
if (r == 0 && timeout < 0 && thr(2)) {
|
|
475
|
+
if (lbegin("epoll_wait TIMEOUT fd=")) { ldec(epfd); lend(); }
|
|
476
|
+
}
|
|
477
|
+
return r;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
int connect(int fd, const struct sockaddr *addr, socklen_t len)
|
|
481
|
+
{
|
|
482
|
+
if (thr(3) && lbegin("connect fd=")) {
|
|
483
|
+
ldec(fd); lstr(" fam="); ldec(addr ? (long)addr->sa_family : -1);
|
|
484
|
+
if (addr && addr->sa_family == AF_UNIX && len > 3) {
|
|
485
|
+
const char *p = ((const struct sockaddr_un *)addr)->sun_path;
|
|
486
|
+
lstr(" path="); lstr(p && p[0] ? p : "<abstract>");
|
|
487
|
+
} else if (addr && addr->sa_family == AF_INET && len >= 8) {
|
|
488
|
+
unsigned char *b = (unsigned char *)&((struct sockaddr_in *)addr)->sin_addr;
|
|
489
|
+
lstr(" ip="); ldec(b[0]); lstr("."); ldec(b[1]); lstr("."); ldec(b[2]); lstr("."); ldec(b[3]);
|
|
490
|
+
}
|
|
491
|
+
lend();
|
|
492
|
+
}
|
|
493
|
+
return (int)syscall(SYS_connect, fd, addr, len);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
int socketpair(int d, int type, int proto, int sv[2])
|
|
497
|
+
{
|
|
498
|
+
int r = (int)syscall(SYS_socketpair, d, type, proto, sv);
|
|
499
|
+
if (r == 0 && thr(4)) log_fd_pair("socketpair ->", sv[0], sv[1]);
|
|
500
|
+
return r;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
int pipe2(int fds[2], int flags)
|
|
504
|
+
{
|
|
505
|
+
int r = (int)syscall(SYS_pipe2, fds, flags);
|
|
506
|
+
if (r == 0 && thr(5)) log_fd_pair("pipe2 ->", fds[0], fds[1]);
|
|
507
|
+
return r;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
ssize_t read(int fd, void *buf, size_t n)
|
|
511
|
+
{
|
|
512
|
+
ssize_t r = (ssize_t)syscall(SYS_read, fd, buf, n);
|
|
513
|
+
if (thr(6) && lbegin("read fd=")) { ldec(fd); lstr(" n="); ldec((long)n); lstr(" -> "); ldec(r); lend(); }
|
|
514
|
+
return r;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
ssize_t write(int fd, const void *buf, size_t n)
|
|
518
|
+
{
|
|
519
|
+
ssize_t r = (ssize_t)syscall(SYS_write, fd, buf, n);
|
|
520
|
+
if (thr(7) && lbegin("write fd=")) { ldec(fd); lstr(" n="); ldec((long)n); lstr(" -> "); ldec(r); lend(); }
|
|
521
|
+
return r;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
ssize_t writev(int fd, const struct iovec *iov, int cnt)
|
|
525
|
+
{
|
|
526
|
+
ssize_t r = (ssize_t)syscall(SYS_writev, fd, iov, cnt);
|
|
527
|
+
if (thr(8) && lbegin("writev fd=")) { ldec(fd); lstr(" c="); ldec(cnt); lstr(" -> "); ldec(r); lend(); }
|
|
528
|
+
return r;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
ssize_t recvfrom(int fd, void *buf, size_t n, int fl, struct sockaddr *a, socklen_t *al)
|
|
532
|
+
{
|
|
533
|
+
ssize_t r = (ssize_t)syscall(SYS_recvfrom, fd, buf, n, fl, a, al);
|
|
534
|
+
if (thr(9) && lbegin("recv fd=")) { ldec(fd); lstr(" -> "); ldec(r); lend(); }
|
|
535
|
+
return r;
|
|
536
|
+
}
|
|
537
|
+
ssize_t sendto(int fd, const void *buf, size_t n, int fl, const struct sockaddr *a, socklen_t al)
|
|
538
|
+
{
|
|
539
|
+
ssize_t r = (ssize_t)syscall(SYS_sendto, fd, buf, n, fl, a, al);
|
|
540
|
+
if (thr(10) && lbegin("send fd=")) { ldec(fd); lstr(" n="); ldec((long)n); lstr(" -> "); ldec(r); lend(); }
|
|
541
|
+
return r;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
static int interesting_path(const char *p)
|
|
545
|
+
{
|
|
546
|
+
return p && (strstr(p, "/dev/shm") || strstr(p, "fonts.conf") ||
|
|
547
|
+
strstr(p, "memfd") || strstr(p, "fontconfig"));
|
|
548
|
+
}
|
|
549
|
+
int open(const char *path, int flags, ...)
|
|
550
|
+
{
|
|
551
|
+
mode_t mode = 0;
|
|
552
|
+
if (flags & O_CREAT) { va_list ap; va_start(ap, flags); mode = va_arg(ap, int); va_end(ap); }
|
|
553
|
+
int r = (int)syscall(SYS_openat, AT_FDCWD, path, flags, mode);
|
|
554
|
+
if (interesting_path(path) && thr(11) && lbegin("open ")) {
|
|
555
|
+
lstr(path); lstr(" -> "); ldec(r); lend();
|
|
556
|
+
}
|
|
557
|
+
return r;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
int nanosleep(const struct timespec *req, struct timespec *rem)
|
|
561
|
+
{
|
|
562
|
+
if (thr(12) && lbegin("nanosleep s=")) { ldec(req ? (long)req->tv_sec : -1); lend(); }
|
|
563
|
+
return (int)syscall(SYS_clock_nanosleep, CLOCK_REALTIME, 0, req, rem);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
static int (*g_pj)(unsigned long, void **);
|
|
567
|
+
int pthread_join(unsigned long t, void **res)
|
|
568
|
+
{
|
|
569
|
+
if (thr(13) && lbegin("pthread_join t=")) { lhex(t); lend(); }
|
|
570
|
+
if (!g_pj) g_pj = (int (*)(unsigned long, void **))dlsym(RTLD_NEXT, "pthread_join");
|
|
571
|
+
if (g_pj) return g_pj(t, res);
|
|
572
|
+
return -1;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
int sched_yield(void)
|
|
576
|
+
{
|
|
577
|
+
if (thr(14) && lbegin("sched_yield")) lend();
|
|
578
|
+
return (int)syscall(SYS_sched_yield);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/* ---------- uname interposer (ROOT CAUSE FIX) ----------
|
|
582
|
+
OHOS uname().release = "HongMeng Kernel 1.10.0"; Chromium's
|
|
583
|
+
SysInfo::OperatingSystemVersionNumbers does CHECK(sscanf(release,"%d.%d")==2)
|
|
584
|
+
-> brk/ImmediateCrash in renderer. Return Linux-compatible values instead. */
|
|
585
|
+
struct utsname_ohos {
|
|
586
|
+
char sysname[65]; char nodename[65]; char release[65];
|
|
587
|
+
char version[65]; char machine[65]; char domainname[65];
|
|
588
|
+
};
|
|
589
|
+
static int (*g_real_uname)(struct utsname_ohos *);
|
|
590
|
+
int uname(struct utsname_ohos *u)
|
|
591
|
+
{
|
|
592
|
+
if (!g_real_uname) g_real_uname = (int (*)(struct utsname_ohos *))dlsym(RTLD_NEXT, "uname");
|
|
593
|
+
if (!g_real_uname) return -1;
|
|
594
|
+
int r = g_real_uname(u);
|
|
595
|
+
if (r == 0 && u) {
|
|
596
|
+
if (thr(15) && lbegin("uname orig sysname=")) {
|
|
597
|
+
lstr(u->sysname); lstr(" release="); lstr(u->release);
|
|
598
|
+
lstr(" -> spoofed Linux/5.10.0"); lend();
|
|
599
|
+
}
|
|
600
|
+
strncpy(u->sysname, "Linux", sizeof(u->sysname) - 1);
|
|
601
|
+
strncpy(u->release, "5.10.0-hongmeng", sizeof(u->release) - 1);
|
|
602
|
+
}
|
|
603
|
+
return r;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/* ---------- init ---------- */
|
|
607
|
+
__attribute__((constructor))
|
|
608
|
+
static void init(void)
|
|
609
|
+
{
|
|
610
|
+
if (g_start_ms < 0) g_start_ms = now_ms();
|
|
611
|
+
ensure_fd();
|
|
612
|
+
{
|
|
613
|
+
char cmdbuf[200] = {0};
|
|
614
|
+
int fd = (int)syscall(SYS_openat, AT_FDCWD, "/proc/self/cmdline", O_RDONLY, 0);
|
|
615
|
+
if (fd >= 0) {
|
|
616
|
+
ssize_t n = (ssize_t)syscall(SYS_read, fd, cmdbuf, sizeof(cmdbuf) - 1);
|
|
617
|
+
close(fd);
|
|
618
|
+
for (ssize_t i = 0; i < n - 1; i++) if (cmdbuf[i] == 0) cmdbuf[i] = ' ';
|
|
619
|
+
if (lbegin("INIT diag30 cmdline: ")) { lstr(cmdbuf); lend(); }
|
|
620
|
+
}
|
|
621
|
+
if (lbegin("sigsys_diag30 v5 installed")) lend();
|
|
622
|
+
}
|
|
623
|
+
struct k_sigaction {
|
|
624
|
+
void *handler;
|
|
625
|
+
unsigned long flags;
|
|
626
|
+
void *restorer;
|
|
627
|
+
unsigned long mask;
|
|
628
|
+
} ksa;
|
|
629
|
+
memset(&ksa, 0, sizeof(ksa));
|
|
630
|
+
ksa.handler = (void *)sigsys_handler;
|
|
631
|
+
ksa.flags = (unsigned long)(SA_SIGINFO | SA_NODEFER);
|
|
632
|
+
syscall(SYS_rt_sigaction, SIGSYS, &ksa, 0, (size_t)8);
|
|
633
|
+
|
|
634
|
+
ksa.handler = (void *)crash_handler;
|
|
635
|
+
int cs[] = {SIGSEGV, SIGTRAP, SIGILL, SIGBUS, SIGFPE};
|
|
636
|
+
for (unsigned i = 0; i < sizeof(cs)/sizeof(cs[0]); i++)
|
|
637
|
+
syscall(SYS_rt_sigaction, cs[i], &ksa, 0, (size_t)8);
|
|
638
|
+
|
|
639
|
+
patch_dlsym();
|
|
640
|
+
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-ports/playwright-browser-chromium",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.61.1-beta.1",
|
|
4
|
+
"description": "Playwright package that automatically installs Chromium - OpenHarmony (OHOS) port with musl Chromium shim (sigsys_diag30.so) and playwright-core openharmony platform patch (postinstall mechanism)",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
8
|
+
"directory": "ports/playwright-browser-chromium/1.61.1"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://playwright.dev",
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=18"
|
|
13
|
+
},
|
|
14
|
+
"author": {
|
|
15
|
+
"name": "Microsoft Corporation"
|
|
16
|
+
},
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./index.d.ts",
|
|
21
|
+
"import": "./index.mjs",
|
|
22
|
+
"require": "./index.js",
|
|
23
|
+
"default": "./index.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"install": "node install.js"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"playwright-core": "1.61.1"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/ohos-ports/ohos-ports/issues"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"index.js",
|
|
38
|
+
"index.mjs",
|
|
39
|
+
"index.d.ts",
|
|
40
|
+
"install.js",
|
|
41
|
+
"scripts/",
|
|
42
|
+
"ohos-shim/",
|
|
43
|
+
"LICENSE",
|
|
44
|
+
"NOTICE",
|
|
45
|
+
"README.md"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenHarmony platform patch for playwright-core (idempotent, anchor based).
|
|
3
|
+
*
|
|
4
|
+
* playwright-core@1.61.x-1.63.x have no "openharmony" entry in their platform
|
|
5
|
+
* registry:
|
|
6
|
+
* - utils/hostPlatform.ts calculatePlatform() returns hostPlatform "<unknown>"
|
|
7
|
+
* - cache-directory helpers throw `Unsupported platform: openharmony` at module
|
|
8
|
+
* init (lib/coreBundle.js defaultCacheDirectory etc.), which breaks both
|
|
9
|
+
* @playwright/browser-chromium install.js and browserType.launch().
|
|
10
|
+
*
|
|
11
|
+
* This patch (v1):
|
|
12
|
+
* 1. treats process.platform === "openharmony" like "linux" in all platform checks
|
|
13
|
+
* 2. maps hostPlatform for openharmony to "debian12-<arch>" (-> shortPlatform
|
|
14
|
+
* "linux-arm64", whose chromium builds are the ones usable via the ohos-shim)
|
|
15
|
+
* 3. honours CHROMIUM_PATH as a default executablePath on openharmony
|
|
16
|
+
* 4. injects the ohos-shim LD_PRELOAD/LD_LIBRARY_PATH env into launched browsers
|
|
17
|
+
*
|
|
18
|
+
* Anchors are written as regexes covering both the 1.61 bundle layout
|
|
19
|
+
* (executablePath destructure in _prepareToLaunch) and the 1.63 layout
|
|
20
|
+
* (resolveExecutablePath).
|
|
21
|
+
*
|
|
22
|
+
* Idempotent: a `__ohosPlatformPatch__` marker prevents double application.
|
|
23
|
+
*/
|
|
24
|
+
'use strict';
|
|
25
|
+
|
|
26
|
+
const fs = require('fs');
|
|
27
|
+
const path = require('path');
|
|
28
|
+
|
|
29
|
+
const MARKER = '/* __ohosPlatformPatch__ v1 */';
|
|
30
|
+
|
|
31
|
+
const HELPERS = `
|
|
32
|
+
// __ohosPlatformPatch__ v1: OHOS shim env injection helpers
|
|
33
|
+
function ohosShimAssets(executable) {
|
|
34
|
+
if (process.platform !== "openharmony")
|
|
35
|
+
return null;
|
|
36
|
+
const pathMod = require("path");
|
|
37
|
+
const fsMod = require("fs");
|
|
38
|
+
const candidates = [
|
|
39
|
+
process.env.OHOS_CHROMIUM_SHIM_DIR,
|
|
40
|
+
pathMod.join(__dirname, "..", "..", "@playwright", "browser-chromium", "ohos-shim")
|
|
41
|
+
];
|
|
42
|
+
if (executable)
|
|
43
|
+
candidates.push(pathMod.dirname(executable));
|
|
44
|
+
for (const dir of candidates.filter(Boolean)) {
|
|
45
|
+
const so = pathMod.join(dir, "sigsys_diag30.so");
|
|
46
|
+
try {
|
|
47
|
+
if (fsMod.existsSync(so))
|
|
48
|
+
return { dir, so };
|
|
49
|
+
} catch (e) {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function amendOhosShimEnv(env, executable) {
|
|
55
|
+
const assets = ohosShimAssets(executable);
|
|
56
|
+
if (!assets)
|
|
57
|
+
return;
|
|
58
|
+
const pathMod = require("path");
|
|
59
|
+
const fsMod = require("fs");
|
|
60
|
+
if (!env.LD_PRELOAD)
|
|
61
|
+
env.LD_PRELOAD = assets.so;
|
|
62
|
+
if (!env.LD_LIBRARY_PATH) {
|
|
63
|
+
const exeDir = executable ? pathMod.dirname(executable) : null;
|
|
64
|
+
if (exeDir)
|
|
65
|
+
env.LD_LIBRARY_PATH = exeDir;
|
|
66
|
+
}
|
|
67
|
+
let fontConf = pathMod.join(assets.dir, "fonts.conf");
|
|
68
|
+
if (!fsMod.existsSync(fontConf) && executable)
|
|
69
|
+
fontConf = pathMod.join(pathMod.dirname(executable), "fonts.conf");
|
|
70
|
+
if (!env.FONTCONFIG_FILE && fsMod.existsSync(fontConf))
|
|
71
|
+
env.FONTCONFIG_FILE = fontConf;
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
const TARGET_FILES = [
|
|
76
|
+
'lib/coreBundle.js',
|
|
77
|
+
'lib/serverRegistry.js',
|
|
78
|
+
'lib/utilsBundle.js',
|
|
79
|
+
'lib/tools/cli-client/registry.js'
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
function apply({ playwrightRoot, log = console.log } = {}) {
|
|
83
|
+
if (!playwrightRoot)
|
|
84
|
+
throw new Error('patch-playwright-core: playwrightRoot is required');
|
|
85
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(playwrightRoot, 'package.json'), 'utf8'));
|
|
86
|
+
log(`ohos-patch: patching playwright-core@${pkg.version} at ${playwrightRoot}`);
|
|
87
|
+
const changed = [];
|
|
88
|
+
for (const rel of TARGET_FILES) {
|
|
89
|
+
const file = path.join(playwrightRoot, rel);
|
|
90
|
+
if (!fs.existsSync(file))
|
|
91
|
+
continue;
|
|
92
|
+
let src = fs.readFileSync(file, 'utf8');
|
|
93
|
+
if (src.includes('__ohosPlatformPatch__')) {
|
|
94
|
+
log(`ohos-patch: ${rel} already patched, skipping`);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 1) Generic: treat "openharmony" like "linux" everywhere (cache dirs, spawn
|
|
99
|
+
// behaviour, daemon dirs, cli registry, ...).
|
|
100
|
+
src = src.split('process.platform === "linux"')
|
|
101
|
+
.join('(process.platform === "linux" || process.platform === "openharmony")');
|
|
102
|
+
|
|
103
|
+
if (rel === 'lib/coreBundle.js') {
|
|
104
|
+
// 2) hostPlatform detection: openharmony -> debian12-<arch>
|
|
105
|
+
// (shortPlatform resolves to linux-arm64, whose chromium builds run
|
|
106
|
+
// on HarmonyOS through the ohos-shim). First occurrence = hostPlatform.ts.
|
|
107
|
+
const hostRe = /\n const platform = (import_os(\d+)\.default\.platform\(\));\n if \(platform === "darwin"\) \{/;
|
|
108
|
+
if (!hostRe.test(src))
|
|
109
|
+
throw new Error(`patch-playwright-core: hostPlatform anchor not found in ${rel} (unexpected playwright-core build)`);
|
|
110
|
+
src = src.replace(hostRe,
|
|
111
|
+
'\n const platform = $1;\n' +
|
|
112
|
+
' if (platform === "openharmony")\n' +
|
|
113
|
+
' return { hostPlatform: "debian12-" + import_os$2.default.arch(), isOfficiallySupportedPlatform: false };\n' +
|
|
114
|
+
' if (platform === "darwin") {');
|
|
115
|
+
|
|
116
|
+
// 3) CHROMIUM_PATH as default executablePath on openharmony.
|
|
117
|
+
// Variant A (1.61.x): executablePath destructure in _prepareToLaunch.
|
|
118
|
+
const prepA = /(const \{\n(\s+)ignoreDefaultArgs,\n\s+ignoreAllDefaultArgs,\n\s+args = \[\],\n\s+)executablePath = null(\n\s+\} = options;)/;
|
|
119
|
+
// Variant B (1.63.x): resolveExecutablePath in _prepareToLaunch.
|
|
120
|
+
const prepB = /(let executable;\n(\s+))const customExecutablePath = await this\.resolveExecutablePath\(options\);/;
|
|
121
|
+
if (prepA.test(src)) {
|
|
122
|
+
src = src.replace(prepA,
|
|
123
|
+
'$1executablePath: optionExecutablePath = null$3\n' +
|
|
124
|
+
'$2let executablePath = optionExecutablePath;\n' +
|
|
125
|
+
'$2if (!executablePath && process.platform === "openharmony" && process.env.CHROMIUM_PATH)\n' +
|
|
126
|
+
'$2 executablePath = process.env.CHROMIUM_PATH;');
|
|
127
|
+
} else if (prepB.test(src)) {
|
|
128
|
+
src = src.replace(prepB,
|
|
129
|
+
'$1let customExecutablePath = await this.resolveExecutablePath(options);\n' +
|
|
130
|
+
'$2if (!customExecutablePath && process.platform === "openharmony" && process.env.CHROMIUM_PATH)\n' +
|
|
131
|
+
'$2 customExecutablePath = process.env.CHROMIUM_PATH;');
|
|
132
|
+
} else {
|
|
133
|
+
throw new Error(`patch-playwright-core: _prepareToLaunch anchor not found in ${rel} (unexpected playwright-core build)`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 4) Inject ohos-shim env (LD_PRELOAD=sigsys_diag30.so, ...) into the
|
|
137
|
+
// browser process environment for every launched chromium.
|
|
138
|
+
const envRe = /(const env = options\.env \? envArrayToObject\(options\.env\) : process\.env;\n(\s+))const prepared = await progress2\.race\(this\._prepareToLaunch\(options, isPersistent, userDataDir\)\);/;
|
|
139
|
+
if (!envRe.test(src))
|
|
140
|
+
throw new Error(`patch-playwright-core: _launchProcess env anchor not found in ${rel}`);
|
|
141
|
+
src = src.replace(envRe,
|
|
142
|
+
'$1amendOhosShimEnv(env, options.executablePath || process.env.CHROMIUM_PATH || null);\n' +
|
|
143
|
+
'$2const prepared = await progress2.race(this._prepareToLaunch(options, isPersistent, userDataDir));');
|
|
144
|
+
|
|
145
|
+
// 5) Helper functions (module scope of the bundle).
|
|
146
|
+
src = src.replace(/\n*$/, '\n') + HELPERS;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
src += '\n' + MARKER + '\n';
|
|
150
|
+
fs.writeFileSync(file, src);
|
|
151
|
+
changed.push(rel);
|
|
152
|
+
log(`ohos-patch: patched ${rel}`);
|
|
153
|
+
}
|
|
154
|
+
return changed;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function ensureShimBinary(shimDir, log = console.log) {
|
|
158
|
+
const so = path.join(shimDir, 'sigsys_diag30.so');
|
|
159
|
+
const c = path.join(shimDir, 'sigsys_diag30.c');
|
|
160
|
+
if (fs.existsSync(so))
|
|
161
|
+
return so;
|
|
162
|
+
if (!fs.existsSync(c))
|
|
163
|
+
return null;
|
|
164
|
+
const { spawnSync } = require('child_process');
|
|
165
|
+
const res = spawnSync('clang', ['-shared', '-fPIC', '-O2', '-o', so, c], { stdio: 'ignore' });
|
|
166
|
+
if (res.status === 0 && fs.existsSync(so)) {
|
|
167
|
+
log('ohos-patch: built sigsys_diag30.so from source');
|
|
168
|
+
return so;
|
|
169
|
+
}
|
|
170
|
+
log('ohos-patch: WARNING could not build sigsys_diag30.so (clang unavailable)');
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
module.exports = { apply, ensureShimBinary, TARGET_FILES };
|