Skip to content

Commit d963ce2

Browse files
[libc][uefi] fix error, exit, and io OSUtil support compilation
1 parent e5a4692 commit d963ce2

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

libc/src/__support/OSUtil/uefi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_object_library(
1010
DEPENDS
1111
libc.include.errno
1212
libc.include.limits
13+
libc.include.uefi
1314
libc.src.__support.common
1415
libc.src.__support.CPP.string_view
1516
)

libc/src/__support/OSUtil/uefi/error.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
namespace LIBC_NAMESPACE_DECL {
1717

18-
static const struct {
18+
static constexpr struct errno_efi_status_entry {
1919
EFI_STATUS status;
20-
int errno;
20+
int errno_value;
2121
} uefi_status_errno_map[] = {
2222
{EFI_SUCCESS, 0},
2323
{ERROR_BIT | EFI_LOAD_ERROR, EINVAL},
@@ -65,20 +65,20 @@ static constexpr size_t uefi_status_errno_map_length =
6565

6666
int uefi_status_to_errno(EFI_STATUS status) {
6767
for (size_t i = 0; i < uefi_status_errno_map_length; i++) {
68-
if (uefi_status_errno_map[i].status == status) {
69-
return uefi_status_errno_map[i].errno;
70-
}
68+
const struct errno_efi_status_entry *entry = &uefi_status_errno_map[i];
69+
if (entry->status == status)
70+
return entry->errno_value;
7171
}
7272

7373
// Unknown type
7474
__builtin_unreachable();
7575
}
7676

77-
EFI_STATUS errno_to_uefi_status(int errno) {
77+
EFI_STATUS errno_to_uefi_status(int errno_value) {
7878
for (size_t i = 0; i < uefi_status_errno_map_length; i++) {
79-
if (uefi_status_errno_map[i].errno == errno) {
80-
return uefi_status_errno_map[i].status;
81-
}
79+
const struct errno_efi_status_entry *entry = &uefi_status_errno_map[i];
80+
if (entry->errno_value == errno_value)
81+
return entry->status;
8282
}
8383

8484
// Unknown type

libc/src/__support/OSUtil/uefi/exit.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
//===-----------------------------------------------------------------===//
88

99
#include "src/__support/OSUtil/exit.h"
10-
#include "include/Uefi.h"
10+
#include "Uefi.h"
1111
#include "src/__support/macros/config.h"
1212

1313
namespace LIBC_NAMESPACE_DECL {
1414
namespace internal {
1515

1616
[[noreturn]] void exit(int status) {
17-
efi_system_table->BootServices->Exit(efi_image_handle, status, 0, nullptr);
17+
__llvm_libc_efi_system_table->BootServices->Exit(__llvm_libc_efi_image_handle,
18+
status, 0, nullptr);
1819
__builtin_unreachable();
1920
}
2021

libc/src/__support/OSUtil/uefi/io.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,34 @@
88

99
#include "io.h"
1010

11+
#include "Uefi.h"
1112
#include "src/__support/CPP/string_view.h"
1213
#include "src/__support/macros/config.h"
1314

1415
namespace LIBC_NAMESPACE_DECL {
1516

16-
ssize_t read_from_stdin(char *buf, size_t size) { return 0; }
17+
ssize_t read_from_stdin([[gnu::unused]] char *buf,
18+
[[gnu::unused]] size_t size) {
19+
return 0;
20+
}
1721

1822
void write_to_stdout(cpp::string_view msg) {
1923
// TODO: use mbstowcs once implemented
2024
for (size_t i = 0; i < msg.size(); i++) {
2125
char16_t e[2] = {msg[i], 0};
22-
efi_system_table->ConOut->OutputString(
23-
efi_system_table->ConOut, reinterpret_cast<const char16_t *>(&e));
26+
__llvm_libc_efi_system_table->ConOut->OutputString(
27+
__llvm_libc_efi_system_table->ConOut,
28+
reinterpret_cast<const char16_t *>(&e));
2429
}
2530
}
2631

2732
void write_to_stderr(cpp::string_view msg) {
2833
// TODO: use mbstowcs once implemented
2934
for (size_t i = 0; i < msg.size(); i++) {
3035
char16_t e[2] = {msg[i], 0};
31-
efi_system_table->StdErr->OutputString(
32-
efi_system_table->StdErr, reinterpret_cast<const char16_t *>(&e));
36+
__llvm_libc_efi_system_table->StdErr->OutputString(
37+
__llvm_libc_efi_system_table->StdErr,
38+
reinterpret_cast<const char16_t *>(&e));
3339
}
3440
}
3541

0 commit comments

Comments
 (0)