Skip to content

Commit

Permalink
ntdll: HACK: Add WINE_ALERT_SIMULATE_SCHED_QUANTUM option.
Browse files Browse the repository at this point in the history
And enable it for GTA 5.

CW-Bug-Id: #21194
  • Loading branch information
Paul Gofman authored and gofman committed Sep 9, 2022
1 parent bb6411c commit 24d60b5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions dlls/ntdll/unix/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,7 @@ static struct unix_funcs unix_funcs =

BOOL ac_odyssey;
BOOL fsync_simulate_sched_quantum;
BOOL alert_simulate_sched_quantum;
BOOL no_priv_elevation;
BOOL localsystem_sid;

Expand Down Expand Up @@ -2281,6 +2282,16 @@ static void hacks_init(void)
if (fsync_simulate_sched_quantum)
ERR("HACK: Simulating sched quantum in fsync.\n");

env_str = getenv("WINE_ALERT_SIMULATE_SCHED_QUANTUM");
if (env_str)
alert_simulate_sched_quantum = !!atoi(env_str);
else if (main_argc > 1)
{
alert_simulate_sched_quantum = !!strstr(main_argv[1], "GTA5.exe");
}
if (alert_simulate_sched_quantum)
ERR("HACK: Simulating sched quantum in NtWaitForAlertByThreadId.\n");

sgi = getenv("SteamGameId");
if (sgi && (!strcmp(sgi, "50130") || !strcmp(sgi, "202990") || !strcmp(sgi, "212910")))
setenv("WINESTEAMNOEXEC", "1", 0);
Expand Down
8 changes: 8 additions & 0 deletions dlls/ntdll/unix/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -2597,6 +2597,7 @@ NTSTATUS WINAPI NtWaitForAlertByThreadId( const void *address, const LARGE_INTEG
NTSTATUS WINAPI NtWaitForAlertByThreadId( const void *address, const LARGE_INTEGER *timeout )
{
union tid_alert_entry *entry = get_tid_alert_entry( NtCurrentTeb()->ClientId.UniqueThread );
BOOL waited = FALSE;
NTSTATUS status;

TRACE( "%p %s\n", address, debugstr_timeout( timeout ) );
Expand Down Expand Up @@ -2632,8 +2633,15 @@ NTSTATUS WINAPI NtWaitForAlertByThreadId( const void *address, const LARGE_INTEG
else
ret = futex_wait( futex, 0, NULL );

if (!timeout || timeout->QuadPart)
waited = TRUE;

if (ret == -1 && errno == ETIMEDOUT) return STATUS_TIMEOUT;
}

if (alert_simulate_sched_quantum && waited)
usleep(0);

return STATUS_ALERTED;
}
#endif
Expand Down
1 change: 1 addition & 0 deletions dlls/ntdll/unix/unix_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ extern struct ldt_copy __wine_ldt_copy DECLSPEC_HIDDEN;

extern BOOL ac_odyssey DECLSPEC_HIDDEN;
extern BOOL fsync_simulate_sched_quantum DECLSPEC_HIDDEN;
extern BOOL alert_simulate_sched_quantum DECLSPEC_HIDDEN;
extern BOOL no_priv_elevation DECLSPEC_HIDDEN;
extern BOOL localsystem_sid DECLSPEC_HIDDEN;

Expand Down

0 comments on commit 24d60b5

Please sign in to comment.