17
17
#include "perl.h"
18
18
#include "XSUB.h"
19
19
#define CROAK croak
20
- #include <emmintrin.h>
20
+ // #include <emmintrin.h>
21
21
#include "API.h"
22
22
23
23
/*
@@ -75,7 +75,16 @@ BOOL WINAPI _DllMainCRTStartup(
75
75
}
76
76
#endif
77
77
78
- const static struct {
78
+ #ifdef _MSC_VER
79
+ extern __declspec(selectany ) /*enable comdat folding for this symbol in msvc*/
80
+ #endif
81
+ PORTALIGN (1 ) const char bad_esp_msg [] = "Win32::API a function was called with the wrong prototype "
82
+ "and caused a C stack inconsistency EBP=%p ESP=%p" ;
83
+
84
+ #ifdef _MSC_VER
85
+ extern __declspec(selectany ) /*enable comdat folding for this symbol in msvc*/
86
+ #endif
87
+ PORTALIGN (1 ) const struct {
79
88
char Unpack [sizeof ("Win32::API::Type::Unpack" )];
80
89
char Pack [sizeof ("Win32::API::Type::Pack" )];
81
90
char ck_type [sizeof ("Win32::API::Struct::ck_type" )];
@@ -106,9 +115,6 @@ STATIC SV * getTarg(pTHX) {
106
115
return TARG ;
107
116
}
108
117
109
- const char bad_esp_msg [] = "Win32::API a function was called with the wrong prototype "
110
- "and cause a C stack inconsistency EBP=%" UVxf " EBP=%" UVxf ;
111
-
112
118
/* Convert wide character string to mortal SV. Use UTF8 encoding
113
119
* if the string cannot be represented in the system codepage.
114
120
* If wlen isn't -1 (calculate length), wlen must include the null wchar
@@ -171,59 +177,6 @@ STATIC void w32sv_setwstr(pTHX_ SV * sv, WCHAR *wstr, INT_PTR wlenparam) {
171
177
}
172
178
if (tempwstr ) Safefree (tempwstr );
173
179
}
174
- /* bitfield is 4 bytes, low to high diagram\|/
175
- char flags, short stackunwind, char outType
176
- note the stackunwind is unaligned
177
- */
178
-
179
- #define CTRL_IS_MORE 0x10
180
- #define CTRL_HAS_PROTO 0x20
181
- typedef struct {
182
- union {
183
- struct {
184
- unsigned int convention : 3 ;
185
- unsigned int UseMI64 : 1 ;
186
- unsigned int is_more : 1 ;
187
- unsigned int has_proto : 1 ;
188
- #ifndef _WIN64
189
- unsigned int reserved : 2 ;
190
- /* remember to change Call_asm in API::Call() if this is changed */
191
- unsigned int stackunwind : 16 ;
192
- #else
193
- unsigned int reserved : 18 ;
194
- #endif
195
- unsigned int out : 8 ;
196
- };
197
- U32 whole_bf ;
198
- };
199
- U16 inparamlen ;
200
- /* padding hole here, 2 bytes, 32 and 64*/
201
- FARPROC ApiFunction ;
202
- SV * api ; /* a non-ref counted weak RV to the blessed SVPV that holds
203
- APICONTROL, used to optimize method calls on the API obj, the
204
- refcount for the RV is stored in the obj's hidden hash*/
205
- /* this AV is here for no func call look up of it, intypes may be NULL*/
206
- AV * intypes ;
207
- /* a padding hole here of unknown size */
208
- __declspec(align (16 )) APIPARAM param ;
209
- } APICONTROL ;
210
-
211
- #define APICONTROL_CC_STD 0
212
- #define APICONTROL_CC_C 1
213
- //fastcall, thiscall, regcall, will go here
214
-
215
- typedef struct {
216
- /* on 32bit win, HeapAlloc granularity is 8 bytes, if you request less than
217
- size%8 == 0 request is rounded upto next 8, lets assume that
218
- struct perl_memory_debug_header, the HE, and HEK (all if applicable), will
219
- be some multiple of 4 on 32bit windows, since the string is null terminated
220
- even on pre-HEK stash name Perls (< 5.9.3), there are atleast 4 bytes
221
- readable at all times for HvNAME. */
222
- DWORD32 MagicLow ;
223
- DWORD32 MagicHigh ;
224
- DWORD_PTR EncodedPtr ; /* nullless XOR encrypted APICONTROL */
225
- DWORD_PTR PtrKey ; /* key to decrypt above ptr */
226
- } APICLASSNAME ;
227
180
228
181
#if defined(_M_AMD64 ) || defined(__x86_64 )
229
182
#include "call_x86_64.h"
@@ -273,7 +226,7 @@ const static struct {
273
226
STATIC SV * getMgSV (pTHX_ SV * sv ) {
274
227
MAGIC * mg ;
275
228
if (SvRMAGICAL (sv )) { /* implies SvTYPE >= SVt_PVMG */
276
- mg = mg_findext (sv , PERL_MAGIC_ext , & vtbl_API );
229
+ mg = mg_findext (sv , PERL_MAGIC_ext , ( const MGVTBL * const ) & vtbl_API );
277
230
if (mg ) {
278
231
return mg -> mg_obj ;
279
232
}
@@ -286,7 +239,7 @@ STATIC SV * getMgSV(pTHX_ SV * sv) {
286
239
STATIC void setMgSV (pTHX_ SV * sv , SV * newsv ) {
287
240
MAGIC * mg ;
288
241
if (SvRMAGICAL (sv )) { /* implies SvTYPE >= SVt_PVMG */
289
- mg = mg_findext (sv , PERL_MAGIC_ext , & vtbl_API );
242
+ mg = mg_findext (sv , PERL_MAGIC_ext , ( const MGVTBL * const ) & vtbl_API );
290
243
if (mg ) {
291
244
SV * oldsv ;
292
245
SvREFCNT_inc_simple_void_NN (newsv );
@@ -299,7 +252,7 @@ STATIC void setMgSV(pTHX_ SV * sv, SV * newsv) {
299
252
}
300
253
else {
301
254
addmg :
302
- sv_magicext (sv ,newsv ,PERL_MAGIC_ext ,& vtbl_API ,NULL ,0 );
255
+ sv_magicext (sv ,newsv ,PERL_MAGIC_ext ,( const MGVTBL * const ) & vtbl_API ,NULL ,0 );
303
256
}
304
257
}
305
258
@@ -368,6 +321,9 @@ BOOT:
368
321
unsigned char len ;
369
322
unsigned char constval ;
370
323
} CONSTREG ;
324
+ #pragma pack(push)
325
+ #pragma pack(push, 1)
326
+ PORTALIGN (1 )
371
327
static const struct {
372
328
#define XMM (y ) CONSTREG cr_##y; char arr_##y [sizeof(#y)];
373
329
XMM (T_VOID )
@@ -415,6 +371,8 @@ BOOT:
415
371
XMM (T_FLAG_NUMERIC )
416
372
#undef XMM
417
373
};
374
+ #pragma pack (pop )
375
+ #pragma pack (pop )
418
376
CONSTREG * entry = (CONSTREG * )& const_init ;
419
377
while ((DWORD_PTR )entry < (DWORD_PTR )& const_init + sizeof (const_init )){
420
378
newCONSTSUB (stash , (char * )((DWORD_PTR )entry + sizeof (CONSTREG )), newSVuv (entry -> constval ));
@@ -809,11 +767,6 @@ void
809
767
_ImportXS (...)
810
768
PREINIT :
811
769
char * subname ;
812
- #ifdef W32A_SPLITHEAD
813
- XS_EUPXS (XS_Win32__API_ImportCall );
814
- #else
815
- XS_EUPXS (XS_Win32__API_Call );
816
- #endif
817
770
#if (PERL_REVISION == 5 && PERL_VERSION < 9 )
818
771
char * file = __FILE__ ;
819
772
#else
@@ -827,11 +780,7 @@ CODE:
827
780
subname = SvPVX (sv ); }
828
781
{ SV * api = POPs ;
829
782
PUTBACK ;
830
- #ifdef W32A_SPLITHEAD
831
783
{ CV * cv = newXS (subname , XS_Win32__API_ImportCall , file );
832
- #else
833
- { CV * cv = newXS (subname , XS_Win32__API_Call , file );
834
- #endif
835
784
XSANY .any_ptr = (APICONTROL * ) SvPVX (SvRV (api ));
836
785
setMgSV (aTHX_ (SV * )cv , api ); }}
837
786
return ;
@@ -863,3 +812,24 @@ PPCODE:
863
812
croak ("bad alignment" );
864
813
#endif
865
814
return ;
815
+
816
+ #ifdef WIN32_API_PROF
817
+ void
818
+ _DumpTimes ()
819
+ CODE :
820
+ printf ("dumptimes start %I64u loopprep %I64u loopstart %I64u Call_asm_b4 %I64u Call_asm_after %I64u rtn_time\n" ,
821
+ start_loopprep .QuadPart , loopprep_loopstart .QuadPart , loopstart_Call_asm_b4 .QuadPart , Call_asm_b4_Call_asm_after .QuadPart , Call_asm_after_return_time .QuadPart );
822
+
823
+ #endif
824
+
825
+ #ifdef WIN32_API_PROF
826
+ void
827
+ _ResetTimes ()
828
+ CODE :
829
+ start_loopprep .QuadPart = 0 ,
830
+ loopprep_loopstart .QuadPart = 0 ,
831
+ loopstart_Call_asm_b4 .QuadPart = 0 ,
832
+ Call_asm_b4_Call_asm_after .QuadPart = 0 ,
833
+ Call_asm_after_return_time .QuadPart = 0 ;
834
+
835
+ #endif
0 commit comments