Skip to content

Commit 09363d4

Browse files
committed
switching to erroror for internal functions, not complete
1 parent 192eadf commit 09363d4

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed

libc/src/__support/OSUtil/linux/prctl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ErrorOr<int> prctl(int option, unsigned long arg2, unsigned long arg3,
3030
// return value from the syscall is set to 0 on default so we do not need to
3131
// set the value on success manually.
3232
if (ret < 0)
33-
return Error(-ret);
33+
return Error(static_cast<int>(-ret));
3434

3535
return static_cast<int>(ret);
3636
}

libc/src/__support/OSUtil/prctl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "src/__support/macros/config.h"
1313
#include "src/__support/error_or.h"
1414
#include <sys/prctl.h>
15+
#include "src/__support/libc_errno.h"
1516

1617
namespace LIBC_NAMESPACE_DECL {
1718
namespace internal {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
namespace LIBC_NAMESPACE_DECL {
3+
namespace internal {
4+
void utf32to8(char* out, wchar_t src) {
5+
char u, v, w, x, y, z;
6+
u = (src & (0xf << 20)) >> 20;
7+
v = (src & (0xf << 16)) >> 16;
8+
w = (src & (0xf << 12)) >> 12;
9+
x = (src & (0xf << 8)) >> 8;
10+
y = (src & (0xf << 4)) >> 4;
11+
z = (src & (0xf << 0)) >> 0;
12+
13+
if (src <= 0x7f) {
14+
// 0yyyzzzz
15+
out[0] = src;
16+
}
17+
else if (src <= 0x7ff) {
18+
// 110xxxyy 10yyzzzz
19+
out[0] = 0xC0 | (x << 2) | (y >> 2);
20+
out[1] = 0x80 | ((y & 0x3) << 4) | z;
21+
}
22+
else if (src <= 0xffff) {
23+
// 1110wwww 10xxxxyy 10yyzzzz
24+
out[0] = 0xE0 | w;
25+
out[1] = 0x80 | (x << 2) | (y >> 2);
26+
out[2] = 0x80 | ((y & 0x3) << 4) | z;
27+
}
28+
else if (src <= 0x10ffff) {
29+
// 11110uvv 10vvwwww 10xxxxyy 10yyzzzz
30+
out[0] = 0xF0 | (u << 2) | (v >> 2);
31+
out[1] = 0x80 | ((v & 0x3) << 4) | w;
32+
out[2] = 0x80 | (x << 2) | (y >> 2);
33+
out[3] = 0x80 | ((y & 0x3) << 4) | z;
34+
}
35+
}
36+
}
37+
}

libc/src/sys/auxv/linux/getauxval.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "src/__support/OSUtil/munmap.h"
3232

3333
// for reading /proc/self/auxv
34-
#include "src/sys/prctl/prctl.h"
34+
#include "src/__support/OSUtil/prctl.h"
3535
#include "src/unistd/read.h"
3636

3737
// getauxval will work either with or without __cxa_atexit support.
@@ -133,9 +133,9 @@ static void initialize_auxv_once(void) {
133133
// is compiled and run on separate kernels, we also check the return value of
134134
// prctl.
135135
#ifdef PR_GET_AUXV
136-
int ret = prctl(PR_GET_AUXV, reinterpret_cast<unsigned long>(ptr),
136+
auto ret = internal::prctl(PR_GET_AUXV, reinterpret_cast<unsigned long>(ptr),
137137
available_size, 0, 0);
138-
if (ret >= 0) {
138+
if (ret.has_value()) {
139139
mmap_guard.submit_to_global();
140140
return;
141141
}

libc/src/sys/prctl/linux/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ add_entrypoint_object(
66
../prctl.h
77
DEPENDS
88
libc.include.sys_prctl
9-
libc.include.sys_syscall
109
libc.src.__support.OSUtil.osutil
1110
libc.src.errno.errno
1211
)

0 commit comments

Comments
 (0)