1515// See the License for the specific language governing permissions and
1616// limitations under the License.
1717
18+ #include < kernel/syscalls.hpp>
19+
1820#include < fcntl.h> // open()
1921#include < string.h>
2022#include < signal.h>
21-
2223#include < sys/errno.h>
2324#include < sys/stat.h>
24-
2525#include < kernel/os.hpp>
26- #include < kernel/syscalls.hpp>
2726#include < kernel/rtc.hpp>
28- #include < hw/serial.hpp>
2927
3028#include < statman>
3129#include < kprint>
@@ -51,6 +49,26 @@ extern "C" {
5149 uintptr_t heap_end;
5250}
5351
52+ extern " C"
53+ void abort () {
54+ panic (" abort() called" );
55+ }
56+ extern " C"
57+ void abort_message (const char * fmt, ...)
58+ {
59+ char buffer[1024 ];
60+ va_list list;
61+ va_start (list, fmt);
62+ vsnprintf (buffer, sizeof (buffer), fmt, list);
63+ va_end (list);
64+ #ifdef ARCH_x86_64
65+ asm (" movq %0, %%rdi" : : " r" (buffer));
66+ asm (" jmp panic_begin" );
67+ #else
68+ panic (buffer);
69+ #endif
70+ }
71+
5472void _exit (int status) {
5573 kprintf (" %s" ,std::string (LINEWIDTH, ' =' ).c_str ());
5674 kprint (" \n " );
@@ -90,8 +108,10 @@ int kill(pid_t pid, int sig) THROW {
90108 SMP::global_lock ();
91109 printf (" !!! Kill PID: %i, SIG: %i - %s " , pid, sig, strsignal (sig));
92110
93- if (sig == 6ul ) {
111+ if (sig == 6 ) {
94112 printf (" / ABORT\n " );
113+ } else {
114+ printf (" \n " );
95115 }
96116 SMP::global_unlock ();
97117
@@ -139,6 +159,7 @@ bool OS::is_panicking() noexcept
139159**/
140160void panic (const char * why)
141161{
162+ asm (" panic_begin:" );
142163 // / prevent re-entering panic() more than once per CPU
143164 // if (panic_reenter) OS::reboot();
144165 panic_reenter = true ;
@@ -160,7 +181,6 @@ void panic(const char* why)
160181 // heap info
161182 typedef unsigned long ulong;
162183 uintptr_t heap_total = OS::heap_max () - heap_begin;
163- double total = (heap_end - heap_begin) / (double ) heap_total;
164184 fprintf (stderr, " Heap is at: %p / %p (diff=%lu)\n " ,
165185 (void *) heap_end, (void *) OS::heap_max (), (ulong) (OS::heap_max () - heap_end));
166186 fprintf (stderr, " Heap usage: %lu / %lu Kb\n " , // (%.2f%%)\n",
0 commit comments