https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a97fcf19ecd2d73def84f…
commit a97fcf19ecd2d73def84fc60d206372883599631
Author: George Bișoc <george.bisoc(a)reactos.org>
AuthorDate: Fri Jan 10 22:23:23 2025 +0100
Commit: George Bișoc <george.bisoc(a)reactos.org>
CommitDate: Sun Jan 12 20:00:14 2025 +0100
[CMBATT] Minor improvements to estimated battery time code
- Declare CMBATT_DISCHARGE_TIME and CMBATT_CAPACITY_BOGUS constructs
- Determine if the battery was already discharging and if not, update the time when it's being discharged
- Fix the condition where it checks if the battery has been discharging for quite some time
- Default the time to BATTERY_UNKNOWN_TIME if querying the estimated battery time request fails or if the battery has just started discharging not over 15 seconds
CORE-18969
CORE-19452
---
drivers/bus/acpi/cmbatt/cmbatt.c | 21 ++++++++++++++++-----
drivers/bus/acpi/cmbatt/cmbatt.h | 12 ++++++++++++
2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/drivers/bus/acpi/cmbatt/cmbatt.c b/drivers/bus/acpi/cmbatt/cmbatt.c
index 407fa149572..dd01f8b22be 100644
--- a/drivers/bus/acpi/cmbatt/cmbatt.c
+++ b/drivers/bus/acpi/cmbatt/cmbatt.c
@@ -1085,6 +1085,7 @@ CmBattGetBatteryStatus(IN PCMBATT_DEVICE_EXTENSION DeviceExtension,
{
ULONG PsrData = 0;
NTSTATUS Status;
+ BOOLEAN WasDischarging;
ULONG BstState;
ULONG PowerUnit;
ULONG DesignVoltage, PresentRate, RemainingCapacity;
@@ -1113,6 +1114,9 @@ CmBattGetBatteryStatus(IN PCMBATT_DEVICE_EXTENSION DeviceExtension,
return Status;
}
+ /* Remember if the battery was discharging at the time of querying new status */
+ WasDischarging = !!(DeviceExtension->State & BATTERY_DISCHARGING);
+
/* Clear current BST information */
DeviceExtension->State = 0;
DeviceExtension->RemainingCapacity = 0;
@@ -1135,9 +1139,9 @@ CmBattGetBatteryStatus(IN PCMBATT_DEVICE_EXTENSION DeviceExtension,
{
/* Set power state and check if it just started discharging now */
DeviceExtension->State |= BATTERY_DISCHARGING;
- if (!(DeviceExtension->State & ACPI_BATT_STAT_DISCHARG))
+ if (!WasDischarging)
{
- /* Remember the time when the state changed */
+ /* The battery is discharging now and not before, remember the time when the state changed */
DeviceExtension->InterruptTime = KeQueryInterruptTime();
}
}
@@ -1363,8 +1367,8 @@ CmBattQueryInformation(IN PCMBATT_DEVICE_EXTENSION FdoExtension,
case BatteryEstimatedTime:
- /* Check if it's been more than 2 1/2 minutes since the last change */
- if ((KeQueryInterruptTime() - 150000000) > (FdoExtension->InterruptTime))
+ /* Check if it's been more than 15 seconds since the last change */
+ if (KeQueryInterruptTime() > (FdoExtension->InterruptTime + CMBATT_DISCHARGE_TIME))
{
/* Get new battery status */
CmBattGetBatteryStatus(FdoExtension, FdoExtension->Tag);
@@ -1379,6 +1383,9 @@ CmBattQueryInformation(IN PCMBATT_DEVICE_EXTENSION FdoExtension,
/* Grab the remaining capacity */
RemainingCapacity = FdoExtension->RemainingCapacity;
+ /* Default time to unknown if we fail the request later */
+ RemainingTime = BATTERY_UNKNOWN_TIME;
+
/* See if we don't know one or the other */
if ((Rate == BATTERY_UNKNOWN_RATE) ||
(RemainingCapacity == BATTERY_UNKNOWN_CAPACITY))
@@ -1410,7 +1417,7 @@ CmBattQueryInformation(IN PCMBATT_DEVICE_EXTENSION FdoExtension,
else
{
/* We have data, but is it valid? */
- if (RemainingCapacity > 0x123456)
+ if (RemainingCapacity > CMBATT_CAPACITY_BOGUS)
{
/* The capacity seems bogus, so don't use it */
if (CmBattDebug & CMBATT_ACPI_WARNING)
@@ -1423,6 +1430,10 @@ CmBattQueryInformation(IN PCMBATT_DEVICE_EXTENSION FdoExtension,
}
}
}
+ else
+ {
+ RemainingTime = BATTERY_UNKNOWN_TIME;
+ }
/* Return the remaining time */
QueryData = &RemainingTime;
diff --git a/drivers/bus/acpi/cmbatt/cmbatt.h b/drivers/bus/acpi/cmbatt/cmbatt.h
index e6ab5f029bd..4a2ec81acd3 100644
--- a/drivers/bus/acpi/cmbatt/cmbatt.h
+++ b/drivers/bus/acpi/cmbatt/cmbatt.h
@@ -42,6 +42,18 @@
#define CMBATT_PNP_ENTRY_EXIT 0x200
#define CMBATT_ACPI_ASSERT 0x400
+//
+// Constant used to determine if the battery was discharging
+// for over 15 seconds since last time the AC adapter got unplugged.
+//
+#define CMBATT_DISCHARGE_TIME 150000000
+
+//
+// Bogus constant used to determine if the remaining battery capacity
+// overflows which is returned by the hardware.
+//
+#define CMBATT_CAPACITY_BOGUS 0x100000
+
typedef enum _CMBATT_EXTENSION_TYPE
{
CmBattAcAdapter,
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e5a6b0f8e572ee1872b98…
commit e5a6b0f8e572ee1872b987ad7d10418eac073cdf
Author: Oleg Dubinskiy <oleg.dubinskij30(a)gmail.com>
AuthorDate: Fri Jan 10 20:45:43 2025 +0100
Commit: GitHub <noreply(a)github.com>
CommitDate: Fri Jan 10 20:45:43 2025 +0100
[SHELL32] SHELL_ArgifyW(): don't use SearchPathW() for receiving a path to a file (#7605)
Get rid from bogus SearchPathW() call, which is marked as most likely not needed in the comment above (by Wine). Simply get a length of the file name and use the file name directly instead, with checking for its validity too. Similarly as it's done for other cases.
That call seems actually not needed because it is already done using SearchPathW() in another parts of the code in this file, before calling SHELL_ArgifyW().
Fixes another heap corruption when trying to login via OAuth menthod in SpotifyXP 2.0.3 Beta (nightly build). The previous commit did not fix the bug fully, as I discovered it later.
CORE-19953
---
dll/win32/shell32/shlexec.cpp | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/dll/win32/shell32/shlexec.cpp b/dll/win32/shell32/shlexec.cpp
index 85c7feab0ff..f03db3de0e7 100644
--- a/dll/win32/shell32/shlexec.cpp
+++ b/dll/win32/shell32/shlexec.cpp
@@ -197,11 +197,9 @@ static void ParseTildeEffect(PWSTR &res, LPCWSTR &args, DWORD &len, DWORD &used,
static BOOL SHELL_ArgifyW(WCHAR* out, DWORD len, const WCHAR* fmt, const WCHAR* lpFile, LPITEMIDLIST pidl, LPCWSTR args, DWORD* out_len, const WCHAR* lpDir)
{
- WCHAR xlpFile[1024];
BOOL done = FALSE;
BOOL found_p1 = FALSE;
PWSTR res = out;
- PCWSTR cmd;
DWORD used = 0;
bool tildeEffect = false;
@@ -279,20 +277,14 @@ static BOOL SHELL_ArgifyW(WCHAR* out, DWORD len, const WCHAR* fmt, const WCHAR*
break;
case '1':
- if (!done || (*fmt == '1'))
+ if ((!done || (*fmt == '1')) && lpFile)
{
- /*FIXME Is the call to SearchPathW() really needed? We already have separated out the parameter string in args. */
- if (SearchPathW(lpDir, lpFile, L".exe", ARRAY_SIZE(xlpFile), xlpFile, NULL))
- cmd = xlpFile;
- else
- cmd = lpFile;
-
- SIZE_T cmdlen = wcslen(cmd);
- used += cmdlen;
+ SIZE_T filelen = wcslen(lpFile);
+ used += filelen;
if (used < len)
{
- wcscpy(res, cmd);
- res += cmdlen;
+ wcscpy(res, lpFile);
+ res += filelen;
}
}
found_p1 = TRUE;