@@ -2317,6 +2317,21 @@ typedef struct {
#endif
/* License: Ruby's */
+#if RUBY_MSVCRT_VERSION >= 140
+typedef struct {
+ CRITICAL_SECTION lock;
+ intptr_t osfhnd; // underlying OS file HANDLE
+ __int64 startpos; // File position that matches buffer start
+ unsigned char osfile; // Attributes of file (e.g., open in text mode?)
+ char textmode;
+ char _pipe_lookahead;
+
+ uint8_t unicode : 1 ; // Was the file opened as unicode?
+ uint8_t utf8translations : 1 ; // Buffer contains translations other than CRLF
+ uint8_t dbcsBufferUsed : 1 ; // Is the dbcsBuffer in use?
+ char dbcsBuffer; // Buffer for the lead byte of DBCS when converting from DBCS to Unicode
+} ioinfo;
+#else
typedef struct {
intptr_t osfhnd; /* underlying OS file HANDLE */
char osfile; /* attributes of file (e.g., open in text mode?) */
@@ -2328,16 +2343,22 @@ typedef struct {
char pipech2[2 ];
#endif
} ioinfo;
+#endif
#if !defined _CRTIMP || defined __MINGW32__
#undef _CRTIMP
#define _CRTIMP __declspec (dllimport)
#endif
+#if RUBY_MSVCRT_VERSION >= 140
+static ioinfo ** __pioinfo = NULL ;
+#define IOINFO_L2E 6
+#else
EXTERN_C _CRTIMP ioinfo * __pioinfo[];
+#define IOINFO_L2E 5
+#endif
static inline ioinfo* _pioinfo (int );
-#define IOINFO_L2E 5
#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
#define _osfhnd (i ) (_pioinfo(i)->osfhnd)
#define _osfile (i ) (_pioinfo(i)->osfile)
@@ -2352,6 +2373,39 @@ static size_t pioinfo_extra = 0; /* workaround for VC++8 SP1 */
static void
set_pioinfo_extra (void )
{
+#if RUBY_MSVCRT_VERSION >= 140
+ /* get __pioinfo addr with _isatty */
+ HMODULE mod = GetModuleHandle (" ucrtbase.dll" );
+ char *p = (char *)GetProcAddress (mod, " _isatty" );
+ char *pend = p + 100 ;
+ /* _osfile(fh) & FDEV /*0x40*/
+#if _WIN64
+ int32_t rel;
+ char *rip;
+ /* lea rdx,[__pioinfo's addr in RIP-relative 32bit addr] */
+# define PIOINFO_MARK " \x48\x8d\x15 "
+#else
+ /* mov eax,dword ptr [eax*4+100EB430h] */
+# define PIOINFO_MARK " \x8B\x04\x85 "
+#endif
+ for (p; p < pend; p++) {
+ if (memcmp (p, PIOINFO_MARK, strlen (PIOINFO_MARK)) == 0 ) {
+ goto found;
+ }
+ }
+ fprintf (stderr, " unexpected ucrtbase.dll\n " );
+ _exit (1 );
+
+ found:
+ p += strlen (PIOINFO_MARK);
+#if _WIN64
+ rel = *(int32_t *)(p);
+ rip = p + sizeof (int32_t );
+ __pioinfo = (ioinfo**)(rip + rel);
+#else
+ __pioinfo = (ioinfo**)(p);
+#endif
+#else
int fd;
fd = _open (" NUL" , O_RDONLY);
@@ -2366,6 +2420,7 @@ set_pioinfo_extra(void)
/* not found, maybe something wrong... */
pioinfo_extra = 0 ;
}
+#endif
}
#else
#define pioinfo_extra 0
0 comments on commit
9afc312