Commit graph

736 commits

Author SHA1 Message Date
Hermès Bélusca-Maïto
ba342e1d14
[FREELDR] peloader.c: Minor code enhancements.
PeLdrCheckForLoadedDll():
- Use a for-loop to iterate over the linked list.
- Adjust few comments.
- Use SAL2 annotations.

PeLdrpCompareDllName():
- Make its input paramters const.
- Use SAL2 annotations.
2024-12-14 23:31:41 +01:00
Daniel Victor
34e76ade03 [FREELDR] Make it more compatible with w2k3 ini file 2024-12-11 07:18:34 +02:00
Thamatip Chitpong
4d9f67c79b [REACTOS] Rename ReactOS_LogOn.wav to ReactOS_Startup.wav
CORE-13951
2024-12-09 09:52:57 +07:00
Andrei Miloiu
6ec5f8841b
[FDEBUG] Update Romanian (ro-RO) translation (#7340) 2024-12-06 20:48:33 +01:00
Hermès Bélusca-Maïto
dfb43905bb
[FREELDR] peloader.c: Fix PE import binding (#7537)
Use the PE import table's OriginalFirstThunk array when scanning and
resolving imports during DLL binding.

It points to an array of pointer-sized IMAGE_THUNK_DATA structures
which describe the functions being imported. On the other hand, the
FirstThunk points to an array of pointers, whose initial values are
a copy of those pointed to by OriginalFirstThunk, but are replaced
by the actual function pointers determined at runtime, when a DLL
is loaded (see PeLdrpBindImportName() function).
If we were to use the FirstThunk array to find again later the imports
by name or ordinal, we would fail because these are replaced by the
addresses of the corresponding functions.

This fixes loading kdcom.dll from Windows XP x64 with FreeLDR when
testing on ReactOS x64.

```diff
 (freeldr\freeldr\lib\peloader.c:498) trace: PeLdrpScanImportAddressTable() ---- Calling PeLdrpBindImportName() in a loop
 (freeldr\freeldr\lib\peloader.c:501) trace: *** ThunkName->u1.AddressOfData = 00000000000070F0
 (freeldr\freeldr\lib\peloader.c:502) trace: *** ThunkData->u1.AddressOfData = 0000000000573780
 (freeldr\freeldr\lib\peloader.c:209) trace:   !!! ExportDirectory->NumberOfNames 1504
-(freeldr\freeldr\lib\peloader.c:210) trace:   !!! ImportHint 0 - ExportName 'CcCanIWrite' - ImportDataName ''
+(freeldr\freeldr\lib\peloader.c:210) trace:   !!! ImportHint 282 - ExportName 'HalPrivateDispatchTable' - ImportDataName 'HalPrivateDispatchTable'
 ....
-(freeldr\freeldr\lib\peloader.c:268) err: Did not find export ''!
-(freeldr\freeldr\lib\peloader.c:709) err: PeLdrpScanImportAddressTable() failed: ImportName = 'ntoskrnl.exe', DirectoryPath = 'multi(0)disk(0)rdisk(0)partition(2)\ReactOS\system32\'
```
('-': lines before the fix; '+': lines after the fix)

Code has been adapted based from the following functions:
ntdll/ldr/ldrpe.c!LdrpSnapThunk() and LdrpSnapIAT()
ntoskrnl/mm/ARM3/sysldr.c!MiSnapThunk() and MiResolveImageReferences()

References:
https://devblogs.microsoft.com/oldnewthing/20231129-00/?p=109077
https://devblogs.microsoft.com/oldnewthing/20231130-00/?p=109084
https://stackoverflow.com/questions/42413937/why-pe-need-original-first-thunkoft
2024-12-03 13:13:38 +01:00
Hermès Bélusca-Maïto
576fafbaf8
[FREELDR] peloader.c: Add SAL2 annotations for two import-resolving helpers (#7537)
Add annotations for PeLdrpBindImportName()
and PeLdrpScanImportAddressTable().
2024-12-03 13:13:26 +01:00
Hermès Bélusca-Maïto
ddd59f19ae
[FREELDR] peloader.c: Fix some traces 2024-12-03 12:32:08 +01:00
Václav Zouzalík
531c94a0c7
[THEMEUI][INF] Update German (de-DE) translation (#7489) 2024-11-18 21:24:57 +01:00
Stanislav Motylkov
3ecd2363a6 [MSI][BOOTDATA][INF] Add missing mnemonic keys for the context menu
Also add accelerator FIXMEs where I don't know. CORE-12323
2024-11-06 00:34:58 +03:00
Stanislav Motylkov
6be0de5d7b [MSI][BOOTDATA][INF] Add missing localized strings to msi.dll resources 2024-11-06 00:26:18 +03:00
Stanislav Motylkov
3f4f51833a [BOOTDATA][INF] hivecls.inf: Update Russian (ru-RU) translation
CORE-19845
2024-11-05 23:30:15 +03:00
Stanislav Motylkov
b45429ce03 [BOOTDATA][INF] hivecls.inf: Add definitions for MSP / Msi.Patch files
These are used by Steinberg Cubase 5. CORE-19845
Also add some missing MUIVerb for Msi.Package.
2024-11-05 23:28:59 +03:00
Timo Kreuzer
9b8c59d6b7 [FREELDR] Refactor LoadBootDeviceDriver 2024-11-02 17:31:57 +02:00
Timo Kreuzer
393b1f8998 [FREELDR] Implement PeLdrLoadBootImage 2024-11-02 17:31:57 +02:00
Timo Kreuzer
f9849f7cc4 [FREELDR] Initialize a global module list head for freeldr 2024-11-02 17:31:57 +02:00
Timo Kreuzer
6eac9b5891 [FREELDR] Pass VA instead of PA to PeLdrAllocateDataTableEntry
This allows to create DTEs for loader modules.
2024-11-02 17:31:57 +02:00
Timo Kreuzer
8a5ef4c1cc [FREELDR] Implement PeLdrLoadImageEx
This allows to load an image as freeldr extension code.
TODO:
- Add global bootloader DTE list
- Add wrapper function that also processes imports
- Use this for scsiport
2024-11-02 17:31:57 +02:00
Timo Kreuzer
bee8e81d5a [FREELDR] Move IoReadPartitionTable to ntoskrnl.c 2024-11-02 17:31:57 +02:00
Timo Kreuzer
77ba2d496b [FREELDR] Fix some trace prints 2024-11-02 17:31:57 +02:00
Daniel Victor
3fd6e34ab8
[FREELDR/x64] Fix the Multiboot pointer size (#7469)
Addendum to b524c18a3e. CORE-18374
2024-10-19 18:50:41 +03:00
Daniel Victor
b524c18a3e [FREELDR/x64] Add Multiboot header 2024-10-19 17:54:39 +03:00
Timo Kreuzer
bed8b2a0a6 [FREELDR][NDK][X64] Remove KIP0PCRADDRESS definition and mapping
It is not used by either ReactOS or Windows.
2024-10-17 18:31:32 +03:00
Hermès Bélusca-Maïto
5d361b602d
[FREELDR] fs.c: Fix handling of file handles, (de)referencing, and direct-device access (#7414)
- The original code was just incrementing the reference counts (RefCounts)
  of the device objects or the device/file handles, without decrementing
  them when closing the handles. This is now fixed.

  Notice the following:

  * When opening a file on a device (disk), the device's (and its
    handle's) RefCount is incremented, and the file handle's RefCount
    is incremented as well.

  * When closing a file, the file handle's RefCount is decremented
    (and the file closed if the RefCount reaches zero), and the file's
    parent device handle is also closed, recursively.
    This has the effect of decrementing the parent device handle's
    RefCount, and the device's own RefCount is decremented as well.

  IMPORTANT NOTE: The usefulness of handle-level RefCount is still
  under question, and might be (consistently) removed in the future.

- Fix opening a device (disk) in direct access, when this device is
  already opened. Indeed, we previously allowed direct access only if
  the device was opened as such for the very first time (its RefCount
  = 0 originally); no filesystem mounting was attempted as well.
  Then for any later open-operations on this device (while keeping an
  already-opened handle to it), filesystem access was assumed.

  Thus, this problem would show up in two ways:

  * Either the device is first opened for direct access, this succeeded
    and no filesystem was mounted. Then, for any other open-operations,
    the filesystem was NOT mounted, and opening files on it would fail.
    Direct accesses would succeed but would create an unnecessary second
    file handle.

  * Or, the device is first opened for file-access: a filesystem was
    mounted and file opening would succeed. Any other file opening
    operation would succeed as well (if the file exists). But, a direct
    access open-operation would fail, because now any open-operations on
    the device would be assumed to be a file opening.

  This is now correctly fixed. If direct-open is requested, just do it.
  If this is a file opening, we open the device, then try to mount a
  filesystem on it (if not already done), then we try to open the file.

  If file opening fails, derereference the device.

- Pass the file path to the filesystem-specific Open() functions without
  truncating the leading path separator, if any. This has to be handled
  by the filesystem routines themselves.
2024-10-16 22:20:52 +02:00
Joachim Henze
798ea90784
[FREELDR] Less outdated version-hardcodes (#7384)
Those haven't been groomed anymore for more than 10 years. We had many thousands of
different freeldr builds with different behavior and bugs each, but nobody ever
did have the slightest motivation to update those hardcoded
FREELOADER_MAJOR_VERSION, FREELOADER_MINOR_VERSION, FREELOADER_PATCH_VERSION
from ver.h. And that is logical, because touching other modules will change the behavior
of freeldr as well, so it is absolutely impossible to groom anything like that correctly.
Instead we should simply do what we started to do in PR7383, which will at least give
some information (the actual sources it was built from) instead of some misleading voodoo-version.

This might slightly shrink the size of freeldr as well, but I was too lazy to measure by how much.
2024-10-13 19:23:38 +02:00
Timo Kreuzer
0c2cdcae83 [REACTOS] Add missing line breaks at end of file 2024-10-06 10:47:11 +03:00
Hermès Bélusca-Maïto
764881a94b
[FREELDR] Remove the "setupldr" build target (#7419)
The setupldr and freeldr binaries are the same since commit 948e82af1
(r65832), because both their functionality have been shared.
2024-10-03 12:32:45 +02:00
Hermès Bélusca-Maïto
3b928898ef
[FREELDR] Simplify some control branches in loops (#7417)
Collapse some tests; remove redundant `continue;`

Pointed out by Serge Gautherie.
2024-10-03 11:47:31 +02:00
Hermès Bélusca-Maïto
3dfbe52699
[FREELDR] fs.c: Minor refactoring in ArcOpen(); fix a memory leak (#7385)
- `ArcOpen()`: flatten the registered-device search for-loop.
  Limit it to just the device search, and exit early.
  The rest of the initialization is now done outside the loop.

- The `DeviceName` string pointer may have been allocated from
  the heap, for path normalization (see `NormalizeArcDeviceName()`).
  This pointer is then only used in the device search loop and not
  nused anymore afterwards. The old code didn't free this pointer
  and memory could leak. This is now fixed easily, thanks to the
  loop flattening.

- Rename `DEVICE` member `Prefix` to `DeviceName`; SAL-annotate
  `FsRegisterDevice()`.
2024-10-01 22:15:11 +02:00
Hermès Bélusca-Maïto
689b9e0475
[FREELDR] fs.c: Move the "()" -> "(0)" ARC path normalization code into a function (#7385)
This function will be useful in other places later.
2024-10-01 22:14:02 +02:00
Hermès Bélusca-Maïto
829ad06179
[FREELDR] fs.c: Simplify FileId checks; add missing DeviceId invalidation (#7385)
- Replace a lot of `MAX_FDS` by `_countof(FileData)`;

- The duplicated FileId validation logic is wrapped with
  the `IS_VALID_FILEID()` macro.

- When returning an invalid FileId value on purpose, use
  `INVALID_FILE_ID` instead of `MAX_FDS` (that could vary
  if the file handle table gets extended).
  And replace the `(ULONG)-1` also used for that purpose
  by `INVALID_FILE_ID`.

- Add missing DeviceId invalidation:
  * when failing to open a file handle in `ArcOpen()`;
  * when registering a new device in `FsRegisterDevice()`.
    There, having DeviceId always set to zero would tell
    the code that the corresponding device's file ID is
    the first one in the table, which is a BUG. (Many devices
    would have the same file ID...)

- In addition: massage a bit some indicial for-loops.
2024-10-01 22:14:01 +02:00
Hermès Bélusca-Maïto
29a0ff73e6
[FREELDR] fs.c: Move the filesystem mount routines list into a table (#7385)
This allows to make the code better extendable: adding a new FS
mount routine into the table, instead of duplicating also a whole
`if (!FileFuncTable) ...` check.

Later, this table will be made dynamic, so that new filesystems could be
dynamically registered at runtime, and a filesystem could be forced to
be mounted by the user (using a specific syntax).
2024-10-01 22:13:51 +02:00
Hermès Bélusca-Maïto
3a7fe56a5d
[FREELDR] Change GEOMETRY "Sectors" to "SectorsPerTrack" and introduce a new "Sectors" field (#7379)
----
Thanks to the following testers!
- Dmitry Borisov (@disean) for testing on NEC PC-98 emulator;
- Justin Miller (@DarkFire01) for testing on UEFI platform;
- Stanislav Motylkov (@binarymaster) for testing on Xbox emulator
  (xemu), both livecd and bootcd.
----

"SectorsPerTrack" is for the legacy Cylinders/Heads/Sectors(PerTrack)
scheme.

- On BIOS-based PCs, INT 13h can return (for LBA-only drives) an invalid
  geometry, like: C/H/S = (-1)/(-1)/(-1). This is also what happens in
  our hwide.c driver (see IdentifyDevice() for ATAPI devices):
db419efbf2/boot/freeldr/freeldr/arch/drivers/hwide.c (L918-L928)

  as well as on VirtualBox for CD-ROMs:
https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Devices/PC/BIOS/disk.c#L155

- Therefore, we cannot reliably calculate a valid total number of sectors
  by multiplying the Cylinders*Heads*SectorsPerTrack values. In addition,
  such a multiplication could overflow a 32-bit ULONG.
  Thus, a separate ULONGLONG Sectors member is required to hold such a
  value, that is retrieved differently. For example for ATAPI devices,
  our hwide.c driver does return a valid TotalSectors value, even though
  CHS values are invalid. Other platforms, like UEFI, just work using
  logical block addressing (LBA) values (see EFI_BLOCK_IO_MEDIA).

- uefidisk.c : Per the spec, EFI_BLOCK_IO_MEDIA::LastBlock contains
  "The last LBA on the device. [...] For ATA devices, this is reported
  in IDENTIFY DEVICE data words 60-61 (i.e., Total number of user
  addressable logical sectors) _minus one_.
  For SCSI devices, this is reported in the READ CAPACITY parameter
  data 'Returned Logical Block Address field' _minus one_."
  In other words, LastBlock is a zero-based LBA index quantity. The
  corresponding total number of valid "sectors"/blocks of the device
  is therefore, (LastBlock + 1).

- Cleanup some old disabled code.
2024-09-30 12:11:15 +02:00
Joachim Henze
dbda7ab66f
[FDEBUG] *.rc: Less outdated version-hardcodes (#7383)
We do have 22 rc files. Strip a hardcoded version in all of them.
Which hasn't been groomed by anyone for longer than the year 2005 already (SVN r18478).
What a waste of bytes!
2024-09-28 21:23:28 +02:00
Joachim Henze
4f4be5c498
[FREELDR] Print arch + buildnumber on crash-screen (#7382)
This commit tries to improve the quality of the screenshots that we do get posted in JIRA,
where we couldn't even see up to now which build and arch was run.
This is in the wider context of CORE6762
(I intentionally left out the minus in the CORE-ID to prevent auto-linkage to that ticket)
2024-09-26 00:49:29 +02:00
Hermès Bélusca-Maïto
840d39b9d0
[FREELDR] i386/pc/pcdisk.c: Fix LBA reads retry loop (#7367)
When the Int 13h AH=42h "Extended read" function fails, the disk address
packet's LBA block count is reset to the number of blocks that have been
successfully transferred. This is more or less fine, unless one wants to
ensure the exact number of sectors gets read.

If the function fails so that zero sectors were read, the retry loop is
restarted, but with the packet's LBA block count member reset, as per
the documentation. (In this example, it is reset to zero.) Then, at the
next retry attempt, zero sectors are requested to be read, and this time
of course, the call succeeds... Wrongly, of course, this is not what's
expected.

Therefore, for each retry, the LBA block count member should be set
again to the correct number of sectors to read. There are maximum 3
retries, so the retry loop will stop anyway, but the LBA read will now
correctly fail and return FALSE, as expected.

This problem doesn't exist in the retry loop for the Int 13h, AH=02h
"Read Disk Sectors" CHS function, because here, the call is made only
using registers, and we use a pair of RegsIn/RegsOut. RegsOut receives
the modified register values, but the input RegsIn stays unchanged.
2024-09-25 13:24:08 +02:00
Hermès Bélusca-Maïto
4190b48924
[FREELDR] Fix the seg:off values when dumping the extended drive parameters (#7367)
(By the way, it's "EDD": "Enhanced Disk Drive", not "EED"...)

The 13th and 14th USHORTs (at offsets 0x1A-0x1D) in the retrieved buffer
from the INT 13h, AH=48h "Get Extended Drive Parameters" function,
correspond respectively to the offset and the segment of the "EDD
configuration parameters", see http://www.ctyme.com/intr/rb-0715.htm

Fixes code introduced in commit b3f11cfb38 (r17484).

----

16 years ago, these values were wrongly stored in the returned buffer
by VirtualBox, see https://www.virtualbox.org/ticket/2848 .
This has been fixed since VBox 2.1.0 in commit 15712 (22 Dec. 2008):
https://www.virtualbox.org/changeset/15712/vbox
This problem was also noticed earlier (07 Mar. 2008) and fixed in Xen:
https://lists.xenproject.org/archives/html/xen-devel/2008-03/msg00229.html

This bug originated from Bochs, from which the two projects above
adapted their rombios.c code. It was fixed on 08-09 Oct. 2007 by
Myles Watson, see https://sourceforge.net/p/bochs/mailman/message/13777090/
and included in Bochs 1.15x and 1.185+
https://sourceforge.net/p/bochs/mailman/message/12953093/
https://sourceforge.net/p/bochs/mailman/message/12953094/
2024-09-25 13:05:07 +02:00
Hermès Bélusca-Maïto
e2d0c7de30
[FREELDR] iso.c: Perform extra validation before mounting the ISO filesystem (#7367)
Validate the primary volume descriptor version and its reported
logical block size.
2024-09-25 13:05:02 +02:00
Hermès Bélusca-Maïto
56eede6e38
[FREELDR] iso.h: Fix definition of the "Primary Volume Descriptor" PVD structure (#7367)
For reference, see the cdfs/cd.h RAW_ISO_VD structure.

Each of the old "VolumeSetSize", "VolumeSequenceNumber" and "LogicalBlockSize"
ULONG fields actually correspond to pairs of USHORT fields:
"VolumeSetSizeL" and "VolumeSetSizeM", etc., where the "L" one contains
the value in little-endian format, while the "M" one contains the same
value in big-endian format.

Additionally, use UCHARs for the character arrays.
2024-09-25 12:56:47 +02:00
Hermès Bélusca-Maïto
5d99a70597
[FREELDR] Minimally reformat include/fs/iso.h 2024-09-25 12:56:46 +02:00
Laura Konopinska
e2fc578f6d [FREELDR] Support drives with 4k sector size
PR was reviewed at pull/5784
2024-09-12 20:53:10 -07:00
Adam Słaboń
e168d60bc5
[FREELDR] Fix boot timeout regression on AMD64 (#7281)
Initialize the BootMgrInfo struct globally, so the TimeOut value is guaranteed to be negative when no Multiboot cmdline is provided. This could happen when BootMain is called with a NULL pointer:
https://git.reactos.org/?p=reactos.git;a=blob;f=boot/freeldr/freeldr/arch/amd64/entry.S;hb=163f3407c8fa93ce06773fdf9fc53064506bd05e#l73
so CmdLine == NULL and LoadSettings is called with NULL, thus the CmdLineParse isn't run.

Fixes boot timeout regression introduced in commit 7bee32d237 which occured only on AMD64 builds.
2024-09-01 11:54:28 +03:00
Adam Słaboń
03d41008d4
[BOOTDATA] Fix LiveCD autorun (#7282)
Use 'shellexecute' entry instead of 'open', because the latter
tries to execute a non-executable readme.txt file.

https://learn.microsoft.com/en-us/windows/win32/shell/autorun-cmds

Addendum to 4cc03bbf01 (r71342).
2024-08-30 10:16:31 +03:00
Serge Gautherie
44662eaf62 [CMAKE] Use COMPILE_OPTIONS instead of superseded COMPILE_FLAGS
for set_source_files_properties().
2024-08-21 11:34:48 +03:00
Hermès Bélusca-Maïto
c9c5fd1a18
[SETUPLIB][BOOTDATA] Rename "MBRInstallType" to "BootLoaderLocation"
Less hardcoded references to "MBR" for code that should be generic
is always better.
2024-08-12 12:04:38 +02:00
Václav Zouzalík
5e6b2daf15
[THEMEUI][INF] Update Czech (cs-CZ) translation (#7145) 2024-07-29 14:18:10 +02:00
Whindmar Saksit
a8b33400a2
[INF][BOOTDATA][SETUPAPI] Use Inf instead of Cmd.exe to register IExplore (#7171)
This moves the IExplore registration from cmd.exe (established in 4a4060ce3c (r52196) for CORE-1370) to syssetup.inf to avoid console popups on first boot.
2024-07-24 22:55:29 +02:00
Katayama Hirofumi MZ
070d353326
[BOOTDATA] Fix Internet Browser icon for LiveCD (#7153)
JIRA issue: CORE-19202
Add CLSID_Internet settings to
boot/bootdata/livecd.inf.
2024-07-19 22:10:29 +09:00
Andrei Miloiu
d8fb869de0
[INF] Update Romanian (ro-RO) translation (#6859) 2024-07-16 21:38:44 +02:00
Katayama Hirofumi MZ
22561d5046
[CMD][BOOTDATA] Populate 'Command Processor' registry data (#7114)
Improve compatibility.
JIRA issue: CORE-8002
- Fix the default values of AutoCompletionChar
  and PathCompletionChar in cmd.exe.
- Populate "SOFTWARE\Microsoft\Command
  Processor" registry key like Win2k3 does.
2024-07-09 22:40:22 +09:00
Katayama Hirofumi MZ
0f9e889736
[NTGDI][FREETYPE][SETUP][INF] Support FontLink (#7009)
If East Asian people were unable
to see the Latin characters, it
becomes a barrier to mutual
understanding.
FontLink will break that barrier.
JIRA issue: CORE-9616
JIRA issue: CORE-15480
- Modify font substitutes.
- Unify the lock variables.
- Add FONTLINK and
  FONTLINK_CHAIN structures.
- Add FontLink_Create and
  FontLink_Destroy functions.
- Add FontLink_Chain_Init,
  FontLink_Chain_Free,
  FontLink_Chain_LoadReg,
  FontLink_Chain_Populate, and
  FontLink_Chain_FindGlyph
  functions.
- Implement FontLink.
- Add font file DroidSansFallback.ttf
  for LiveCD.
2024-06-30 22:15:34 +09:00