From 9290f1fe99c91ba6c57dec956ff73d1741d81b45 Mon Sep 17 00:00:00 2001 From: Zheng Da Date: Tue, 17 Nov 2009 10:29:23 +0100 Subject: Add DDEKit headers. --- libddekit/include/ddekit/printf.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 libddekit/include/ddekit/printf.h (limited to 'libddekit/include/ddekit/printf.h') diff --git a/libddekit/include/ddekit/printf.h b/libddekit/include/ddekit/printf.h new file mode 100644 index 00000000..35b0dfa1 --- /dev/null +++ b/libddekit/include/ddekit/printf.h @@ -0,0 +1,33 @@ +#ifndef _ddekit_print_h +#define _ddekit_print_h + +#include + +/** Print message. + * \ingroup DDEKit_util + */ +int ddekit_print(const char *); + +/** Print message with format. + * \ingroup DDEKit_util + */ +int ddekit_printf(const char *fmt, ...); + +/** Print message with format list. + * \ingroup DDEKit_util + */ +int ddekit_vprintf(const char *fmt, va_list va); + +/** Log function and message. + * \ingroup DDEKit_util + */ +#define ddekit_log(doit, msg...) \ + do { \ + if (doit) { \ + ddekit_printf("%s(): ", __func__); \ + ddekit_printf(msg); \ + ddekit_printf("\n"); \ + } \ + } while(0); + +#endif -- cgit v1.2.3 From 0ea79b053d4a853d7bdd3363ccb6c132b2f7ee5c Mon Sep 17 00:00:00 2001 From: Zheng Da Date: Tue, 29 Dec 2009 20:48:00 +0100 Subject: Don't include C library headers files in our header files. --- libddekit/Makefile | 2 +- libddekit/c_headers.h | 7 ++++++ libddekit/include/ddekit/memory.h | 13 ++--------- libddekit/include/ddekit/panic.h | 2 +- libddekit/include/ddekit/printf.h | 2 +- libddekit/malloc.c | 49 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 libddekit/c_headers.h create mode 100644 libddekit/malloc.c (limited to 'libddekit/include/ddekit/printf.h') diff --git a/libddekit/Makefile b/libddekit/Makefile index f2e52f25..018d67c9 100644 --- a/libddekit/Makefile +++ b/libddekit/Makefile @@ -19,7 +19,7 @@ dir := libddekit makemode := library libname = libddekit -SRCS= condvar.c init.c interrupt.c lock.c memory.c \ +SRCS= condvar.c init.c interrupt.c lock.c malloc.c memory.c \ pci.c pgtab.c printf.c resources.c list.c \ thread.c timer.c kmem.c LCLHDRS = include/ddekit/condvar.h include/ddekit/lock.h \ diff --git a/libddekit/c_headers.h b/libddekit/c_headers.h new file mode 100644 index 00000000..6141e900 --- /dev/null +++ b/libddekit/c_headers.h @@ -0,0 +1,7 @@ +#ifndef __C_HEADERS_H__ +#define __C_HEADERS_H__ + +#include +#include + +#endif diff --git a/libddekit/include/ddekit/memory.h b/libddekit/include/ddekit/memory.h index 2c573d8f..051a4d9e 100644 --- a/libddekit/include/ddekit/memory.h +++ b/libddekit/include/ddekit/memory.h @@ -123,9 +123,6 @@ void *ddekit_contig_malloc( ** Simple memory allocator ** *****************************/ -#include -#include "ddekit/inline.h" - /** * Allocate memory block via simple allocator * @@ -135,19 +132,13 @@ void *ddekit_contig_malloc( * The blocks allocated via this allocator CANNOT be used for DMA or other * device operations, i.e., there exists no virt->phys mapping. */ -static INLINE void *ddekit_simple_malloc(unsigned size) -{ - return malloc (size); -} +void *ddekit_simple_malloc(unsigned size); /** * Free memory block via simple allocator * * \param p pointer to memory block */ -static INLINE void ddekit_simple_free(void *p) -{ - free (p); -} +void ddekit_simple_free(void *p); #endif diff --git a/libddekit/include/ddekit/panic.h b/libddekit/include/ddekit/panic.h index 11c46ebb..f036ab3e 100644 --- a/libddekit/include/ddekit/panic.h +++ b/libddekit/include/ddekit/panic.h @@ -3,7 +3,7 @@ /** \defgroup DDEKit_util */ -#include +#include "c_headers.h" /** Panic - print error message and enter the kernel debugger. * \ingroup DDEKit_util diff --git a/libddekit/include/ddekit/printf.h b/libddekit/include/ddekit/printf.h index 35b0dfa1..aa086c71 100644 --- a/libddekit/include/ddekit/printf.h +++ b/libddekit/include/ddekit/printf.h @@ -1,7 +1,7 @@ #ifndef _ddekit_print_h #define _ddekit_print_h -#include +#include "c_headers.h" /** Print message. * \ingroup DDEKit_util diff --git a/libddekit/malloc.c b/libddekit/malloc.c new file mode 100644 index 00000000..a30cd7b7 --- /dev/null +++ b/libddekit/malloc.c @@ -0,0 +1,49 @@ +/* + Copyright (C) 2009 Free Software Foundation, Inc. + Written by Zheng Da. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The GNU Hurd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +/** + * Allocate memory block via simple allocator + * + * \param size block size + * \return pointer to new memory block + * + * The blocks allocated via this allocator CANNOT be used for DMA or other + * device operations, i.e., there exists no virt->phys mapping. + * + * Each chunk stores its size in the first word for free() to work. + */ + +#include + +void *ddekit_simple_malloc(unsigned size) +{ + return malloc (size); +} + + +/** + * Free memory block via simple allocator + * + * \param p pointer to memory block + */ +void ddekit_simple_free(void *p) +{ + free (p); +} -- cgit v1.2.3 From 7460caca37c30536b7b507d141cf5b7c51697cf3 Mon Sep 17 00:00:00 2001 From: Zheng Da Date: Fri, 1 Jan 2010 14:54:28 +0100 Subject: Remove c_headers.h --- libddekit/Makefile | 2 +- libddekit/c_headers.h | 7 ------- libddekit/include/ddekit/panic.h | 19 ++----------------- libddekit/include/ddekit/printf.h | 2 +- libddekit/memory.c | 2 ++ libddekit/timer.c | 1 + 6 files changed, 7 insertions(+), 26 deletions(-) delete mode 100644 libddekit/c_headers.h (limited to 'libddekit/include/ddekit/printf.h') diff --git a/libddekit/Makefile b/libddekit/Makefile index 018d67c9..4d5d58fa 100644 --- a/libddekit/Makefile +++ b/libddekit/Makefile @@ -20,7 +20,7 @@ makemode := library libname = libddekit SRCS= condvar.c init.c interrupt.c lock.c malloc.c memory.c \ - pci.c pgtab.c printf.c resources.c list.c \ + pci.c pgtab.c printf.c resources.c list.c panic.c \ thread.c timer.c kmem.c LCLHDRS = include/ddekit/condvar.h include/ddekit/lock.h \ include/ddekit/semaphore.h include/ddekit/debug.h \ diff --git a/libddekit/c_headers.h b/libddekit/c_headers.h deleted file mode 100644 index 6141e900..00000000 --- a/libddekit/c_headers.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __C_HEADERS_H__ -#define __C_HEADERS_H__ - -#include -#include - -#endif diff --git a/libddekit/include/ddekit/panic.h b/libddekit/include/ddekit/panic.h index f036ab3e..1468675f 100644 --- a/libddekit/include/ddekit/panic.h +++ b/libddekit/include/ddekit/panic.h @@ -3,29 +3,14 @@ /** \defgroup DDEKit_util */ -#include "c_headers.h" - /** Panic - print error message and enter the kernel debugger. * \ingroup DDEKit_util */ -#define ddekit_panic(format, ...) do \ -{ \ - char buf[1024]; \ - snprintf (buf, 1024, "%s", format); \ - fprintf (stderr , buf, ## __VA_ARGS__); \ - fflush (stderr); \ - abort (); \ -} while (0) +void ddekit_panic(char *fmt, ...) __attribute__((noreturn)); /** Print a debug message. * \ingroup DDEKit_util */ -#define ddekit_debug(format, ...) do \ -{ \ - char buf[1024]; \ - snprintf (buf, 1024, "%s: %s\n", __func__, format); \ - fprintf (stderr , buf, ## __VA_ARGS__); \ - fflush (stderr); \ -} while (0) +void ddekit_debug(char *fmt, ...); #endif diff --git a/libddekit/include/ddekit/printf.h b/libddekit/include/ddekit/printf.h index aa086c71..35b0dfa1 100644 --- a/libddekit/include/ddekit/printf.h +++ b/libddekit/include/ddekit/printf.h @@ -1,7 +1,7 @@ #ifndef _ddekit_print_h #define _ddekit_print_h -#include "c_headers.h" +#include /** Print message. * \ingroup DDEKit_util diff --git a/libddekit/memory.c b/libddekit/memory.c index 781a4bae..69088c2a 100644 --- a/libddekit/memory.c +++ b/libddekit/memory.c @@ -10,6 +10,8 @@ * FIXME check thread-safety and add locks where appropriate */ +#include + #include "ddekit/memory.h" #include "ddekit/panic.h" diff --git a/libddekit/timer.c b/libddekit/timer.c index 4944be69..ea66e5f5 100644 --- a/libddekit/timer.c +++ b/libddekit/timer.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "ddekit/lock.h" #include "ddekit/memory.h" -- cgit v1.2.3 From d31e486426aed7952b3468a63f2e81735d09943c Mon Sep 17 00:00:00 2001 From: Zheng Da Date: Tue, 6 Apr 2010 04:33:16 +0200 Subject: implement dump_stack in libddekit with backtrace. --- libdde_linux26/lib/src/arch/l4/process.c | 4 ---- libddekit/include/ddekit/printf.h | 2 ++ libddekit/printf.c | 12 ++++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'libddekit/include/ddekit/printf.h') diff --git a/libdde_linux26/lib/src/arch/l4/process.c b/libdde_linux26/lib/src/arch/l4/process.c index b5189cd4..ac700f82 100644 --- a/libdde_linux26/lib/src/arch/l4/process.c +++ b/libdde_linux26/lib/src/arch/l4/process.c @@ -220,10 +220,6 @@ void do_exit(long code) ** Misc functions ** *****************************************************************************/ -void dump_stack(void) -{ -} - char *get_task_comm(char *buf, struct task_struct *tsk) { diff --git a/libddekit/include/ddekit/printf.h b/libddekit/include/ddekit/printf.h index 35b0dfa1..6dafa18d 100644 --- a/libddekit/include/ddekit/printf.h +++ b/libddekit/include/ddekit/printf.h @@ -18,6 +18,8 @@ int ddekit_printf(const char *fmt, ...); */ int ddekit_vprintf(const char *fmt, va_list va); +void dump_stack(void); + /** Log function and message. * \ingroup DDEKit_util */ diff --git a/libddekit/printf.c b/libddekit/printf.c index dacc65e6..c4a8b718 100644 --- a/libddekit/printf.c +++ b/libddekit/printf.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "ddekit/printf.h" @@ -93,3 +94,14 @@ int log_init () return 0; } + +void dump_stack() +{ +#define NUM_TRACES 16 + void *trace[NUM_TRACES]; + int trace_size = 0; + + fprintf (stderr, "dump the stack\n"); + trace_size = backtrace(trace, NUM_TRACES); + backtrace_symbols_fd(trace, trace_size, 2); +} -- cgit v1.2.3