Skip to content

Commit

Permalink
Rename 'msecs' to 'usecs' to avoid potential confusion
Browse files Browse the repository at this point in the history
The function msleep uses gBS->Stall which waits for a specified number
of microseconds.

Reference: https://edk2-docs.gitbook.io/edk-ii-uefi-driver-writer-s-guide/5_uefi_services/51_services_that_uefi_drivers_commonly_use/517_stall

This reference even mentions an example sleeping for 10 microseconds: // Wait 10 uS. Notice the letter 'u'.

Therefore it's a good idea to call the function 'usleep' rather than
'msleep', so no one confuses it with milliseconds, and to change the
argument name to match as well.

Signed-off-by: Kamil Aronowski <kamil.aronowski@yahoo.com>
  • Loading branch information
aronowski authored and vathpela committed Jun 21, 2023
1 parent f7a4338 commit 549d346
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions fallback.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ try_start_first_option(EFI_HANDLE parent_image_handle)
console_print(L"Verbose enabled, sleeping for %d mseconds... "
L"Press the Pause key now to hold for longer.\n",
fallback_verbose_wait);
msleep(fallback_verbose_wait);
usleep(fallback_verbose_wait);
}

if (!first_new_option) {
Expand All @@ -1036,7 +1036,7 @@ try_start_first_option(EFI_HANDLE parent_image_handle)
}
console_print(L"\n");

msleep(500000000);
usleep(500000000);
return efi_status;
}

Expand All @@ -1051,7 +1051,7 @@ try_start_first_option(EFI_HANDLE parent_image_handle)
efi_status = BS->StartImage(image_handle, NULL, NULL);
if (EFI_ERROR(efi_status)) {
console_print(L"StartImage failed: %r\n", efi_status);
msleep(500000000);
usleep(500000000);
}
return efi_status;
}
Expand Down Expand Up @@ -1218,7 +1218,7 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
console_print(L"Verbose enabled, sleeping for %d mseconds... "
L"Press the Pause key now to hold for longer.\n",
fallback_verbose_wait);
msleep(fallback_verbose_wait);
usleep(fallback_verbose_wait);
}

RT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
Expand Down
4 changes: 2 additions & 2 deletions include/asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ static inline void wait_for_debug(void)
{
uint64_t a, b;
int x;
extern void msleep(unsigned long msecs);
extern void usleep(unsigned long usecs);

a = read_counter();
for (x = 0; x < 1000; x++) {
msleep(1000);
usleep(1000);
b = read_counter();
if (a != b)
break;
Expand Down
2 changes: 1 addition & 1 deletion include/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ extern EFI_STATUS print_crypto_errors(EFI_STATUS rc, char *file, const char *fun
#define crypterr(rc) print_crypto_errors((rc), __FILE__, __func__, __LINE__)

#ifndef SHIM_UNIT_TEST
extern VOID msleep(unsigned long msecs);
extern VOID usleep(unsigned long usecs);
#endif

/* This is used in various things to determine if we should print to the
Expand Down
4 changes: 2 additions & 2 deletions lib/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,9 @@ setup_verbosity(VOID)

#ifndef SHIM_UNIT_TEST
VOID
msleep(unsigned long msecs)
usleep(unsigned long usecs)
{
BS->Stall(msecs);
BS->Stall(usecs);
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion model.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ gcm_gmult_4bit(u64 Xi[2], u128 Htable[16])
}

void
msleep(int n)
usleep(int n)
{
__coverity_sleep__();
}
Expand Down
6 changes: 3 additions & 3 deletions replacements.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ replacement_start_image(EFI_HANDLE image_handle, UINTN *exit_data_size, CHAR16 *
console_print(L"Something has gone seriously wrong: %r\n",
efi_status2);
console_print(L"shim cannot continue, sorry.\n");
msleep(5000000);
usleep(5000000);
RT->ResetSystem(EfiResetShutdown,
EFI_SECURITY_VIOLATION,
0, NULL);
Expand Down Expand Up @@ -137,7 +137,7 @@ exit_boot_services(EFI_HANDLE image_key, UINTN map_key)

console_print(L"Bootloader has not verified loaded image.\n");
console_print(L"System is compromised. halting.\n");
msleep(5000000);
usleep(5000000);
RT->ResetSystem(EfiResetShutdown, EFI_SECURITY_VIOLATION, 0, NULL);
return EFI_SECURITY_VIOLATION;
}
Expand All @@ -162,7 +162,7 @@ do_exit(EFI_HANDLE ImageHandle, EFI_STATUS ExitStatus,
console_print(L"Something has gone seriously wrong: %r\n",
efi_status2);
console_print(L"shim cannot continue, sorry.\n");
msleep(5000000);
usleep(5000000);
RT->ResetSystem(EfiResetShutdown,
EFI_SECURITY_VIOLATION, 0, NULL);
}
Expand Down
12 changes: 6 additions & 6 deletions shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ EFI_STATUS init_grub(EFI_HANDLE image_handle)
efi_status = start_image(image_handle, MOK_MANAGER);
if (EFI_ERROR(efi_status)) {
console_print(L"start_image() returned %r\n", efi_status);
msleep(2000000);
usleep(2000000);
return efi_status;
}

Expand All @@ -1222,15 +1222,15 @@ EFI_STATUS init_grub(EFI_HANDLE image_handle)
console_print(
L"start_image() returned %r, falling back to default loader\n",
efi_status);
msleep(2000000);
usleep(2000000);
load_options = NULL;
load_options_size = 0;
efi_status = start_image(image_handle, DEFAULT_LOADER);
}

if (EFI_ERROR(efi_status)) {
console_print(L"start_image() returned %r\n", efi_status);
msleep(2000000);
usleep(2000000);
}

return efi_status;
Expand Down Expand Up @@ -1642,7 +1642,7 @@ devel_egress(devel_egress_action action UNUSED)
console_print(L"Waiting to %a...", reasons[action]);
for (size_t sleepcount = 0; sleepcount < 10; sleepcount++) {
console_print(L"%d...", 10 - sleepcount);
msleep(1000000);
usleep(1000000);
}
console_print(L"\ndoing %a\n", action);

Expand Down Expand Up @@ -1780,7 +1780,7 @@ efi_main (EFI_HANDLE passed_image_handle, EFI_SYSTEM_TABLE *passed_systab)
#if defined(ENABLE_SHIM_DEVEL)
devel_egress(COLD_RESET);
#else
msleep(5000000);
usleep(5000000);
RT->ResetSystem(EfiResetShutdown, EFI_SECURITY_VIOLATION,
0, NULL);
#endif
Expand All @@ -1803,7 +1803,7 @@ efi_main (EFI_HANDLE passed_image_handle, EFI_SYSTEM_TABLE *passed_systab)
*/
if (user_insecure_mode) {
console_print(L"Booting in insecure mode\n");
msleep(2000000);
usleep(2000000);
}

/*
Expand Down

0 comments on commit 549d346

Please sign in to comment.