mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-12 22:17:11 -04:00
Improve error reporting between kernel<->user
This commit is contained in:
parent
d3a00e55b1
commit
5f20bd02e0
@ -10,6 +10,7 @@
|
||||
#include <optional.hpp>
|
||||
#include <string.hpp>
|
||||
#include <lock_guard.hpp>
|
||||
#include <errors.hpp>
|
||||
|
||||
#include "scheduler.hpp"
|
||||
#include "paging.hpp"
|
||||
@ -532,7 +533,7 @@ int64_t scheduler::exec(const std::string& file){
|
||||
k_print_line("Not a file");
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -std::ERROR_NOT_EXISTS;
|
||||
}
|
||||
|
||||
if(!elf::is_valid(content)){
|
||||
@ -540,7 +541,7 @@ int64_t scheduler::exec(const std::string& file){
|
||||
k_print_line("Not a valid file");
|
||||
}
|
||||
|
||||
return -2;
|
||||
return -std::ERROR_NOT_EXECUTABLE;
|
||||
}
|
||||
|
||||
auto buffer = content.c_str();
|
||||
@ -552,7 +553,7 @@ int64_t scheduler::exec(const std::string& file){
|
||||
k_print_line("Impossible to create paging");
|
||||
}
|
||||
|
||||
return -3;
|
||||
return -std::ERROR_FAILED_EXECUTION;
|
||||
}
|
||||
|
||||
process.brk_start = program_break;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <system.hpp>
|
||||
#include <string.hpp>
|
||||
#include <algorithms.hpp>
|
||||
#include <errors.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
@ -99,15 +100,7 @@ int main(){
|
||||
|
||||
if(!result.valid()){
|
||||
print("error: ");
|
||||
|
||||
auto err = result.error();
|
||||
if(err == 1){
|
||||
print_line("The file does not exist");
|
||||
} else if(err == 2){
|
||||
print_line("The file is not an executable");
|
||||
} else if(err == 3){
|
||||
print_line("Failed to execute the file");
|
||||
}
|
||||
print_line(std::error_message(result.error()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
32
tstl/include/errors.hpp
Normal file
32
tstl/include/errors.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
//=======================================================================
|
||||
// Copyright Baptiste Wicht 2013-2014.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//=======================================================================
|
||||
|
||||
#ifndef ERRORS_H
|
||||
#define ERRORS_H
|
||||
|
||||
namespace std {
|
||||
|
||||
constexpr const size_t ERROR_NOT_EXISTS = 1;
|
||||
constexpr const size_t ERROR_NOT_EXECUTABLE = 2;
|
||||
constexpr const size_t ERROR_FAILED_EXECUTION = 3;
|
||||
|
||||
inline const char* error_message(size_t error){
|
||||
switch(error){
|
||||
case ERROR_NOT_EXISTS:
|
||||
return "The file does not exist";
|
||||
case ERROR_NOT_EXECUTABLE:
|
||||
return "The file is not an executable";
|
||||
case ERROR_FAILED_EXECUTION:
|
||||
return "Execution failed";
|
||||
default:
|
||||
return "Unknonwn error";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user