Repository navigation
Expand file tree
/
Copy pathwk-winuwp.patch
More file actions
2076 lines (1906 loc) · 88 KB
/
Copy pathwk-winuwp.patch
File metadata and controls
2076 lines (1906 loc) · 88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index 614318abbd..71b1de91a8 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -19,7 +19,8 @@ endif ()
add_subdirectory(JavaScriptCore)
-if (ENABLE_WEBGL OR USE_ANGLE_EGL)
+if ((ENABLE_WEBGL OR USE_ANGLE_EGL) AND NOT APOTHEOSIS_GPU)
+ # APOTHEOSIS_GPU:复用预编译 NuGet ANGLE(ANGLE::GLES/EGL 在 OptionsWinUWP 做成 IMPORTED),不编 in-tree ANGLE
add_subdirectory(ThirdParty/ANGLE)
endif ()
diff --git a/Source/JavaScriptCore/CMakeLists.txt b/Source/JavaScriptCore/CMakeLists.txt
index a2a6d72460..ea9ea17802 100644
--- a/Source/JavaScriptCore/CMakeLists.txt
+++ b/Source/JavaScriptCore/CMakeLists.txt
@@ -412,8 +412,10 @@ set(LLIntSettingsExtractor_DEPENDENCIES
JavaScriptCore_CopyHeaders
JavaScriptCore_CopyPrivateHeaders
WTF_CopyHeaders
- bmalloc_CopyHeaders
)
+if (NOT USE_SYSTEM_MALLOC)
+ list(APPEND LLIntSettingsExtractor_DEPENDENCIES bmalloc_CopyHeaders)
+endif ()
WEBKIT_EXECUTABLE(LLIntSettingsExtractor)
# LLIntSettingsExtractor target needs to have a direct or indirect
@@ -439,8 +441,10 @@ set(LLIntOffsetsExtractor_DEPENDENCIES
JavaScriptCore_CopyHeaders
JavaScriptCore_CopyPrivateHeaders
WTF_CopyHeaders
- bmalloc_CopyHeaders
)
+if (NOT USE_SYSTEM_MALLOC)
+ list(APPEND LLIntOffsetsExtractor_DEPENDENCIES bmalloc_CopyHeaders)
+endif ()
WEBKIT_EXECUTABLE(LLIntOffsetsExtractor)
# The build system will execute asm.rb every time LLIntOffsetsExtractor's mtime is newer than
diff --git a/Source/JavaScriptCore/assembler/ARMv7Assembler.h b/Source/JavaScriptCore/assembler/ARMv7Assembler.h
index 2695af3ec3..1484b1b0d5 100644
--- a/Source/JavaScriptCore/assembler/ARMv7Assembler.h
+++ b/Source/JavaScriptCore/assembler/ARMv7Assembler.h
@@ -2886,6 +2886,9 @@ public:
linuxPageFlush(current, current + page);
linuxPageFlush(current, end);
+#elif OS(WINDOWS)
+ // Windows(含 UWP App Container):写入 JIT 代码后刷新指令缓存,确保 CPU 看到新指令。
+ FlushInstructionCache(GetCurrentProcess(), code, size);
#else
#error "The cacheFlush support is missing on this platform."
#endif
diff --git a/Source/JavaScriptCore/assembler/AbstractMacroAssembler.h b/Source/JavaScriptCore/assembler/AbstractMacroAssembler.h
index 0911bd48c7..1c40610f65 100644
--- a/Source/JavaScriptCore/assembler/AbstractMacroAssembler.h
+++ b/Source/JavaScriptCore/assembler/AbstractMacroAssembler.h
@@ -305,7 +305,9 @@ public:
{
}
-#if OS(WINDOWS)
+#if OS(WINDOWS) && CPU(X86_64)
+ // 仅 x86_64:SYSV_ABI 是与默认不同的调用约定,这是个独立重载。ARM 上 SYSV_ABI 为空,
+ // 此签名与上面的 TrustedImmPtr(ReturnType(*)(Arguments...)) 完全相同 → 构造函数撞重。
template<typename ReturnType, typename... Arguments>
explicit TrustedImmPtr(ReturnType(SYSV_ABI *value)(Arguments...))
: m_value(reinterpret_cast<void*>(value))
diff --git a/Source/JavaScriptCore/assembler/MacroAssemblerARMv7.cpp b/Source/JavaScriptCore/assembler/MacroAssemblerARMv7.cpp
index 5726fd1968..9044961c69 100644
--- a/Source/JavaScriptCore/assembler/MacroAssemblerARMv7.cpp
+++ b/Source/JavaScriptCore/assembler/MacroAssemblerARMv7.cpp
@@ -366,7 +366,11 @@ __asm__(
// Restore the sp and pc.
"ldr sp, [sp, #" STRINGIZE_VALUE_OF(PROBE_CPU_SP_OFFSET) "]" "\n"
"pop { pc }" "\n"
+#if !OS(WINDOWS)
+ // .previous(返回上一 section)是 GNU-as 指令,clang 的 COFF 汇编器不支持;
+ // 此独立 asm 块无需恢复 section,Windows 下省略即可。
".previous" "\n"
+#endif
);
void MacroAssembler::probe(Probe::Function function, void* arg)
diff --git a/Source/JavaScriptCore/inspector/scripts/codegen/preprocess.pl b/Source/JavaScriptCore/inspector/scripts/codegen/preprocess.pl
index d8c6022644..e46f4a992c 100644
--- a/Source/JavaScriptCore/inspector/scripts/codegen/preprocess.pl
+++ b/Source/JavaScriptCore/inspector/scripts/codegen/preprocess.pl
@@ -39,7 +39,7 @@ GetOptions('input=s' => \$inputPath,
my @args = ();
if (!$preprocessor) {
- if ($Config::Config{"osname"} eq "MSWin32") {
+ if ($Config::Config{"osname"} eq "MSWin32" or $Config::Config{"osname"} eq "msys") {
$preprocessor = $ENV{CC} || "cl";
push(@args, qw(/nologo /EP /TP /C));
} else {
@@ -85,7 +85,7 @@ if ($Config{osname} eq "cygwin") {
sleep 1;
}
}
-} elsif ($Config::Config{"osname"} eq "MSWin32") {
+} elsif ($Config::Config{"osname"} eq "MSWin32" or $Config::Config{"osname"} eq "msys") {
# Suppress STDERR so that if we're using cl.exe, the output
# name isn't needlessly echoed.
use Symbol 'gensym'; my $err = gensym;
diff --git a/Source/JavaScriptCore/offlineasm/arm.rb b/Source/JavaScriptCore/offlineasm/arm.rb
index adc2cba6aa..bf65485b64 100644
--- a/Source/JavaScriptCore/offlineasm/arm.rb
+++ b/Source/JavaScriptCore/offlineasm/arm.rb
@@ -980,6 +980,12 @@ class Instruction
$asm.puts "add #{dest.armOperand}, pc, #{dest.armOperand}"
$asm.puts "ldr #{dest.armOperand}, [#{dest.armOperand}, #{temp.armOperand}]"
+ # Windows (COFF, non-PIC): movw/movt 取符号绝对地址,linker 用 IMAGE_REL_ARM_MOV32T 重定位、
+ # 加载器按 ASLR 基址修正。无需 GOT / non_lazy_ptr 表(故下方 deferNextLabelAction 不需 Windows 分支)。
+ $asm.putStr("#elif OS(WINDOWS)")
+ $asm.puts "movw #{dest.armOperand}, :lower16:#{operands[0].asmLabel}"
+ $asm.puts "movt #{dest.armOperand}, :upper16:#{operands[0].asmLabel}"
+
# Throw a compiler error everywhere else.
$asm.putStr("#else")
$asm.putStr("#error Missing globaladdr implementation")
diff --git a/Source/JavaScriptCore/runtime/MachineContext.h b/Source/JavaScriptCore/runtime/MachineContext.h
index 50353c75e4..b66b9f60da 100644
--- a/Source/JavaScriptCore/runtime/MachineContext.h
+++ b/Source/JavaScriptCore/runtime/MachineContext.h
@@ -748,8 +748,9 @@ inline void*& llintInstructionPointer(PlatformRegisters& regs)
#elif OS(WINDOWS)
#if CPU(ARM)
- static_assert(LLInt::LLIntPC == ARMRegisters::r8, "Wrong LLInt PC.");
- return reinterpret_cast<void*&>((uintptr_t&) regs.R8);
+ // LLIntPC = GPRInfo::regT4,在 ARM 上是 r4(原 r8/R8 是未测过的错误推测)。
+ static_assert(LLInt::LLIntPC == ARMRegisters::r4, "Wrong LLInt PC.");
+ return reinterpret_cast<void*&>((uintptr_t&) regs.R4);
#elif CPU(X86)
static_assert(LLInt::LLIntPC == X86Registers::esi, "Wrong LLInt PC.");
return reinterpret_cast<void*&>((uintptr_t&) regs.Esi);
diff --git a/Source/JavaScriptCore/runtime/MathCommon.cpp b/Source/JavaScriptCore/runtime/MathCommon.cpp
index 24429b75b6..174c05239e 100644
--- a/Source/JavaScriptCore/runtime/MathCommon.cpp
+++ b/Source/JavaScriptCore/runtime/MathCommon.cpp
@@ -604,7 +604,8 @@ JSC_DEFINE_NOEXCEPT_JIT_OPERATION(f64_nearest, double, (double operand))
return std::nearbyint(operand);
}
-#if (OS(LINUX) && !defined(__GLIBC__)) || OS(HAIKU)
+#if (OS(LINUX) && !defined(__GLIBC__)) || OS(HAIKU) || OS(WINDOWS)
+// MSVC UCRT 不提供 C23 的 roundeven/roundevenf, Windows 也用 WebKit 自带 fallback。
static inline float roundevenf(float operand)
{
float rounded = roundf(operand);
diff --git a/Source/WTF/wtf/CodePtr.h b/Source/WTF/wtf/CodePtr.h
index efa00c8f4a..0a6a5c65a4 100644
--- a/Source/WTF/wtf/CodePtr.h
+++ b/Source/WTF/wtf/CodePtr.h
@@ -91,7 +91,7 @@ public:
: m_value(encodeFunc(ptr))
{ }
-#if OS(WINDOWS)
+#if OS(WINDOWS) && CPU(X86_64)
template<typename Out, typename... In>
constexpr CodePtr(Out(SYSV_ABI *ptr)(In...))
: m_value(encodeFunc(ptr))
diff --git a/Source/WTF/wtf/CurrentTime.cpp b/Source/WTF/wtf/CurrentTime.cpp
index 681aeffc2d..8631aac7a0 100644
--- a/Source/WTF/wtf/CurrentTime.cpp
+++ b/Source/WTF/wtf/CurrentTime.cpp
@@ -170,9 +170,13 @@ static inline double currentTime()
double highResTime = highResUpTime();
if (!syncedTime) {
- timeBeginPeriod(1); // increase time resolution around low-res time getter
+#if !defined(WK_WINUWP)
+ timeBeginPeriod(1); // increase time resolution around low-res time getter (winmm, desktop-only)
+#endif
syncLowResUTCTime = lowResTime = lowResUTCTime();
+#if !defined(WK_WINUWP)
timeEndPeriod(1); // restore time resolution
+#endif
syncHighResUpTime = highResTime;
syncedTime = true;
}
diff --git a/Source/WTF/wtf/FastMalloc.cpp b/Source/WTF/wtf/FastMalloc.cpp
index b8a269c620..a0cc635248 100644
--- a/Source/WTF/wtf/FastMalloc.cpp
+++ b/Source/WTF/wtf/FastMalloc.cpp
@@ -208,18 +208,37 @@ void fastAlignedFree(void* p)
#endif // OS(WINDOWS)
-TryMallocReturnValue tryFastMalloc(size_t n)
+#if defined(WK_WINUWP)
+// Apotheosis: ARM32 上 clang 对 alignof>=16 的类型(如 WebCore::EventHandler)会生成 NEON
+// vst1.64 {dN,dM},[rX:128] 这类要求目标 16 字节对齐的指令来批量初始化成员。但
+// WTF_MAKE_FAST_ALLOCATED 只提供非对齐的 operator new(size_t)→fastMalloc;按 C++17 规则,过对齐
+// 类型在找不到接受 align_val_t 的分配函数时会"静默退回"非对齐版,于是 malloc 只给 8 字节对齐
+// → vst1.64 触发 EXCEPTION_DATATYPE_MISALIGNMENT(0x80000002)真机闪退(EventHandler 构造)。
+// 这里把整套 fast* 提升为 16 字节对齐(_aligned_malloc 的内存必须用 _aligned_free/_aligned_realloc/
+// _aligned_msize 配套处理,故整组一起改,保持自洽)。
+static constexpr size_t kWinUWPFastMallocAlignment = 16;
+#endif
+
+TryMallocReturnValue tryFastMalloc(size_t n)
{
FAIL_IF_EXCEEDS_LIMIT(n);
assertMallocRestrictionForCurrentThreadScope();
+#if defined(WK_WINUWP)
+ return _aligned_malloc(n, kWinUWPFastMallocAlignment);
+#else
return malloc(n);
+#endif
}
-void* fastMalloc(size_t n)
+void* fastMalloc(size_t n)
{
ASSERT_IS_WITHIN_LIMIT(n);
assertMallocRestrictionForCurrentThreadScope();
+#if defined(WK_WINUWP)
+ void* result = _aligned_malloc(n, kWinUWPFastMallocAlignment);
+#else
void* result = malloc(n);
+#endif
if (!result)
CRASH();
@@ -246,14 +265,29 @@ TryMallocReturnValue tryFastCalloc(size_t n_elements, size_t element_size)
{
FAIL_IF_EXCEEDS_LIMIT(n_elements * element_size);
assertMallocRestrictionForCurrentThreadScope();
+#if defined(WK_WINUWP)
+ size_t total = n_elements * element_size;
+ void* result = _aligned_malloc(total, kWinUWPFastMallocAlignment);
+ if (result)
+ memset(result, 0, total);
+ return result;
+#else
return calloc(n_elements, element_size);
+#endif
}
void* fastCalloc(size_t n_elements, size_t element_size)
{
ASSERT_IS_WITHIN_LIMIT(n_elements * element_size);
assertMallocRestrictionForCurrentThreadScope();
+#if defined(WK_WINUWP)
+ size_t total = n_elements * element_size;
+ void* result = _aligned_malloc(total, kWinUWPFastMallocAlignment);
+ if (result)
+ memset(result, 0, total);
+#else
void* result = calloc(n_elements, element_size);
+#endif
if (!result)
CRASH();
@@ -262,14 +296,22 @@ void* fastCalloc(size_t n_elements, size_t element_size)
void fastFree(void* p)
{
+#if defined(WK_WINUWP)
+ _aligned_free(p);
+#else
free(p);
+#endif
}
void* fastRealloc(void* p, size_t n)
{
ASSERT_IS_WITHIN_LIMIT(n);
assertMallocRestrictionForCurrentThreadScope();
+#if defined(WK_WINUWP)
+ void* result = _aligned_realloc(p, n, kWinUWPFastMallocAlignment);
+#else
void* result = realloc(p, n);
+#endif
if (!result)
CRASH();
return result;
@@ -279,7 +321,11 @@ TryMallocReturnValue tryFastRealloc(void* p, size_t n)
{
FAIL_IF_EXCEEDS_LIMIT(n);
assertMallocRestrictionForCurrentThreadScope();
+#if defined(WK_WINUWP)
+ return _aligned_realloc(p, n, kWinUWPFastMallocAlignment);
+#else
return realloc(p, n);
+#endif
}
void releaseFastMallocFreeMemory() { }
@@ -296,7 +342,11 @@ size_t fastMallocSize(const void* p)
#if OS(DARWIN)
return malloc_size(p);
#elif OS(WINDOWS)
+#if defined(WK_WINUWP)
+ return _aligned_msize(const_cast<void*>(p), kWinUWPFastMallocAlignment, 0);
+#else
return _msize(const_cast<void*>(p));
+#endif
#else
UNUSED_PARAM(p);
return 1;
diff --git a/Source/WTF/wtf/FunctionPtr.h b/Source/WTF/wtf/FunctionPtr.h
index c78c59733c..198bc88761 100644
--- a/Source/WTF/wtf/FunctionPtr.h
+++ b/Source/WTF/wtf/FunctionPtr.h
@@ -88,7 +88,7 @@ public:
: m_ptr(encode(ptr))
{ }
-#if OS(WINDOWS)
+#if OS(WINDOWS) && CPU(X86_64)
constexpr FunctionPtr(Out(SYSV_ABI *ptr)(In...))
: m_ptr(encode(ptr))
{ }
diff --git a/Source/WTF/wtf/FunctionTraits.h b/Source/WTF/wtf/FunctionTraits.h
index 90e9142621..ac54804e8d 100644
--- a/Source/WTF/wtf/FunctionTraits.h
+++ b/Source/WTF/wtf/FunctionTraits.h
@@ -80,7 +80,7 @@ struct FunctionTraits<Result(Args...)> {
};
-#if OS(WINDOWS)
+#if OS(WINDOWS) && CPU(X86_64)
template<typename Result, typename... Args>
struct FunctionTraits<Result SYSV_ABI(Args...)> : public FunctionTraits<Result(Args...)> {
};
@@ -90,7 +90,7 @@ template<typename Result, typename... Args>
struct FunctionTraits<Result(*)(Args...)> : public FunctionTraits<Result(Args...)> {
};
-#if OS(WINDOWS)
+#if OS(WINDOWS) && CPU(X86_64)
template<typename Result, typename... Args>
struct FunctionTraits<Result SYSV_ABI (*)(Args...)> : public FunctionTraits<Result(Args...)> {
};
diff --git a/Source/WTF/wtf/PlatformCallingConventions.h b/Source/WTF/wtf/PlatformCallingConventions.h
index eea6f6f70e..266dca7682 100644
--- a/Source/WTF/wtf/PlatformCallingConventions.h
+++ b/Source/WTF/wtf/PlatformCallingConventions.h
@@ -33,7 +33,10 @@
/* Macros for specifing specific calling conventions. */
-#if OS(WINDOWS)
+// sysv_abi 仅在 x86_64 上区分 Win64 与 System V AMD64 调用约定;ARM/ARM64 只有 AAPCS 一种,
+// 该属性被编译器忽略(并产生大量 -Wignored-attributes 警告 + 触发 TrustedImmPtr 构造函数撞重)。
+// 故仅在 x86_64 Windows 启用。
+#if OS(WINDOWS) && CPU(X86_64)
#define SYSV_ABI __attribute__((sysv_abi))
#else
#define SYSV_ABI
diff --git a/Source/WTF/wtf/RandomDevice.cpp b/Source/WTF/wtf/RandomDevice.cpp
index 95921fd376..2719111e42 100644
--- a/Source/WTF/wtf/RandomDevice.cpp
+++ b/Source/WTF/wtf/RandomDevice.cpp
@@ -37,8 +37,12 @@
#if OS(WINDOWS)
#include <windows.h>
+#if defined(WK_WINUWP)
+#include <bcrypt.h> // App Container: 用 BCrypt 代替不可用的旧版 CryptoAPI(wincrypt)
+#else
#include <wincrypt.h> // windows.h must be included before wincrypt.h.
#endif
+#endif
#if OS(DARWIN)
#include <CommonCrypto/CommonCryptor.h>
@@ -105,6 +109,10 @@ void RandomDevice::cryptographicallyRandomValues(std::span<uint8_t> buffer)
} else
amountRead += currentRead;
}
+#elif OS(WINDOWS) && defined(WK_WINUWP)
+ // App Container: 旧版 CryptoAPI 不可用, 用 BCrypt 的系统首选 RNG(无需打开算法句柄)。
+ if (BCryptGenRandom(nullptr, reinterpret_cast<PUCHAR>(buffer.data()), static_cast<ULONG>(buffer.size()), BCRYPT_USE_SYSTEM_PREFERRED_RNG))
+ CRASH(); // 返回非 0 (NTSTATUS != STATUS_SUCCESS) 即失败
#elif OS(WINDOWS)
// FIXME: We cannot ensure that Cryptographic Service Provider context and CryptGenRandom are safe across threads.
// If it is safe, we can acquire context per RandomDevice.
diff --git a/Source/WTF/wtf/StackTrace.h b/Source/WTF/wtf/StackTrace.h
index 60d2eb043f..52b374e5f7 100644
--- a/Source/WTF/wtf/StackTrace.h
+++ b/Source/WTF/wtf/StackTrace.h
@@ -126,7 +126,7 @@ public:
char** symbols = backtrace_symbols(m_stack.data(), m_stack.size());
if (!symbols)
return;
-#elif OS(WINDOWS)
+#elif OS(WINDOWS) && !defined(WK_WINUWP)
HANDLE hProc = GetCurrentProcess();
uint8_t symbolData[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)] = { 0 };
auto symbolInfo = reinterpret_cast<SYMBOL_INFO*>(symbolData);
@@ -142,7 +142,7 @@ public:
#if HAVE(BACKTRACE_SYMBOLS)
if (!name || !strcmp(name, "<redacted>"))
name = symbols[i];
-#elif OS(WINDOWS)
+#elif OS(WINDOWS) && !defined(WK_WINUWP)
if (!name && DbgHelper::SymFromAddress(hProc, reinterpret_cast<DWORD64>(m_stack[i]), nullptr, symbolInfo))
name = symbolInfo->Name;
#endif
diff --git a/Source/WTF/wtf/StdLibExtras.h b/Source/WTF/wtf/StdLibExtras.h
index ec0194903f..25eb5d82a9 100644
--- a/Source/WTF/wtf/StdLibExtras.h
+++ b/Source/WTF/wtf/StdLibExtras.h
@@ -423,7 +423,15 @@ template<class A> struct Visitor<A> : A {
using A::operator();
};
-template<class... F> ALWAYS_INLINE Visitor<F...> makeVisitor(F... f)
+// Apotheosis(WK_WINUWP): clang thumbv7-windows-msvc 的 MS-ABI 修饰器对包展开"未实现"(MicrosoftMangle.cpp
+// 2012 年的桩,任何 LLVM 版本/main/23 都没修)。makeVisitor/switchOn 用变参 lambda 包构造 Visitor,其闭包类
+// 落入需导出 MS 修饰名的模板实参 → "cannot mangle this pack expansion yet"。给这些 helper 内部链接(static)
+// + 强制内联,CodeGen 就不再为它们请求导出修饰名。内部链接/内联改动不改 ABI,不影响已建的 Phase0 WTF/JSC.lib。
+// Apotheosis: 早期为绕 mpark 修饰墙试过 static/gnu_inline 内部链接,均无效(已改为换 std::variant)。
+// 此宏现等价于 ALWAYS_INLINE,保留仅为不改动下方各 switchOn/makeVisitor 的引用点。
+#define WTF_VISITOR_INTERNAL ALWAYS_INLINE
+
+template<class... F> WTF_VISITOR_INTERNAL Visitor<F...> makeVisitor(F... f)
{
return Visitor<F...>(f...);
}
@@ -534,6 +542,16 @@ template<typename T> concept HasSwitchOn = requires(T t) {
t.switchOn([](const auto&) {});
};
+#if defined(WK_WINUWP)
+// Apotheosis: clang thumbv7-windows-msvc 的 MS-ABI 修饰器在修饰"带 C++20 requires 约束的变参函数模板
+// switchOn 实例"时,必须把关联约束(HasSwitchOn 概念表达式,内含未展开包 / 概念内泛型 lambda)编进修饰名,
+// 落入 MicrosoftMangle.cpp 的 pack-expansion 未实现桩(任何 LLVM 版本未修)→ "cannot mangle this pack expansion yet"。
+// 消融实验(port\repro_variant_return_15/16)证明:把约束从 requires 换成 enable_if SFINAE,墙即消失
+// (SFINAE 条件不进修饰名)。下方用等价的 void_t trait 替代概念,仅用于 WK_WINUWP 的 switchOn 重载约束。
+template<class T, class = void> struct HasSwitchOnMember : std::false_type { };
+template<class T> struct HasSwitchOnMember<T, std::void_t<decltype(std::declval<T&>().switchOn([](const auto&) { }))>> : std::true_type { };
+#endif
+
template<typename Derived, typename Base>
concept DerivedFromOrConvertibleTo = std::is_base_of_v<Base, Derived> || std::is_convertible_v<Derived, Base>;
@@ -557,24 +575,42 @@ template<size_t Minimum = 0, class F, class V> ALWAYS_INLINE decltype(auto) visi
#undef WTF_INDEX_VISIT_CASE
}
-template<class V, class... F> requires (!HasSwitchOn<V>) ALWAYS_INLINE auto switchOn(V&& v, F&&... f) -> decltype(visitOneVariant(makeVisitor(std::forward<F>(f)...), asVariant(std::forward<V>(v))))
+template<class V, class... F> requires (!HasSwitchOn<V>) ALWAYS_INLINE auto switchOn(V&& v, F&&... f) // Apotheosis: 去尾置 decltype,用 auto 推导避免 MS ABI decltype 修饰
{
return visitOneVariant(makeVisitor(std::forward<F>(f)...), asVariant(std::forward<V>(v)));
}
#else
-template<class V, class... F> requires (!HasSwitchOn<V>) ALWAYS_INLINE constexpr auto switchOn(V&& v, F&&... f) -> decltype(WTF::visit(makeVisitor(std::forward<F>(f)...), asVariant(std::forward<V>(v))))
+// Apotheosis: 原为 `-> decltype(WTF::visit(...))` 尾置返回类型。clang 的 thumbv7-windows-msvc
+// (MS ABI)名字修饰器对某些复杂 variant 的 decltype 报 "cannot mangle this decltype() yet"。
+// 改用 auto 返回推导(修饰的是推导出的具体类型,而非 decltype),requires 子句仍保证只对
+// 非 HasSwitchOn 的 variant 参与重载。
+#if defined(WK_WINUWP)
+template<class V, class... F, std::enable_if_t<!HasSwitchOnMember<std::remove_cvref_t<V>>::value, int> = 0> WTF_VISITOR_INTERNAL decltype(auto) switchOn(V&& v, F&&... f) // Apotheosis: requires→enable_if(避 pack 墙);decltype(auto) 保留引用返回(避 Render* 等引用被 decay 成抽象/不可拷贝值)
{
return WTF::visit(makeVisitor(std::forward<F>(f)...), asVariant(std::forward<V>(v)));
}
+#else
+template<class V, class... F> requires (!HasSwitchOn<V>) WTF_VISITOR_INTERNAL auto switchOn(V&& v, F&&... f)
+{
+ return WTF::visit(makeVisitor(std::forward<F>(f)...), asVariant(std::forward<V>(v)));
+}
+#endif
#endif
-template<class V, class... F> requires (HasSwitchOn<V>) ALWAYS_INLINE auto switchOn(V&& v, F&&... f) -> decltype(v.switchOn(std::forward<F>(f)...))
+#if defined(WK_WINUWP)
+template<class V, class... F, std::enable_if_t<HasSwitchOnMember<std::remove_cvref_t<V>>::value, int> = 0> WTF_VISITOR_INTERNAL decltype(auto) switchOn(V&& v, F&&... f) // Apotheosis: requires→enable_if + decltype(auto) 返回(原尾置 decltype 撞次要墙,decltype(auto) 推导出具体类型可修饰且保留引用)
{
return v.switchOn(std::forward<F>(f)...);
}
+#else
+template<class V, class... F> requires (HasSwitchOn<V>) WTF_VISITOR_INTERNAL auto switchOn(V&& v, F&&... f) -> decltype(v.switchOn(std::forward<F>(f)...))
+{
+ return v.switchOn(std::forward<F>(f)...);
+}
+#endif
// Implementation of std::variant_alternative_index from https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2527r3.html.
diff --git a/Source/WTF/wtf/Variant.h b/Source/WTF/wtf/Variant.h
index fc43f039d8..83b9b18be6 100644
--- a/Source/WTF/wtf/Variant.h
+++ b/Source/WTF/wtf/Variant.h
@@ -2907,7 +2907,34 @@ template<class T, class... Types> constexpr add_pointer_t<const T> get_if(const
}
+#if defined(WK_WINUWP)
+#include <variant> // Apotheosis: std::variant 替换 mpark 所需的标准头(mpark 单头不含 <variant>)
+#endif
+
namespace WTF {
+#if defined(WK_WINUWP)
+// Apotheosis(WK_WINUWP): 用 std::variant 替换 mpark::variant。clang thumbv7-windows-msvc 的 MS-ABI
+// 名字修饰器对 mpark::variant 在 switchOn/visit 里的实例化报 "cannot mangle this pack expansion yet"
+// (最小复现证明 std::variant + std::visit 同样的递归 Visitor / 变参 switchOn 模式可正常修饰)。
+// std::variant 与 mpark API 兼容;build-clang-webcore 整体重编 WTF+JSC+WebCore,ABI 自洽。
+template<typename... Ts> using Variant = std::variant<Ts...>;
+template<size_t I, class T> using variant_alternative_t = std::variant_alternative_t<I, T>;
+template<typename T> constexpr std::in_place_type_t<T> InPlaceType { };
+template<typename T> using InPlaceTypeT = std::in_place_type_t<T>;
+template<size_t I> constexpr std::in_place_index_t<I> InPlaceIndex { };
+template<size_t I> using InPlaceIndexT = std::in_place_index_t<I>;
+template <size_t I, class T> struct VariantAlternative;
+template<size_t I, typename... Types> struct VariantAlternative<I, Variant<Types...>> : std::variant_alternative<I, Variant<Types...>> { };
+template<size_t I, typename T> using VariantAlternativeT = typename VariantAlternative<I, T>::type;
+template<typename T> struct VariantSize;
+template<typename... Types> struct VariantSize<Variant<Types...>> : std::integral_constant<std::size_t, sizeof...(Types)> { };
+template<typename T> struct VariantSize<const T> : VariantSize<T> { };
+template<typename T> constexpr size_t VariantSizeV = VariantSize<T>::value;
+template<typename Visitor, typename... Variants> constexpr decltype(auto) visit(Visitor&& v, Variants&&... values) // Apotheosis: decltype(auto) 而非 auto,保留 visitor 分支的引用返回(否则抽象类 RenderObject/不可拷贝 RenderBlockFlow 被 decay 成值 → 拷贝/实例化抽象类报错)
+{
+ return std::visit(std::forward<Visitor>(v), std::forward<Variants>(values)...);
+}
+#else
template<typename... Ts> using Variant = mpark::variant<Ts...>;
template<size_t I, class T> using variant_alternative_t = typename mpark::variant_alternative<I, T>::type;
template<typename T> constexpr mpark::in_place_type_t<T> InPlaceType { };
@@ -2921,12 +2948,11 @@ template<typename T> struct VariantSize;
template<typename... Types> struct VariantSize<Variant<Types...>> : std::integral_constant<std::size_t, sizeof...(Types)> { };
template<typename T> struct VariantSize<const T> : VariantSize<T> { };
template<typename T> constexpr size_t VariantSizeV = VariantSize<T>::value;
-
template<typename Visitor, typename... Variants> constexpr auto visit(Visitor&& v, Variants&&... values)
- -> decltype(mpark::visit<Visitor, Variants...>(std::forward<Visitor>(v), std::forward<Variants>(values)...))
{
- return mpark::visit<Visitor, Variants...>(std::forward<Visitor>(v), std::forward<Variants>(values)...);
+ return mpark::visit(std::forward<Visitor>(v), std::forward<Variants>(values)...);
}
+#endif
}
diff --git a/Source/WTF/wtf/WindowsExtras.h b/Source/WTF/wtf/WindowsExtras.h
index 00cb2b14e0..6b86207053 100644
--- a/Source/WTF/wtf/WindowsExtras.h
+++ b/Source/WTF/wtf/WindowsExtras.h
@@ -41,17 +41,31 @@ namespace WTF {
inline HRESULT getRegistryValue(HKEY hkey, LPCWSTR pszSubKey, LPCWSTR pszValue, LPDWORD pdwType, LPVOID pvData, LPDWORD pcbData)
{
+#if defined(WK_WINUWP)
+ UNUSED_PARAM(hkey); UNUSED_PARAM(pszSubKey); UNUSED_PARAM(pszValue);
+ UNUSED_PARAM(pdwType); UNUSED_PARAM(pvData); UNUSED_PARAM(pcbData);
+ return E_NOTIMPL; // App Container: 无 shlwapi SHGetValueW
+#else
return ::SHGetValueW(hkey, pszSubKey, pszValue, pdwType, pvData, pcbData);
+#endif
}
inline void* getWindowPointer(HWND hWnd, int index)
{
+#if defined(WK_WINUWP)
+ UNUSED_PARAM(hWnd); UNUSED_PARAM(index); return nullptr; // App Container: 无 HWND/user32
+#else
return reinterpret_cast<void*>(::GetWindowLongPtr(hWnd, index));
+#endif
}
inline void* setWindowPointer(HWND hWnd, int index, void* value)
{
+#if defined(WK_WINUWP)
+ UNUSED_PARAM(hWnd); UNUSED_PARAM(index); UNUSED_PARAM(value); return nullptr;
+#else
return reinterpret_cast<void*>(::SetWindowLongPtr(hWnd, index, reinterpret_cast<LONG_PTR>(value)));
+#endif
}
} // namespace WTF
diff --git a/Source/WTF/wtf/generic/MainThreadGeneric.cpp b/Source/WTF/wtf/generic/MainThreadGeneric.cpp
index 6f873d0771..834ba12f3c 100644
--- a/Source/WTF/wtf/generic/MainThreadGeneric.cpp
+++ b/Source/WTF/wtf/generic/MainThreadGeneric.cpp
@@ -31,12 +31,32 @@
*/
#include "config.h"
+#if OS(WINDOWS)
+#include <windows.h>
+#else
#include <pthread.h>
+#endif
#include <wtf/RunLoop.h>
namespace WTF {
+#if OS(WINDOWS)
+
+static DWORD s_mainThread;
+
+void initializeMainThreadPlatform()
+{
+ s_mainThread = GetCurrentThreadId();
+}
+
+bool isMainThread()
+{
+ return GetCurrentThreadId() == s_mainThread;
+}
+
+#else
+
static pthread_t s_mainThread;
void initializeMainThreadPlatform()
@@ -54,4 +74,6 @@ bool isMainThread()
return pthread_equal(pthread_self(), s_mainThread);
}
+#endif
+
} // namespace WTF
diff --git a/Source/WTF/wtf/simde/arm/neon.h b/Source/WTF/wtf/simde/arm/neon.h
index 28dc5821f3..561de48401 100644
--- a/Source/WTF/wtf/simde/arm/neon.h
+++ b/Source/WTF/wtf/simde/arm/neon.h
@@ -105333,7 +105333,11 @@ simde_mm_pause (void) {
#endif
#elif defined(SIMDE_ARCH_ARM_NEON)
#if defined(_MSC_VER)
- __isb(SIMDE_ARM64_BARRIER_SY);
+ #if defined(_M_ARM64)
+ __isb(SIMDE_ARM64_BARRIER_SY);
+ #else
+ __isb(SIMDE_ARM_BARRIER_SY);
+ #endif
#else
__asm__ __volatile__("isb\n");
#endif
diff --git a/Source/WTF/wtf/win/DbgHelperWin.h b/Source/WTF/wtf/win/DbgHelperWin.h
index d951a0b07f..efd603af12 100644
--- a/Source/WTF/wtf/win/DbgHelperWin.h
+++ b/Source/WTF/wtf/win/DbgHelperWin.h
@@ -28,6 +28,8 @@
#include <wtf/Lock.h>
#include <wtf/Noncopyable.h>
+// dbghelp 是桌面专用(App Container 无 SYMBOL_INFO 等), UWP 下整块排除。
+#if !defined(WK_WINUWP)
#include <dbghelp.h>
namespace WTF {
@@ -39,3 +41,4 @@ WTF_EXPORT_PRIVATE bool SymFromAddress(HANDLE hProc, DWORD64 address, DWORD64* d
};
} // namespace WTF
+#endif
diff --git a/Source/WTF/wtf/win/FileSystemWin.cpp b/Source/WTF/wtf/win/FileSystemWin.cpp
index 5c1332dbb0..acfe2ef424 100644
--- a/Source/WTF/wtf/win/FileSystemWin.cpp
+++ b/Source/WTF/wtf/win/FileSystemWin.cpp
@@ -100,8 +100,30 @@ CString fileSystemRepresentation(const String& path)
return string;
}
+#if defined(WK_WINUWP)
+// App Container: 旧版 CreateFileW 不可用(fileapi.h 仅暴露 CreateFile2)。包一层兼容旧 7 参签名。
+static inline HANDLE wkCreateFile(LPCWSTR name, DWORD access, DWORD share, LPSECURITY_ATTRIBUTES sa, DWORD disposition, DWORD flagsAndAttributes, HANDLE)
+{
+ CREATEFILE2_EXTENDED_PARAMETERS p { };
+ p.dwSize = sizeof(p);
+ p.dwFileAttributes = flagsAndAttributes & 0x0000FFFF;
+ p.dwFileFlags = flagsAndAttributes & 0xFFF00000;
+ p.dwSecurityQosFlags = flagsAndAttributes & 0x000F0000;
+ p.lpSecurityAttributes = sa;
+ return CreateFile2(name, access, share, disposition, &p);
+}
+#define WK_CREATE_FILE wkCreateFile
+#else
+#define WK_CREATE_FILE ::CreateFileW
+#endif
+
static String storageDirectory(DWORD pathIdentifier)
{
+#if defined(WK_WINUWP)
+ // App Container: 无 SHGetFolderPath/CSIDL。Phase 0 不需要 appdata 缓存目录。
+ UNUSED_PARAM(pathIdentifier);
+ return String();
+#else
Vector<char16_t> buffer(MAX_PATH);
if (FAILED(SHGetFolderPathW(nullptr, pathIdentifier | CSIDL_FLAG_CREATE, nullptr, 0, wcharFrom(buffer.mutableSpan().data()))))
return String();
@@ -114,6 +136,7 @@ static String storageDirectory(DWORD pathIdentifier)
return String();
return directory;
+#endif
}
static String cachedStorageDirectory(DWORD pathIdentifier)
@@ -168,7 +191,7 @@ std::pair<String, FileHandle> openTemporaryFile(StringView, StringView suffix, c
String proposedPath = generateTemporaryPath([&handle](const String& proposedPath) {
// use CREATE_NEW to avoid overwriting an existing file with the same name
- handle = FileHandle::adopt(::CreateFileW(proposedPath.wideCharacters().span().data(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr));
+ handle = FileHandle::adopt(WK_CREATE_FILE(proposedPath.wideCharacters().span().data(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr));
return handle || GetLastError() == ERROR_ALREADY_EXISTS;
});
@@ -204,17 +227,25 @@ FileHandle openFile(const String& path, FileOpenMode mode, FileAccessPermission,
creationDisposition = CREATE_NEW;
String destination = path;
- return FileHandle::adopt(CreateFile(destination.wideCharacters().span().data(), desiredAccess, shareMode, nullptr, creationDisposition, FILE_ATTRIBUTE_NORMAL, nullptr), lockMode);
+ return FileHandle::adopt(WK_CREATE_FILE(destination.wideCharacters().span().data(), desiredAccess, shareMode, nullptr, creationDisposition, FILE_ATTRIBUTE_NORMAL, nullptr), lockMode);
}
String localUserSpecificStorageDirectory()
{
+#if defined(WK_WINUWP)
+ return String(); // App Container: 无 CSIDL_LOCAL_APPDATA(Phase 0 不需要)
+#else
return cachedStorageDirectory(CSIDL_LOCAL_APPDATA);
+#endif
}
String roamingUserSpecificStorageDirectory()
{
+#if defined(WK_WINUWP)
+ return String(); // App Container: 无 CSIDL_APPDATA
+#else
return cachedStorageDirectory(CSIDL_APPDATA);
+#endif
}
std::optional<int32_t> getFileDeviceId(const String& fsFile)
diff --git a/Source/WTF/wtf/win/GDIObject.h b/Source/WTF/wtf/win/GDIObject.h
index 772aab73a6..903c1469c0 100644
--- a/Source/WTF/wtf/win/GDIObject.h
+++ b/Source/WTF/wtf/win/GDIObject.h
@@ -113,16 +113,26 @@ template<typename T> inline void swap(GDIObject<T>& a, GDIObject<T>& b)
}
// Nearly all GDI types use the same DeleteObject call.
+// Apotheosis(App Container): DeleteObject/DeleteDC 是 GDI 桌面 API,WINAPI_FAMILY_APP 下
+// 不可用。沙箱里 GDI 对象也无法创建,故 GDIObject 永不持真实句柄 → 删除器 no-op 安全。
template<typename T> inline void deleteObject(T object)
{
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
if (object)
::DeleteObject(object);
+#else
+ (void)object;
+#endif
}
template<> inline void deleteObject<HDC>(HDC hdc)
{
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
if (hdc)
::DeleteDC(hdc);
+#else
+ (void)hdc;
+#endif
}
} // namespace WTF
diff --git a/Source/WTF/wtf/win/MemoryPressureHandlerWin.cpp b/Source/WTF/wtf/win/MemoryPressureHandlerWin.cpp
index 372f8f74a0..2cddf617fd 100644
--- a/Source/WTF/wtf/win/MemoryPressureHandlerWin.cpp
+++ b/Source/WTF/wtf/win/MemoryPressureHandlerWin.cpp
@@ -26,20 +26,26 @@
#include "config.h"
#include <wtf/MemoryPressureHandler.h>
+#if !defined(WK_WINUWP)
#include <psapi.h>
+#endif
#include <wtf/NeverDestroyed.h>
namespace WTF {
void MemoryPressureHandler::platformInitialize()
{
+#if !defined(WK_WINUWP)
+ // App Container 无 CreateMemoryResourceNotification(桌面内存通知 API)。
m_lowMemoryHandle = Win32Handle::adopt(::CreateMemoryResourceNotification(LowMemoryResourceNotification));
+#endif
}
void MemoryPressureHandler::windowsMeasurementTimerFired()
{
setMemoryPressureStatus(SystemMemoryPressureStatus::Normal);
+#if !defined(WK_WINUWP)
BOOL memoryLow;
if (QueryMemoryResourceNotification(m_lowMemoryHandle.get(), &memoryLow) && memoryLow) {
@@ -47,6 +53,7 @@ void MemoryPressureHandler::windowsMeasurementTimerFired()
releaseMemory(Critical::Yes);
return;
}
+#endif
#if CPU(X86)
PROCESS_MEMORY_COUNTERS_EX counters;
diff --git a/Source/WTF/wtf/win/OSAllocatorWin.cpp b/Source/WTF/wtf/win/OSAllocatorWin.cpp
index 5664e2d839..53c1bf5081 100644
--- a/Source/WTF/wtf/win/OSAllocatorWin.cpp
+++ b/Source/WTF/wtf/win/OSAllocatorWin.cpp
@@ -34,7 +34,23 @@
#include <wtf/SoftLinking.h>
SOFT_LINK_LIBRARY(kernelbase)
+
+#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP
+// App Container(UWP): 普通 VirtualAlloc/VirtualAlloc2/VirtualProtect 不在允许的 API set, 必须用 *FromApp 变体。
+// JIT(ENABLE_JIT=1):真机实测 VirtualAllocFromApp 直接带 PAGE_EXECUTE_* 会 err=87 失败,但「RW 分配 + 写码 +
+// VirtualProtectFromApp 翻成 PAGE_EXECUTE_*」可行(W^X),前提是清单声明 codeGeneration 能力。
+#define WK_VirtualAlloc VirtualAllocFromApp
+#define WK_VirtualProtect VirtualProtectFromApp
+SOFT_LINK_OPTIONAL(kernelbase, VirtualAlloc2FromApp, void*, WINAPI, (HANDLE, PVOID, SIZE_T, ULONG, ULONG, MEM_EXTENDED_PARAMETER *, ULONG))
+#define WK_VirtualAlloc2Ptr VirtualAlloc2FromAppPtr
+#define WK_APP_CONTAINER 1
+#else
+#define WK_VirtualAlloc VirtualAlloc
+#define WK_VirtualProtect VirtualProtect
SOFT_LINK_OPTIONAL(kernelbase, VirtualAlloc2, void*, WINAPI, (HANDLE, PVOID, SIZE_T, ULONG, ULONG, MEM_EXTENDED_PARAMETER *, ULONG))
+#define WK_VirtualAlloc2Ptr VirtualAlloc2Ptr
+#define WK_APP_CONTAINER 0
+#endif
namespace WTF {
@@ -45,9 +61,34 @@ static inline DWORD protection(bool writable, bool executable)
(writable ? PAGE_READWRITE : PAGE_READONLY);
}
+// App Container 下分配时用的保护:executable 一律先按可写非执行分配(*FromApp 不接受 PAGE_EXECUTE_*),
+// 可执行靠提交后的 applyExecutableProtection 翻转(W^X)。非 App 容器与原行为一致。
+static inline DWORD allocProtection(bool writable, bool executable)
+{
+#if WK_APP_CONTAINER
+ if (executable)
+ return writable ? PAGE_READWRITE : PAGE_READONLY;
+#endif
+ return protection(writable, executable);
+}
+
+// 提交后,App Container 下若需可执行,用 VirtualProtectFromApp 翻成可执行保护(需 codeGeneration 能力)。
+static inline void applyExecutableProtection(void* address, size_t bytes, bool writable, bool executable)
+{
+#if WK_APP_CONTAINER
+ if (address && executable) {
+ DWORD oldProtect = 0;
+ WK_VirtualProtect(address, bytes, protection(writable, executable), &oldProtect);
+ }
+#else
+ UNUSED_PARAM(address); UNUSED_PARAM(bytes); UNUSED_PARAM(writable); UNUSED_PARAM(executable);
+#endif
+}
+
void* OSAllocator::tryReserveUncommitted(size_t bytes, Usage, void* address, bool writable, bool executable, bool, unsigned)
{
- return VirtualAlloc(address, bytes, MEM_RESERVE, protection(writable, executable));
+ // 仅预留(不提交):无已提交页,故只按 allocProtection 预留;可执行保护在 commit 时再翻。
+ return WK_VirtualAlloc(address, bytes, MEM_RESERVE, allocProtection(writable, executable));
}
void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, void* address, bool writable, bool executable, bool jitCageEnabled, unsigned numGuardPagesToAddOnEachEnd)
@@ -61,13 +102,13 @@ void* OSAllocator::tryReserveUncommittedAligned(size_t bytes, size_t alignment,
{
ASSERT(hasOneBitSet(alignment) && alignment >= pageSize());
- if (VirtualAlloc2Ptr()) {
+ if (WK_VirtualAlloc2Ptr()) {
MEM_ADDRESS_REQUIREMENTS addressReqs = { };
MEM_EXTENDED_PARAMETER param = { };
addressReqs.Alignment = alignment;
param.Type = MemExtendedParameterAddressRequirements;
param.Pointer = &addressReqs;
- void* result = VirtualAlloc2Ptr()(nullptr, address, bytes, MEM_RESERVE, protection(writable, executable), ¶m, 1);
+ void* result = WK_VirtualAlloc2Ptr()(nullptr, address, bytes, MEM_RESERVE, allocProtection(writable, executable), ¶m, 1);
return result;
}
@@ -79,7 +120,9 @@ void* OSAllocator::tryReserveUncommittedAligned(size_t bytes, size_t alignment,
void* OSAllocator::tryReserveAndCommit(size_t bytes, Usage, void* address, bool writable, bool executable, bool, unsigned)
{
- return VirtualAlloc(address, bytes, MEM_RESERVE | MEM_COMMIT, protection(writable, executable));
+ void* result = WK_VirtualAlloc(address, bytes, MEM_RESERVE | MEM_COMMIT, allocProtection(writable, executable));
+ applyExecutableProtection(result, bytes, writable, executable); // App Container:提交后翻可执行
+ return result;
}
void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, void* address, bool writable, bool executable, bool jitCageEnabled, unsigned numGuardPagesToAddOnEachEnd)
@@ -91,9 +134,10 @@ void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, void* address, bo
void OSAllocator::commit(void* address, size_t bytes, bool writable, bool executable)
{
- void* result = VirtualAlloc(address, bytes, MEM_COMMIT, protection(writable, executable));
+ void* result = WK_VirtualAlloc(address, bytes, MEM_COMMIT, allocProtection(writable, executable));
if (!result)
CRASH();
+ applyExecutableProtection(address, bytes, writable, executable); // App Container:提交后翻可执行
}
void OSAllocator::decommit(void* address, size_t bytes)
@@ -108,13 +152,15 @@ void OSAllocator::decommit(void* address, size_t bytes)
// So, we need VirtualUnlock call.
if (!bytes)
return;
- void* result = VirtualAlloc(address, bytes, MEM_RESET, PAGE_READWRITE);
+ void* result = WK_VirtualAlloc(address, bytes, MEM_RESET, PAGE_READWRITE);
if (!result)
CRASH();
// Calling VirtualUnlock on a range of memory that is not locked releases the pages from the
// process's working set.
// https://devblogs.microsoft.com/oldnewthing/20170317-00/?p=95755
- VirtualUnlock(address, bytes);
+#if !defined(WK_WINUWP)
+ VirtualUnlock(address, bytes); // 桌面专用; App Container 无此 API(MEM_RESET 已 decommit)
+#endif
}
void OSAllocator::releaseDecommitted(void* address, size_t bytes, unsigned)
@@ -148,7 +194,7 @@ bool OSAllocator::tryProtect(void* address, size_t bytes, bool readable, bool wr
ASSERT(!readable && !writable);
protection = PAGE_NOACCESS;
}
- return VirtualAlloc(address, bytes, MEM_COMMIT, protection);
+ return WK_VirtualAlloc(address, bytes, MEM_COMMIT, protection);
}
void OSAllocator::protect(void* address, size_t bytes, bool readable, bool writable)
diff --git a/Source/WTF/wtf/win/SignalsWin.cpp b/Source/WTF/wtf/win/SignalsWin.cpp
index 28be55d821..c8c034a412 100644
--- a/Source/WTF/wtf/win/SignalsWin.cpp
+++ b/Source/WTF/wtf/win/SignalsWin.cpp
@@ -152,7 +152,11 @@ void SignalHandlers::finalize()
for (unsigned i = 0; i < numberOfSignals; ++i) {
if (handlers.numberOfHandlers[i]) {
- AddVectoredExceptionHandler(1, vectoredHandler);
+#if !defined(WK_WINUWP)
+ AddVectoredExceptionHandler(1, vectoredHandler); // App Container 无 VEH; 无 JIT/Wasm 故无需信号
+#else
+ UNUSED_VARIABLE(vectoredHandler);
+#endif
break;
}
}
diff --git a/Source/WTF/wtf/win/ThreadingWin.cpp b/Source/WTF/wtf/win/ThreadingWin.cpp
index 9c944ea631..9559f15dfa 100644
--- a/Source/WTF/wtf/win/ThreadingWin.cpp
+++ b/Source/WTF/wtf/win/ThreadingWin.cpp
@@ -130,9 +130,14 @@ void Thread::initializeCurrentThreadInternal(const char* szThreadName)
info.dwThreadID = GetCurrentThreadId();
info.dwFlags = 0;
+#if !defined(WK_WINUWP)
+ // SEH 的 __try clang ARM32 不支持; 这只是给调试器命名线程的旧把戏, UWP 跳过。
__try {
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), reinterpret_cast<ULONG_PTR*>(&info));
} __except(EXCEPTION_CONTINUE_EXECUTION) { }
+#else
+ (void)info;
+#endif
initializeCurrentThreadEvenIfNonWTFCreated();
}
diff --git a/Source/WebCore/accessibility/AccessibilityObject.cpp b/Source/WebCore/accessibility/AccessibilityObject.cpp
index e16097e52e..9d379aca7c 100644
--- a/Source/WebCore/accessibility/AccessibilityObject.cpp
+++ b/Source/WebCore/accessibility/AccessibilityObject.cpp
@@ -2709,7 +2709,7 @@ struct RoleEntry {
AccessibilityRole webcoreRole;
};
-static void initializeRoleMap()
+static void initializeAriaRoleMaps()
{
if (gAriaRoleMap)
return;
@@ -2875,13 +2875,13 @@ static void initializeRoleMap()
static ARIARoleMap& ariaRoleMap()
{
- initializeRoleMap();
+ initializeAriaRoleMaps();
return *gAriaRoleMap;
}