Skip to content

Commit

Permalink
posix: Handle files that are less than the size of an elf header in exec
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisbonke committed Jul 22, 2024
1 parent b732734 commit 9f9fb3f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion posix/subsystem/src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ async::result<frg::expected<Error>> File::readExactly(Process *process,
auto result = FRG_CO_TRY(co_await readSome(process,
(char *)data + offset, length - offset));
if(!result)
co_return Error::wouldBlock;
co_return Error::eof;
offset += result;
}

Expand Down
5 changes: 4 additions & 1 deletion posix/subsystem/src/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ enum class Error {

noMemory,

directoryNotEmpty
directoryNotEmpty,

// Failure of the underlying device, corresponds to EIO
ioError
};

std::ostream& operator<<(std::ostream& os, const Error& err);
Expand Down
17 changes: 13 additions & 4 deletions posix/subsystem/src/observations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,29 @@ async::result<void> observeThread(std::shared_ptr<Process> self,

auto error = co_await Process::exec(self,
path, std::move(args), std::move(env));
if(error == Error::noSuchFile) {
if(error == Error::success) {
// Continue
}else if(error == Error::noSuchFile) {
gprs[kHelRegError] = kHelErrNone;
gprs[kHelRegOut0] = ENOENT;
HEL_CHECK(helStoreRegisters(thread.getHandle(), kHelRegsGeneral, &gprs));

HEL_CHECK(helResume(thread.getHandle()));
}else if(error == Error::badExecutable) {
}else if(error == Error::badExecutable || error == Error::eof) {
gprs[kHelRegError] = kHelErrNone;
gprs[kHelRegOut0] = ENOEXEC;
HEL_CHECK(helStoreRegisters(thread.getHandle(), kHelRegsGeneral, &gprs));

HEL_CHECK(helResume(thread.getHandle()));
}else
assert(error == Error::success);
}else {
// Unhandled error, log and bubble up EIO
std::cout << "posix: exec: unhandled error from Process::exec, we got: " << (int)error << std::endl;
gprs[kHelRegError] = kHelErrNone;
gprs[kHelRegOut0] = EIO;
HEL_CHECK(helStoreRegisters(thread.getHandle(), kHelRegsGeneral, &gprs));

HEL_CHECK(helResume(thread.getHandle()));
}
}else if(observe.observation() == kHelObserveSuperCall + posix::superExit) {
if(logRequests)
std::cout << "posix: EXIT supercall" << std::endl;
Expand Down
1 change: 1 addition & 0 deletions posix/subsystem/src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ std::ostream& operator<<(std::ostream& os, const Error& err) {
case Error::isDirectory: err_string = "isDirectory"; break;
case Error::noMemory: err_string = "noMemory"; break;
case Error::directoryNotEmpty: err_string = "directoryNotEmpty"; break;
case Error::ioError: err_string = "ioError"; break;
}

return os << err_string;
Expand Down

0 comments on commit 9f9fb3f

Please sign in to comment.