Improve error reporting between kernel<->user

This commit is contained in:
Baptiste Wicht 2014-02-11 18:22:51 +01:00
parent d3a00e55b1
commit 5f20bd02e0
3 changed files with 38 additions and 12 deletions

View File

@ -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;

View File

@ -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
View 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