fix: fix faulty syscall result/status code compares
This commit is contained in:
1 parent
abfd9de8f6
commit
a81298fb24
7 files changed
+19
-14
No files matched your search
@@ -60,6 +60,13 @@ inline const char* GetStatusText(StatusCode statusCode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Map a raw syscall result to a StatusCode.
|
||||||
|
inline StatusCode StatusFromResult(long long rc) {
|
||||||
|
if (rc >= 0) return Success;
|
||||||
|
if (rc < -(long long)WouldBlock) return GenericFailure;
|
||||||
|
return (StatusCode)(-rc);
|
||||||
|
}
|
||||||
|
|
||||||
// Shared with C (libc.c), so no nullptr.
|
// Shared with C (libc.c), so no nullptr.
|
||||||
inline const char* GetStatusExplanationText(StatusCode statusCode) {
|
inline const char* GetStatusExplanationText(StatusCode statusCode) {
|
||||||
const char* explanationText[] = {
|
const char* explanationText[] = {
|
||||||
|
|||||||
@@ -2494,7 +2494,7 @@ char *getcwd(char *buf, size_t size) {
|
|||||||
}
|
}
|
||||||
int result = (int)_mtk_syscall2(SYS_GETCWD, (long)buf, (long)size);
|
int result = (int)_mtk_syscall2(SYS_GETCWD, (long)buf, (long)size);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
errno = result == BufferTooSmall ? ERANGE : EIO;
|
errno = result == -BufferTooSmall ? ERANGE : EIO;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return buf;
|
return buf;
|
||||||
@@ -3584,10 +3584,11 @@ int utime(const char *path, const struct utimbuf *times) {
|
|||||||
times != NULL ? (long)times->modtime : 0,
|
times != NULL ? (long)times->modtime : 0,
|
||||||
times == NULL);
|
times == NULL);
|
||||||
if (result == 0) return 0;
|
if (result == 0) return 0;
|
||||||
if (result == UnsupportedOp) errno = ENOTSUP;
|
/* The kernel returns StatusCodes negated. */
|
||||||
else if (result == InvalidArgument) errno = EOVERFLOW;
|
if (result == -UnsupportedOp) errno = ENOTSUP;
|
||||||
else if (result == IoFailure) errno = EIO;
|
else if (result == -InvalidArgument) errno = EOVERFLOW;
|
||||||
else if (result == SystemIntegrityError) errno = EPERM;
|
else if (result == -IoFailure) errno = EIO;
|
||||||
|
else if (result == -SystemIntegrityError) errno = EPERM;
|
||||||
else errno = ENOENT;
|
else errno = ENOENT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,10 +234,7 @@ void filemanager_read_system_configuration(FileManagerState* fm);
|
|||||||
// Map a raw syscall result (kernel StatusCodes are negative) to a userspace
|
// Map a raw syscall result (kernel StatusCodes are negative) to a userspace
|
||||||
// montauk::StatusCodes. Non-negative results (handles, counts) are Success.
|
// montauk::StatusCodes. Non-negative results (handles, counts) are Success.
|
||||||
inline montauk::StatusCode filemanager_status_from_result(int rc) {
|
inline montauk::StatusCode filemanager_status_from_result(int rc) {
|
||||||
if (rc >= 0) return montauk::Success;
|
return montauk::StatusFromResult(rc);
|
||||||
int code = -rc;
|
|
||||||
if (code > montauk::OutOfMemory) return montauk::GenericFailure;
|
|
||||||
return (montauk::StatusCode)code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The path itself may not be modified. Falling back to copy + delete after a
|
// The path itself may not be modified. Falling back to copy + delete after a
|
||||||
|
|||||||
@@ -501,7 +501,7 @@ static void apply_changes() {
|
|||||||
if (g_driver_available && g_selected_mode != g_info.currentMode) {
|
if (g_driver_available && g_selected_mode != g_info.currentMode) {
|
||||||
int result = montauk::display_set_mode(g_selected_mode);
|
int result = montauk::display_set_mode(g_selected_mode);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
set_status(result == montauk::UnsupportedOp
|
set_status(montauk::StatusFromResult(result) == montauk::UnsupportedOp
|
||||||
? "Mode needs unsupported display-link training"
|
? "Mode needs unsupported display-link training"
|
||||||
: "Mode change failed; previous mode restored");
|
: "Mode change failed; previous mode restored");
|
||||||
refresh_state(true);
|
refresh_state(true);
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ void perform_graceful_shutdown(LoginState* ls, int action) {
|
|||||||
// A successful power-control syscall never returns. If it does return,
|
// A successful power-control syscall never returns. If it does return,
|
||||||
// keep the trusted supervisor alive and make the authorization failure
|
// keep the trusted supervisor alive and make the authorization failure
|
||||||
// visible instead of falling through an unreachable-code assumption.
|
// visible instead of falling through an unreachable-code assumption.
|
||||||
show_stage(ls, heading, rc == montauk::CapabilityDenied
|
show_stage(ls, heading, montauk::StatusFromResult(rc) == montauk::CapabilityDenied
|
||||||
? "Power control permission denied."
|
? "Power control permission denied."
|
||||||
: "Power control failed.");
|
: "Power control failed.");
|
||||||
for (;;) montauk::sleep_ms(1000);
|
for (;;) montauk::sleep_ms(1000);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
extern "C" void _start() {
|
extern "C" void _start() {
|
||||||
montauk::print("Rebooting...\n");
|
montauk::print("Rebooting...\n");
|
||||||
int rc = montauk::reset();
|
int rc = montauk::reset();
|
||||||
if (rc == montauk::CapabilityDenied)
|
if (montauk::StatusFromResult(rc) == montauk::CapabilityDenied)
|
||||||
montauk::print("reset: permission denied\n");
|
montauk::print("reset: permission denied\n");
|
||||||
else
|
else
|
||||||
montauk::print("reset: reboot failed\n");
|
montauk::print("reset: reboot failed\n");
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ static int process_command(const char* line) {
|
|||||||
: montauk::abi::POWER_REQ_SHUTDOWN;
|
: montauk::abi::POWER_REQ_SHUTDOWN;
|
||||||
int rc = montauk::power_request(action);
|
int rc = montauk::power_request(action);
|
||||||
if (rc == 0) montauk::exit(0);
|
if (rc == 0) montauk::exit(0);
|
||||||
montauk::print(rc == montauk::CapabilityDenied
|
montauk::print(montauk::StatusFromResult(rc) == montauk::CapabilityDenied
|
||||||
? "power: permission denied\n"
|
? "power: permission denied\n"
|
||||||
: "power: request failed\n");
|
: "power: request failed\n");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -204,7 +204,7 @@ static int process_command(const char* line) {
|
|||||||
|
|
||||||
if (streq(cmd, "suspend")) {
|
if (streq(cmd, "suspend")) {
|
||||||
int rc = montauk::suspend();
|
int rc = montauk::suspend();
|
||||||
if (rc == montauk::CapabilityDenied)
|
if (montauk::StatusFromResult(rc) == montauk::CapabilityDenied)
|
||||||
montauk::print("suspend: permission denied\n");
|
montauk::print("suspend: permission denied\n");
|
||||||
return rc == 0 ? 0 : 1;
|
return rc == 0 ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user