Subject: Re: bug#60996: 29.0.60; Native compile fails to remove temp file for trampoline

From: Andy Moreton <[email-masked]>
Date: Mon, 23 Jan 2023 02:30:43 +0000

On Sun 22 Jan 2023, Eli Zaretskii wrote:

>> Date: Sat, 21 Jan 2023 22:12:10 +0000
>> From: Andy Moreton <[email-masked]>
>> 
>> Recently emacs 29 (and master) has started showing an error and
>> backtrace during startup:
>> 
>> Debugger entered--Lisp error: (permission-denied "Removing old name" 
>> "Permission denied" "c:/Users/ajm/AppData/Local/Temp/comp-lambda-MTAMbr...")
>> delete-file("c:/Users/ajm/AppData/Local/Temp/comp-lambda-MTAMbr...")
>
> We need a reproducible recipe to investigate this, or results of such
> investigation by you: which code has the file open when we try
> deleting it, and why that other code has it open?
>
> For a recipe, it should be enough to present a minimal init file which
> causes the problem (but pleased make it really minimal: as few lines
> as strictly needed for reproduction)

Agreed, but this appear to be tiing sensitive, so a minimised reproducer
may take a while to reduce down from my init file.

> Btw, "comp-lambda-MTAMbr..." seems to tell that it's some part of
> comp.el, which sounds strange: comp.el is supposed to be
> natively-compiled during the build, and that includes the trampolines
> for it.  Hmm...

>From more expermenting with a debug build in gdb, it seem to be related
to this code in native-elisp-load:

      /* If in this session there was ever a file loaded with this
	 name, rename it before loading, to make sure we always get a
	 new handle!  */
      Lisp_Object tmp_filename =
	Fmake_temp_file_internal (filename, Qnil, build_string (".eln.tmp"),
				  Qnil);
      if (NILP (Ffile_writable_p (tmp_filename)))
	comp_u->handle = dynlib_open_for_eln (SSDATA (encoded_filename));
      else
	{
	  Frename_file (filename, tmp_filename, Qt);
	  comp_u->handle = dynlib_open_for_eln (SSDATA (ENCODE_FILE (tmp_filename)));
	  Frename_file (tmp_filename, filename, Qnil);
	}

The renaming results in the ".eln.tmp" suffixed name having an open
handle. That handle is still open when other code tries to delete
the renamed ".eln" file, which fails.

The attached .csv file shows filesystem activity captured by Process
Monitor for the relevant "...\comp-lambda-*" temp files during emacs
startup. (It may be easier to read if imported into a spreadsheet).

