Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/arch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include <string>


extern void __arch_poweroff();
extern void __arch_reboot();
[[noreturn]] extern void __arch_poweroff();
[[noreturn]] extern void __arch_reboot();
extern void __arch_enable_legacy_irq(uint8_t);
extern void __arch_disable_legacy_irq(uint8_t);
extern void __arch_system_deactivate();
Expand Down
43 changes: 41 additions & 2 deletions api/expects
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,34 @@
#endif

#include <os.hpp>
#include <serial>

inline bool __expect_is_recursive() {
#ifndef UNITTESTS
static volatile bool in_failure = false;
if (in_failure) return true;
in_failure = true;
return false;
#else
return false;
#endif
}

inline void __expect_emit_failure(std::string_view msg, std::string_view panic_text) {
#ifndef UNITTESTS

#ifdef INCLUDEOS_SMP_ENABLE
SMP::global_lock();
#endif

std::fprintf(stderr, "%.*s\n", int(msg.size()), msg.data());
fflush(NULL);
#ifdef INCLUDEOS_SMP_ENABLE
SMP::global_unlock();
#endif
os::panic(std::string(panic_text).c_str());
#else // TEST

#else // UNITTESTS
(void) panic_text;
// throw here to allow tests to capture the error
#include <stdexcept>
Expand All @@ -52,13 +68,36 @@ inline void __expect_emit_failure(std::string_view msg, std::string_view panic_t
}

template <class... Args>
inline void __expect_failf(const char *err_prefix, const char * /*cond*/, const char *file, int line, const char *func, std::format_string<Args...> fmt, Args&&... args){
inline void __expect_failf(const char *err_prefix, const char * cond, const char *file, int line, const char *func, std::format_string<Args...> fmt, Args&&... args){
if (__expect_is_recursive()) {
kprint("Fatal Expects/Ensures recursion. (libc not initialized?)\n");

kprint("Condition was '");
kprint(cond); kprint("' @ ");
kprint(file); kprint(":");
kprint(func); kprint(" with fmt=");
kprint(fmt.get().data()); kprint("\n");

// os::shutdown();
__arch_poweroff();
}
auto reason_msg = std::format(fmt, std::forward<Args>(args)...);
auto error_msg = std::format("{}:{}:{}: {}: {}", file, line, func, err_prefix, reason_msg);
__expect_emit_failure(error_msg, reason_msg);
}

inline void __expect_failf(const char *err_prefix, const char *cond, const char *file, int line, const char *func){
if (__expect_is_recursive()) {
kprint("Fatal Expects/Ensures recursion (libc not initialized?)\n");

kprint("Condition was '");
kprint(cond); kprint("' @ ");
kprint(file); kprint(":");
kprint(func); kprint("\n");

// os::shutdown();
__arch_poweroff();
}
auto reason_msg = std::format("{}: {}", err_prefix, cond);
auto error_msg = std::format("{}:{}:{}: {}", file, line, func, err_prefix);
__expect_emit_failure(error_msg, reason_msg);
Expand Down
2 changes: 1 addition & 1 deletion api/os.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace os {
//

/** Trigger unrecoverable error and output diagnostics **/
__attribute__((noreturn))
[[noreturn]]
void panic(const char* why) noexcept;

/** Default behavior after panic **/
Expand Down
6 changes: 5 additions & 1 deletion src/kernel/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,16 @@ extern kernel::ctor_t __plugin_ctors_end;
* Print EOT character to stderr, to signal outside that PANIC output completed
* If the handler returns, go to (permanent) sleep
**/
void os::panic(const char* why) noexcept
[[noreturn]] void os::panic(const char* why) noexcept
{
cpu_enable_panicking();
if (kernel::panics() > 4) double_fault(why);

const int current_cpu = SMP::cpu_id();
if (!kernel::libc_initialized()) {
kprint("FATAL: panic before libc\n");
panic_epilogue(why);
}

#ifdef INCLUDEOS_SMP_ENABLE
SMP::global_lock();
Expand Down
3 changes: 1 addition & 2 deletions src/platform/x86_pc/acpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,7 @@ namespace x86 {
}
}

__attribute__((noreturn))
void ACPI::shutdown()
[[noreturn]] void ACPI::shutdown()
{
asm("cli");

Expand Down
2 changes: 1 addition & 1 deletion src/platform/x86_pc/acpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace x86 {
}

static void reboot();
static void shutdown();
[[noreturn]] static void shutdown();

private:
void discover();
Expand Down
5 changes: 2 additions & 3 deletions src/platform/x86_pc/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,11 @@ void __arch_disable_legacy_irq(uint8_t irq)
x86::APIC::disable_irq(irq);
}

void __arch_poweroff()
[[noreturn]] void __arch_poweroff()
{
x86::ACPI::shutdown();
__builtin_unreachable();
}
void __arch_reboot()
[[noreturn]] void __arch_reboot()
{
x86::ACPI::reboot();
__builtin_unreachable();
Expand Down
3 changes: 1 addition & 2 deletions test/integration/kernel/kprint/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import division
from __future__ import print_function
from builtins import str
from past.utils import old_div
import sys
import os

Expand All @@ -27,7 +26,7 @@ def set_format_string_size(line):
def check_truncation(line):
assert(format_string_size)

print("Received truncated string: ", line, "of size", len(line), "(format size * ", old_div(len(line),format_string_size),")")
print("Received truncated string: ", line, "of size", len(line), "(format size * ", len(line)//format_string_size,")")
assert(len(line) <= format_string_size * 2)
# truncated outputs are unacceptable :)
assert(line.strip().split(" ")[-1] == "END")
Expand Down
13 changes: 5 additions & 8 deletions test/integration/net/http/test.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#!/usr/bin/env python3

from future import standard_library
standard_library.install_aliases()
from builtins import str
import sys
import os
import _thread
import http.server
import sys
import urllib.error
import urllib.parse
import urllib.request

from vmrunner import vmrunner

HOST = ''
PORT = 9011

import http.server

DO_SERVE = True
class RequestHandler(http.server.BaseHTTPRequestHandler):
def do_GET(s):
Expand All @@ -36,7 +34,6 @@ def Client_test():
_thread.start_new_thread(Client_test, ())


import urllib.request, urllib.error, urllib.parse
def Server_test(triggerline):
res = urllib.request.urlopen("http://10.0.0.46:8080").read()
assert(res.decode('utf-8') == "Hello")
Expand Down