summaryrefslogtreecommitdiff
path: root/win32/win32.c
Commit message (Collapse)AuthorAgeFilesLines
* Restore build with some mingw.org compilers using mingw runtimes >= 3.21Steve Hay2021-01-261-1/+3
| | | | | | | | | | | | | | | | | | | | | | | MinGW runtime version 3.21 added a definition of mkstemp(), so requires a fix similar to f33b2f5852 for MinGW-w64's runtime 4.0 onwards. Based on a patch by Dan Collins on GH#15446. This commit also tweaks 43b3b04375, having discovered that mingw runtime 3.22 also contains a definition of timespec. For me, this fixes the build with my mingw.org 5.3.0 compiler using any of the mingw runtimes 3.21, 3.22.4 or 5.0 without breaking older versions such as 4.9.3 with the 3.20 runtime (or even with the withdrawn 4.0.3 runtime, which had __MINGW32_MAJOR/MINOR_VERSION set to 3.20 whilst adding new a __MINGW_MAJOR/MINOR_VERSION set to 4.0). However, 6.3.0 and 7.3.0 have other issues when compiling win32sck.c, while 8.2.0 and 9.2.0 have other issues again when compiling win32.c. See GH#18510 for more details. Also, C++ mode builds with some MinGW/MinGW-w64 compilers are still broken, as documented in 8a217c9aa7. See GH#16459 for more details.
* style: Detabify indentation of the C code maintained by the core.Michael G. Schwern2021-01-171-1185/+1185
| | | | | | | | | | | This just detabifies to get rid of the mixed tab/space indentation. Applying consistent indentation and dealing with other tabs are another issue. Done with `expand -i`. * vutil.* left alone, it's part of version. * Left regen managed files alone for now.
* win32 symlink: reindentTony Cook2020-12-011-33/+34
|
* win32 symlink: treats paths that look like directories as directoriesTony Cook2020-12-011-5/+23
|
* Win32: try to make the new stat pre-Vista compatibleTony Cook2020-12-011-1/+15
| | | | | | | | Skips the win32\stat.t execute flag test for handles pre-Vista This is intended mostly for allowing the Win2000 smoker to build and test. If we end up dropping pre-Vista support this commit can be removed (or reverted if it ends up in blead)
* pre-vista support for win32_symlinkTony Cook2020-12-011-1/+14
|
* lstat(), readlink() and unlink() treat directory junctions as symlinksTony Cook2020-12-011-18/+46
|
* remove ${^WIN32_SLOPPY_STAT}Tony Cook2020-12-011-6/+0
| | | | | The new implementation, like the UCRT implementation, always opens the specified file.
* win32 symlink: only use the unprivileged flag if windows is new enoughTony Cook2020-12-011-1/+9
|
* Win32: re-work FILETIME <=> time_t conversionsTony Cook2020-12-011-15/+41
| | | | | | | | | Current versions of Windows claim to support leap seconds, but the time conversion I was using ignores that possibility. Switch to using APIs (FileTimeToSystemTime() and SystemTimeToFileTime()) that are documented to support leap seconds that might be included in a FILETIME.
* Win32: implement our own stat(), and hence our own utimeTony Cook2020-12-011-209/+188
| | | | | | | | | | | | | | | | | | | | | | | This fixes at least two problems: - unlike UCRT, the MSVCRT used for gcc builds has a bug converting a FILETIME in an unlike current DST state, returning a time offset by an hour. Fixes GH #6080 - the MSVCRT apparently uses FindFirstFile() to fetch file information, but this doesn't follow symlinks(), so stat() ends up returning information about the symlink(), not the underlying file. This isn't an issue with the UCRT which opens the file as this implementation does. Currently this code calculates the time_t for st_*time, and the other way for utime() using a simple multiplication and offset between time_t and FILETIME values, but this may be incorrect if leap seconds are enabled. This code also requires Vista or later. Some of this is based on code by Tomasz Konojacki (xenu).
* Win32: implement symlink() and readlink()Tony Cook2020-12-011-36/+147
| | | | | | | | The API used requires Windows Vista or later. The API itself requires either elevated privileges or a sufficiently recent version of Windows 10 running in "Developer Mode", so some tests require updates.
* Win32: add lstat(), fetch st_dev and st_ino and fetch st_nlink for fstatTony Cook2020-12-011-4/+195
| | | | | | | | | | | | | | | We need lstat() for various modules to work well with symlinks, and the same modules often want to check for matches on the device and inode number. The values we're using for st_ino match those that the Python and Rust libraries use, and Go uses the same volume and file index values for testing if two stat objects refer to the same file. They aren't entirely unique, given ReFS uses 128-bit file ids, but the API used to check for this (GetFileInformationByHandleEx() for FileIdInfo) is only available on server operating systems, so I can't directly test it anyway.
* win32: remove support for disabling USE_LARGE_FILESTomasz Konojacki2020-11-221-28/+0
| | | | | It was enabled by default on all compilers. I don't think it ever makes sense to disable it.
* win32.c: rework the waitpid(-1, WNOHANG) fixTomasz Konojacki2020-07-241-4/+7
| | | | | | | | | | Oops! While 08e55ec5e3ef6d6c040c0dc8bdec7d59f76bfbe8 made waitpid(-1, WNOHANG) not segfault, it introduced another problem: when retry == 1, MsgWaitForMultipleObjects() will sometimes be called with a very large timeout due to unsigned integer overflow. This is *exactly* the same problem that the comment above the loop warns about.
* Remove use of dVAR in coreDagfinn Ilmari Mannsåker2020-07-201-4/+0
| | | | | It only does anything under PERL_GLOBAL_STRUCT, which is gone. Keep the dNOOP defintion for CPAN back-compat
* Fix a bunch of repeated-word typosDagfinn Ilmari Mannsåker2020-05-221-1/+1
| | | | | Mostly in comments and docs, but some in diagnostic messages and one case of 'or die die'.
* Remove spurious double spaces before open braces in core C codeDagfinn Ilmari Mannsåker2020-04-131-1/+1
|
* Add mutex for accessing ENVKarl Williamson2020-03-111-0/+1
|
* win32/win32.c: Use inRANGE macroKarl Williamson2019-12-261-1/+1
| | | | which is more efficient.
* Convert issue links from rt.perl.org to GitHubDan Book2019-11-261-1/+1
|
* win32: Add more missing wchar.h includesDagfinn Ilmari Mannsåker2019-11-151-0/+1
|
* win32: fix waitpid(-1, WNOHANG) segfault/panicTomasz Konojacki2019-11-101-1/+4
| | | | | | | | | waitpid(-1, WNOHANG) would panic or segfault if called when the thread's message queue is not empty. Thanks to Erik Jezierski for the report and diagnosis. [gh #16529]
* (perl #134221) support append mode temp files on Win32 tooTony Cook2019-07-161-1/+9
|
* add dVAR's for PERL_GLOBAL_STRUCT_PRIVATE buildsDavid Mitchell2019-02-191-0/+5
| | | | | | The perl build option -DPERL_GLOBAL_STRUCT_PRIVATE had bit-rotted due to lack of smoking. The main fix is to just add 'dVAR;' to any functions which have a pTHX arg. It's a NOOP on normal builds.
* Use sv_catpvs where appropriate vs sv_catpvKarl Williamson2018-08-061-1/+1
| | | | | This moves calculations definitely to compile time; some optimizing compilers may already do this, but some may not.
* win32: fix argumentless sleep()Tomasz Konojacki2018-08-011-0/+8
| | | | | | | | | | | | | | Before this commit, pause() was implemented as a macro calling win32_sleep((32767L << 16) + 32767), which was causing the following problems with argumentless sleep(): - it was sleeping for 4262198 seconds (~50 days) instead of forever - it was triggering "sleep(2147450879) too large" warning This commit implements pause() as a proper function which calls win32_msgwait() with an INFINITE timeout. [perl #133376]
* avoid reading errno twice in a rowZefram2017-11-111-1/+2
| | | | | Reading errno can involve calling a function and indirecting through its result, so cache the value of errno where possible. [perl #122096]
* Change some strncmp(), etc. to strBEGINs()Karl Williamson2017-11-061-1/+1
| | | | | The latter is much clearer as to what's going on, and the programmer and program reader don't have to count characters.
* Convert strncmp into strnEQ, strnNEKarl Williamson2017-10-241-2/+2
| | | | | | | The new versions are much easier to comprehend. There are several cases in vms.c where strEQ and strNE suffice, instead of having to have a count parameter.
* Convert strcmp into strEQ, strNEKarl Williamson2017-10-241-1/+1
| | | | The latter two are easier to read
* WIN32: update size after RenewHugo van der Sanden2017-03-151-1/+1
| | | | | | RT #130841 Setting it before Renew can cause problems if the Renew fails.
* Add support for VS2015 (VC++ 14.0)Steve Hay2017-02-191-3/+3
| | | | | | | | | | | | | | | Due to the rewritten CRT in this version of Visual C++ it is no longer possible (or at least not at all easy) to make use of the ioinfo struct, which commit b47a847f62 (re-)introduced in order to fix RT#120091/118059. Therefore, we effectively revert commit b47a847f62 for VS2015 onwards on the basis that being able to build with VS2015 onwards is more important than the RT#120091/118059 bug fix. This does unfortunately mean that perls built with <=VS2013 will not be compatible with perls built with >=VS2015, but they may well not have been compatible anyway because of the CRT rewrite, and certainly wouldn't be compatible if perl builds with VS2015 were not supported! See RT#125714 for more discussion about this.
* Add locale mutexKarl Williamson2016-04-091-0/+1
| | | | | This adds a new mutex for use in the next commit for use with locale handling.
* add shortcut around syscalls when file not found in win32_statDaniel Dragan2016-02-111-0/+8
| | | | | | | | | | | | | | | win32_stat on success makes ~7 system calls, some from perl, some from CRT, but on failure, typically file not found, the perl syscalls fails, then the CRT stat runs, and fails too, so 5 mostly failing system calls are done for file not found. If the perl syscall says file not found, the file wont magically come into existence in the next 10-1000 us for the CRT's syscalls, so skip calling the CRT and the additional syscalls if the perl didn't find the file. This patch reduces the number of syscalls from 5 to 1 for file not found for a win32 perl stat. Benchmark and profiling info is attached to RT ticket for this patch. Note CreateFile on a dir fails with ERROR_ACCESS_DENIED so in some cases, a failed CreateFile is still a successful CRT stat() which does things differently so dirs can be opened.
* give Win32 miniperl a real getcwd for build perfDaniel Dragan2016-01-071-0/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | getcwd() is now 605x faster for Win32 miniperl. ------------------------------ use Cwd; Cwd::getcwd() for(0..10000); ------------------------------ before C:\p523\src\win32>timeit -f t.dat ..\miniperl -I..\lib t.pl Version Number: Windows NT 6.1 (Build 7601) Exit Time: 2:03 am, Thursday, December 10 2015 Elapsed Time: 0:01:12.438 Process Time: 0:00:14.289 System Calls: 5802378 Context Switches: 1455066 Page Faults: 5250724 Bytes Read: 76809789 Bytes Written: 5278717 Bytes Other: 10407004 after C:\p523\src\win32>timeit -f t.dat ..\miniperl -I..\lib t.pl Version Number: Windows NT 6.1 (Build 7601) Exit Time: 1:20 am, Thursday, December 10 2015 Elapsed Time: 0:00:00.119 Process Time: 0:00:00.124 System Calls: 4658 Context Switches: 540 Page Faults: 1127 Bytes Read: 99074 Bytes Written: 0 Bytes Other: 12888
* reimplement $^WIN32_SLOPPY_STAT as a magic varDaniel Dragan2015-10-191-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The original implementation in commit cba61fe146 was sloppy. It is named like a special var, it is listed as a special var, but it was a regular GV. Since nobody knows this var exists, and full stat is the default (which I disagree with see below). There will be alot more PP and C/XS perl stat() calls (atleast a couple to dozens or low 100s for short lived perl processes) than reads/writes to this global scalar (rounded to 0 R/Ws) in a Win32 perl process. So avoid the 1 usually failing GV package (hash) lookup for each PP/XS/PL C stat by using magic vars and a C bool. This is a perf increase. Use sv_true instead of SvTRUE_NN because this code is extremely rare to execute and the macro has large machine code. I disagree with the default being full stat with since this increases the number of kernel IO calls and ASCII->UTF16 conversions, and there was perf criticism in the original thread that implemented this this http://www.nntp.perl.org/group/perl.perl5.porters/2006/02/msg109917.html but why full stat is default is for another ticket. This patch lessens the overhead of full stat until something else is decided. Change the initial value of the sloppystat setting for miniperl to be true instead of doing it in buildcustomize.pl in PP. Revert part of commit 8ce7a7e8b0 "speed up miniperl require on Win32" to acomplish this. Unlike Unix perl, no object files are shared between mini and full perl, so changing the default is fine on Win32 Perl. If minitest/miniperl really need hard link testing/support, they can explictly turn off sloppy stat and enable full stat with the special var. Changing the stat default from C for miniperl avoids creating the special GV on each miniperl process start as it previously was with the buildcustomize.pl way. Changing stat setting in C and not PP also saves a couple IO calls in win32_stat when opening the first .pl if it isn't -e, and opening buildcustomize.pl in all permutations. The PP code in S_parse_body contains a -f. See ticket for this patch for details. Only CPAN use of this special var is File-Stat-Moose-0.06/lib/File/Stat/Moose.pm#L208 according to cpangrep.
* add Win32 USE_NO_REGISTRY build optionDaniel Dragan2015-10-121-7/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -the first arg of win32_get_privlib is not used if the registry is not queried, create a macro to allow the arg to drop out on WIN32_NO_REGISTRY builds for efficiency and not to have unused C litteral strings in the binary -This patch changes the ABI of PerlEnv_lib_path/PerlEnvLibPath/win32_get_privlib between USE_NO_REGISTRY and no USE_NO_REGISTRY. Since win32_get_privlib is not exported from perl523.dll, assume it and PerlEnv_lib_path are not public API, note technically PerlEnv_lib_path will be callable only on PERL_IMPLICIT_SYS builds, on no PERL_IMPLICIT_SYS builds it will fail at link time since win32_get_privlib isnt exported. Therefore place it in non-[affecting]-binary compatibility even though it does affect binary compatibility. -delay load advapi32.dll to save startup time (loading the DLL and the DLL calling its initializers in DllMain) and one 4 KB memory page for advapi32's .data section (doing "perl -E"sleep 100" on WinXP shows advapi32 has a 20KB long .data section, first 4 KB are unique to the process, the remaining 16KB are COW shared between processes according to vmmap tool), putting a DebugBreak() in pp_getlogin and doing a "nmake all" shows miniperl never calls getlogin during the build process. An nmake test shows only ext/POSIX/t/wrappers.t and lib/warnings.t execute pp_getlogin. Keeping advapi32.dll out of the perl process requires removing comctl32.dll, since comctrl32.dll loads advapi32.dll, from perl which I always do as a custom patch. filed as [perl #123658] XXXXXXXXXXXXXXXXXXXXXXX
* stop checking the Win32 registry if *"/Software/Perl" doesn't existDaniel Dragan2015-10-121-24/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This stops each ENV var lookup (and 16 calls to get_regstr, most of which are %ENV lookups, are done automatically each time a Win32 Perl process starts) from querying the registry for usually failing lookups. ActiveState is the only known major user of the Software/Perl reg key. details: -cache the root handles, so a typically failing env var lookup does only 1 system call instead of 3 if the parent key exists -if the key exists, looking it up is slightly faster since it is 4 registry syscall instead of previously 6 (open "*\Software\Perl", 2 RegQueryValueExAs(on "found" behavior each RegQueryValueExA does 2 RegQueryValueExW calls), close "*\Software\Perl") -dont make a system call to lookup a value if the parent key doesn't exist -change "Software\\Perl" to "SOFTWARE\\Perl" since the reg is case preserving but lookups are not case sensitive, this all caps casing is what regedit shows, and might save a couple cpu cycles in the DB lookup in the kernel -use RegOpenKeyExW instead of RegOpenKeyEx (actually RegOpenKeyExA), this avoids ansi to utf16 conversions at runtime -dont check HKEY handles for NULL before calling RegCloseKey. MS and ReactOS RegCloseKey checks for NULL (zero) handle first thing and returns ERROR_INVALID_HANDLE as the retval of RegCloseKey. MS App Verifier does not complain about NULL handles. -Dont check the retval of RegCloseKey, there is no way to dispatch an error at this point in the process, there are no interps, and no perlio, and maybe no console if its a GUI, and the process is probably exiting anyway. Calling Perl_noperl_die (no perl, no perlio, print to stderr) would not be friendly to an embedder. A crash box with RaiseException with EXCEPTION_INVALID_HANDLE is a bad UI. -Dont bother to zero the HKEY handles, after a PERL_SYS_TERM until the next (if any) PERL_SYS_INIT3, libperl is in an undefined state, it is the embedders responsibility to refcount and serialize calls to PERL_SYS_INIT3/PERL_SYS_TERM if necessary See details in [perl #123658]
* Remove PERLIO_IS_STDIO from win32.c and wince.c.Craig A. Berry2015-07-231-3/+2
| | | | | It will never be defined so there's no reason to check that it's not defined.
* ensure chdir('') sets $! to ENOENT on non-IMP_SYS Win32 buildsTony Cook2015-06-181-1/+1
|
* refactor win32_get_*lib() funcs to match rest of PERL_IMPLICIT_SYS APIDaniel Dragan2015-06-031-6/+0
| | | | | | | | | | | | | | | | | | The front end of PERL_IMPLICIT_SYS is PerlEnv_*/PerlSock_*/PerlProc_*/etc macros. These are either macroed to C vtable calls when PERL_IMPLICIT_SYS is on, or to the backend raw win32_*() functions when PERL_IMPLICIT_SYS is off. win32_get_*() were not following this convention. All this code looks like a hack as if someone didn't have perms to edit perl.c, but they did have perms to edit /win32, so they devise a scheme of hooking "unhooked" win32_get_*() functions with win32.h macros for win32_get_*() to call the Perl*() virutalization macros, and rename the original function bodies in win32.c to g_win32_get_*() as to not make a macro loop. Undo all of this hack by having perl.c call correct PerlEnv_* macro. This refactoring will be useful for a future patch in #123658 to disable win32 registry lookups.
* handle existing mkstemp() in mingw-w64-v4KMX2015-05-211-0/+2
|
* remove the shell fallback from list pipe open on Win32Tony Cook2015-02-101-17/+27
| | | | | | | | | | This is a potential security issue, and while we'd need a deprecation cycle to remove it from system(), there hasn't been a production release of perl with list pipe open, so we can pretend it never was. Without the shell, CreateProcess() won't pick up .cmd or .bat files, which several perl utilities are packaged as on Win32, so use qualified_path() to produce a full executable name.
* Corrections to spelling and grammatical errors.Lajos Veres2015-01-281-2/+2
| | | | Extracted from patch submitted by Lajos Veres in RT #123693.
* Remove sources of "unreferenced label" warning on Win32Steve Hay2014-12-311-1/+0
| | | | and then remove the disabling of that warning.
* win32/win32.c Perl_croak->croak_xs_usageDaniel Dragan2014-12-261-1/+1
| | | | | When this XSUB was written croak_xs_usage didn't exist. Now it does. Use it so the error string is shorter in the perl binary.
* Fix compilation errors in win32.c with MinGW/gcc -xc++Steve Hay2014-12-241-4/+4
| | | | | | | | | | | | | | | | | | | | | In MinGW-w64 builds, there are warnings/errors like this (depending on the compiler version used): gcc-4.5.3: warning: passing argument 2 of 'execv' from incompatible pointer type gcc-4.8.0: error: invalid conversion from 'const char* const*' to 'char* const*' This happens because MinGW-w64's process.h declares execv/execvp's second argument as 'char * const*' instead of 'const char * const*'. The _execv/_execvp versions don't have this problem so use them instead. MSDN says execv/execvp are deprecated POSIX functions; use the ISO C++ conformant _execv/_execvp instead anyway so it is not even worth sticking with execv/execvp for those compilers (namely, MinGW and VC++) that have the correct declarations. Likewise with spawnv/spawnvp vs. _spawnv/_spawnvp.
* implement list form of pipe open for Win32Tony Cook2014-10-221-17/+49
|
* Change sv_catpvn(…, "…", …) to sv_catpvs(…, "…")Dagfinn Ilmari Mannsåker2014-06-121-2/+2
| | | | | The dual-life dist affected uses Devel::PPPort, so can safely use sv_catpvs() even though it wasn't added until Perl v5.8.9.