"Time of Day","Process Name","PID","Operation","Path","Result","Detail"
"14:15:21.8965246","emacs.exe","6452","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Generic Read/Write, Disposition: Create, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0, OpenResult: Created"
"14:15:21.8968228","emacs.exe","6452","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.4141153","emacs.exe","7976","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Desired Access: Generic Read/Write, Disposition: Create, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0, OpenResult: Created"
"14:15:24.4143658","emacs.exe","7976","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS",""
"14:15:24.8245971","emacs.exe","7976","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Desired Access: Generic Write, Read Attributes, Disposition: OverwriteIf, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0, OpenResult: Overwritten"
"14:15:24.8248010","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 0, Length: 4,096, Priority: Normal"
"14:15:24.8250025","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 4,096, Length: 4,096, Priority: Normal"
"14:15:24.8251398","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 8,192, Length: 4,096, Priority: Normal"
"14:15:24.8252491","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 12,288, Length: 4,096"
"14:15:24.8253186","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 16,384, Length: 4,096"
"14:15:24.8253869","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 20,480, Length: 4,096"
"14:15:24.8254553","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 24,576, Length: 4,096"
"14:15:24.8255238","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 28,672, Length: 4,096"
"14:15:24.8256255","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 32,768, Length: 4,096, Priority: Normal"
"14:15:24.8257619","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 36,864, Length: 4,096, Priority: Normal"
"14:15:24.8259024","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 40,960, Length: 4,096, Priority: Normal"
"14:15:24.8260399","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 45,056, Length: 4,096, Priority: Normal"
"14:15:24.8261815","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 49,152, Length: 4,096, Priority: Normal"
"14:15:24.8262978","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 53,248, Length: 4,096"
"14:15:24.8263671","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 57,344, Length: 4,096"
"14:15:24.8264377","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 61,440, Length: 4,096"
"14:15:24.8265084","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 65,536, Length: 4,096"
"14:15:24.8265771","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 69,632, Length: 4,096"
"14:15:24.8266454","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 73,728, Length: 4,096"
"14:15:24.8267138","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 77,824, Length: 4,096"
"14:15:24.8267821","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 81,920, Length: 4,096"
"14:15:24.8268504","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 86,016, Length: 4,096"
"14:15:24.8271045","emacs.exe","7976","WriteFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Offset: 90,112, Length: 2,139"
"14:15:24.8271425","emacs.exe","7976","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS",""
"14:15:24.8289434","emacs.exe","7976","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8289892","emacs.exe","7976","QueryBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","CreationTime: 22/01/2023 14:15:21, LastAccessTime: 22/01/2023 14:15:21, LastWriteTime: 22/01/2023 14:15:21, ChangeTime: 22/01/2023 14:15:21, FileAttributes: A"
"14:15:24.8290252","emacs.exe","7976","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8293467","emacs.exe","7976","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8293902","emacs.exe","7976","QueryBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","CreationTime: 22/01/2023 14:15:21, LastAccessTime: 22/01/2023 14:15:21, LastWriteTime: 22/01/2023 14:15:21, ChangeTime: 22/01/2023 14:15:21, FileAttributes: A"
"14:15:24.8294253","emacs.exe","7976","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8297901","emacs.exe","7976","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8298328","emacs.exe","7976","QueryBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","CreationTime: 22/01/2023 14:15:21, LastAccessTime: 22/01/2023 14:15:21, LastWriteTime: 22/01/2023 14:15:21, ChangeTime: 22/01/2023 14:15:21, FileAttributes: A"
"14:15:24.8298674","emacs.exe","7976","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8300493","emacs.exe","7976","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Write Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8301106","emacs.exe","7976","SetBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","CreationTime: 01/01/1601 00:00:00, LastAccessTime: 01/01/1601 00:00:00, LastWriteTime: 01/01/1601 00:00:00, ChangeTime: 01/01/1601 00:00:00, FileAttributes: AN"
"14:15:24.8301488","emacs.exe","7976","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8303279","emacs.exe","7976","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Attributes, Delete, Disposition: Open, Options: Non-Directory File, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8303853","emacs.exe","7976","QueryAttributeTagFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Attributes: A, ReparseTag: 0x0"
"14:15:24.8304243","emacs.exe","7976","SetDispositionInformationEx","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Flags: FILE_DISPOSITION_DELETE, FILE_DISPOSITION_POSIX_SEMANTICS, FILE_DISPOSITION_FORCE_IMAGE_SECTION_CHECK"
"14:15:24.8304640","emacs.exe","7976","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8309423","emacs.exe","7976","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","NAME NOT FOUND","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a"
"14:15:24.8312547","emacs.exe","7976","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","NAME NOT FOUND","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a"
"14:15:24.8316060","emacs.exe","7976","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","Desired Access: Read Attributes, Delete, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Attributes: n/a, ShareMode: None, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8316786","emacs.exe","7976","QueryBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","CreationTime: 22/01/2023 14:15:24, LastAccessTime: 22/01/2023 14:15:24, LastWriteTime: 22/01/2023 14:15:24, ChangeTime: 22/01/2023 14:15:24, FileAttributes: A"
"14:15:24.8321739","emacs.exe","7976","SetRenameInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7vca7Uc.eln.tmp","SUCCESS","ReplaceIfExists: False, FileName: C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln"
"14:15:24.8327212","emacs.exe","7976","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8724898","emacs.exe","6452","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8725598","emacs.exe","6452","QueryBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","CreationTime: 22/01/2023 14:15:21, LastAccessTime: 22/01/2023 14:15:24, LastWriteTime: 22/01/2023 14:15:24, ChangeTime: 22/01/2023 14:15:24, FileAttributes: A"
"14:15:24.8726035","emacs.exe","6452","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8729415","emacs.exe","6452","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8729962","emacs.exe","6452","QueryBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","CreationTime: 22/01/2023 14:15:21, LastAccessTime: 22/01/2023 14:15:24, LastWriteTime: 22/01/2023 14:15:24, ChangeTime: 22/01/2023 14:15:24, FileAttributes: A"
"14:15:24.8730581","emacs.exe","6452","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8734177","emacs.exe","6452","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8734703","emacs.exe","6452","QueryBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","CreationTime: 22/01/2023 14:15:21, LastAccessTime: 22/01/2023 14:15:24, LastWriteTime: 22/01/2023 14:15:24, ChangeTime: 22/01/2023 14:15:24, FileAttributes: A"
"14:15:24.8735148","emacs.exe","6452","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8737115","emacs.exe","6452","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Data/List Directory, Execute/Traverse, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: n/a, ShareMode: Read, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8737860","emacs.exe","6452","CreateFileMapping","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","FILE LOCKED WITH ONLY READERS","SyncType: SyncTypeCreateSection, PageProtection: PAGE_EXECUTE_READWRITE|PAGE_NOCACHE"
"14:15:24.8738324","emacs.exe","6452","QueryStandardInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","AllocationSize: 94,208, EndOfFile: 92,251, NumberOfLinks: 1, DeletePending: False, Directory: False"
"14:15:24.8740966","emacs.exe","6452","CreateFileMapping","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","SyncType: SyncTypeOther"
"14:15:24.8742065","emacs.exe","6452","Load Image","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Image Base: 0x7ffaacb50000, Image Size: 0x21000"
"14:15:24.8743184","emacs.exe","6452","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8747892","emacs.exe","6452","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8748127","emacs.exe","6452","QueryBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","CreationTime: 22/01/2023 14:15:21, LastAccessTime: 22/01/2023 14:15:24, LastWriteTime: 22/01/2023 14:15:24, ChangeTime: 22/01/2023 14:15:24, FileAttributes: A"
"14:15:24.8748286","emacs.exe","6452","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8751046","emacs.exe","6452","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8751292","emacs.exe","6452","QueryBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","CreationTime: 22/01/2023 14:15:21, LastAccessTime: 22/01/2023 14:15:24, LastWriteTime: 22/01/2023 14:15:24, ChangeTime: 22/01/2023 14:15:24, FileAttributes: A"
"14:15:24.8751445","emacs.exe","6452","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8754961","emacs.exe","6452","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8755282","emacs.exe","6452","QueryBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","CreationTime: 22/01/2023 14:15:21, LastAccessTime: 22/01/2023 14:15:24, LastWriteTime: 22/01/2023 14:15:24, ChangeTime: 22/01/2023 14:15:24, FileAttributes: A"
"14:15:24.8755437","emacs.exe","6452","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8757797","emacs.exe","6452","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8758013","emacs.exe","6452","QueryBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","CreationTime: 22/01/2023 14:15:21, LastAccessTime: 22/01/2023 14:15:24, LastWriteTime: 22/01/2023 14:15:24, ChangeTime: 22/01/2023 14:15:24, FileAttributes: A"
"14:15:24.8758154","emacs.exe","6452","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8764948","emacs.exe","6452","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8765354","emacs.exe","6452","QueryBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","CreationTime: 22/01/2023 14:15:21, LastAccessTime: 22/01/2023 14:15:24, LastWriteTime: 22/01/2023 14:15:24, ChangeTime: 22/01/2023 14:15:24, FileAttributes: A"
"14:15:24.8765646","emacs.exe","6452","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8768883","emacs.exe","6452","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Write Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8769622","emacs.exe","6452","SetBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","CreationTime: 01/01/1601 00:00:00, LastAccessTime: 01/01/1601 00:00:00, LastWriteTime: 01/01/1601 00:00:00, ChangeTime: 01/01/1601 00:00:00, FileAttributes: AN"
"14:15:24.8770113","emacs.exe","6452","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8772176","emacs.exe","6452","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Attributes, Delete, Disposition: Open, Options: Non-Directory File, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8772934","emacs.exe","6452","QueryAttributeTagFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Attributes: A, ReparseTag: 0x0"
"14:15:24.8773402","emacs.exe","6452","SetDispositionInformationEx","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","CANNOT DELETE","Flags: FILE_DISPOSITION_DELETE, FILE_DISPOSITION_POSIX_SEMANTICS, FILE_DISPOSITION_FORCE_IMAGE_SECTION_CHECK"
"14:15:24.8774207","emacs.exe","6452","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""
"14:15:24.8777610","emacs.exe","6452","CreateFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened"
"14:15:24.8778135","emacs.exe","6452","QueryBasicInformationFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS","CreationTime: 22/01/2023 14:15:21, LastAccessTime: 22/01/2023 14:15:24, LastWriteTime: 22/01/2023 14:15:24, ChangeTime: 22/01/2023 14:15:24, FileAttributes: A"
"14:15:24.8778576","emacs.exe","6452","CloseFile","C:\Users\ajm\AppData\Local\Temp\comp-lambda-SGvFx7.eln","SUCCESS",""

>> Tracing execution of emacs with Process Explorer shows that the temp
>> file used to native compile trampolines is opened and closed repeatedly
>> by emacs, and at the point of the backtrace is still open by the same
>> emacs process.
>
> We need to know which code opened it the last time and didn't close
> it.  Can you figure that out?  All the files Emacs opens go through 2
> functions in w32.c: sys_fopen and sys_open, so by running with 2
> breakpoints there that show the backtrace and continue, you should be
> able to see the culprit, and we can then take it from there.

As noted above, I think it is the code in native-elisp-load interacting
woth the way that the files are renamed (and if those operations have
specified posix semantics or not). 

>> I am not sure excactly when this issue started, but I did not see it in
>> emacs-29 or master bootstrapped before this month.
>
> Could be because we now compile trampolines differently (to avoid the
> danger of the "fork bomb" due to recursive compilation of
> trampolines by async subprocesses).

Any idea when those changes were committed, and which changesets ? IT
doesn't apper obvios from the commit history.

> Andrea, any suggestions or comments?
>
> Thanks.