Do not allow to disable guards separately

This commit is contained in:
Alex Kotov 2022-01-22 22:12:26 +05:00
parent b489d786d0
commit e10c4f60b7
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
5 changed files with 23 additions and 37 deletions

View File

@ -1,3 +1,7 @@
2022-01-22 Alex Kotov <kotovalexarian@gmail.com>
* include/kernaux/assert.h: Do not allow to disable guards separately
2022-01-21 Alex Kotov <kotovalexarian@gmail.com>
* configure.ac: Allow to disable unnecessary heavy binary data

View File

@ -87,10 +87,7 @@ are some non-default options:
* `--enable-guard` - safely return from functions even when assertions are
disabled. This option doesn't have effect if your assetion function was set
and ends execution of application (kernel). However it prevents crashes and
undefined behavior in other cases. You can also separately enable or disable
guards:
* `--(enable|disable)-guard-cond`
* `--(enable|disable)-guard-null`
undefined behavior in other cases.
* `--with-libc` - provides the replacement for some standard C functions. Useful
in freestanding environment, where no libc is present. You can also separately
include or exclude components:

View File

@ -20,9 +20,6 @@ AC_ARG_ENABLE([float], AS_HELP_STRING([--disable-float], [disable f
dnl Features (disabled by default)
AC_ARG_ENABLE([assert], AS_HELP_STRING([--enable-assert], [enable runtime assertions]))
AC_ARG_ENABLE([guard], AS_HELP_STRING([--enable-guard], [enable assert/panic guards]))
AC_ARG_ENABLE([guard-cond], AS_HELP_STRING([--enable-guard-cond], [enable condition guard]))
AC_ARG_ENABLE([guard-null], AS_HELP_STRING([--enable-guard-null], [enable NULL-guard]))
AC_ARG_ENABLE([guard-panic], AS_HELP_STRING([--enable-guard-panic], [enable panic guard]))
AC_ARG_ENABLE([tests], AS_HELP_STRING([--enable-tests], [enable tests and examples]))
dnl Packages (enabled by default)
@ -47,14 +44,6 @@ AC_ARG_WITH( [libc-strnlen], AS_HELP_STRING([--with-libc-strnlen], [with strn
AC_DEFUN([do_enable_guard],
[
if test -z "$enable_guard_cond"; then enable_guard_cond=yes; fi
if test -z "$enable_guard_null"; then enable_guard_null=yes; fi
if test -z "$enable_guard_panic"; then enable_guard_panic=yes; fi
])
AS_IF([test "$enable_guard" = yes], do_enable_guard)
AC_DEFUN([do_without_all],
[
if test -z "$with_cmdline"; then with_cmdline=no; fi
@ -99,9 +88,7 @@ AM_CONDITIONAL([ENABLE_FLOAT], [test "$enable_float" != no])
dnl Features (disabled by default)
AM_CONDITIONAL([ENABLE_ASSERT], [test "$enable_assert" = yes])
AM_CONDITIONAL([ENABLE_GUARD_COND], [test "$enable_guard_cond" = yes])
AM_CONDITIONAL([ENABLE_GUARD_NULL], [test "$enable_guard_null" = yes])
AM_CONDITIONAL([ENABLE_GUARD_PANIC], [test "$enable_guard_panic" = yes])
AM_CONDITIONAL([ENABLE_GUARD], [test "$enable_guard" = yes])
AM_CONDITIONAL([ENABLE_TESTS], [test "$enable_tests" = yes])
dnl Packages (enabled by default)
@ -135,9 +122,7 @@ AS_IF([test "$enable_float" != no], [AC_DEFINE([ENABLE_FLOAT],
dnl Features (disabled by default)
AS_IF([test "$enable_assert" = yes], [AC_DEFINE([KERNAUX_ENABLE_ASSERT], [1], [enabled runtime assertions])])
AS_IF([test "$enable_guard_cond" = yes], [AC_DEFINE([KERNAUX_ENABLE_GUARD_COND], [1], [enabled condition guard])])
AS_IF([test "$enable_guard_null" = yes], [AC_DEFINE([KERNAUX_ENABLE_GUARD_NULL], [1], [enabled NULL-guard])])
AS_IF([test "$enable_guard_panic" = yes], [AC_DEFINE([KERNAUX_ENABLE_GUARD_PANIC], [1], [enabled panic guard])])
AS_IF([test "$enable_guard" = yes], [AC_DEFINE([KERNAUX_ENABLE_GUARD], [1], [enabled assert/panic guards])])
AS_IF([test "$enable_tests" = yes], [AC_DEFINE([ENABLE_TESTS], [1], [enabled tests and examples])])
dnl Packages (enabled by default)

View File

@ -14,7 +14,7 @@ extern "C" {
#define KERNAUX_ASSERT(cond) ((void)sizeof((cond)))
#endif
#if defined(KERNAUX_ENABLE_GUARD) || defined(KERNAUX_ENABLE_GUARD_COND)
#ifdef KERNAUX_ENABLE_GUARD
#define KERNAUX_ASSERT_RETURN(cond) { KERNAUX_ASSERT(cond); if (!(cond)) return; }
#define KERNAUX_ASSERT_RETVAL(cond, val) { KERNAUX_ASSERT(cond); if (!(cond)) return (val); }
#else
@ -22,7 +22,7 @@ extern "C" {
#define KERNAUX_ASSERT_RETVAL(cond, val) { KERNAUX_ASSERT(cond); }
#endif
#if defined(KERNAUX_ENABLE_GUARD) || defined(KERNAUX_ENABLE_GUARD_NULL)
#ifdef KERNAUX_ENABLE_GUARD
#define KERNAUX_NOTNULL_RETURN(cond) { KERNAUX_ASSERT(cond); if (!(cond)) return; }
#define KERNAUX_NOTNULL_RETVAL(cond, val) { KERNAUX_ASSERT(cond); if (!(cond)) return (val); }
#else
@ -30,7 +30,7 @@ extern "C" {
#define KERNAUX_NOTNULL_RETVAL(cond, val) { KERNAUX_ASSERT(cond); }
#endif
#if defined(KERNAUX_ENABLE_GUARD) || defined(KERNAUX_ENABLE_GUARD_PANIC)
#ifdef KERNAUX_ENABLE_GUARD
#define KERNAUX_PANIC_RETURN(msg) { KERNAUX_PANIC(msg); return; }
#define KERNAUX_PANIC_RETVAL(msg, val) { KERNAUX_PANIC(msg); return (val); }
#else

View File

@ -8,7 +8,7 @@
#include <assert.h>
#include <stddef.h>
#if defined(KERNAUX_ENABLE_ASSERT) || defined(KERNAUX_ENABLE_GUARD_COND) || defined(KERNAUX_ENABLE_GUARD_NULL)
#if defined(KERNAUX_ENABLE_ASSERT) || defined(KERNAUX_ENABLE_GUARD)
static unsigned int count = 0;
#endif
@ -32,7 +32,7 @@ int main()
kernaux_assert_cb = NULL;
test();
#if defined(KERNAUX_ENABLE_ASSERT) || defined(KERNAUX_ENABLE_GUARD_COND) || defined(KERNAUX_ENABLE_GUARD_NULL)
#if defined(KERNAUX_ENABLE_ASSERT) || defined(KERNAUX_ENABLE_GUARD)
#ifdef KERNAUX_ENABLE_ASSERT
kernaux_assert_cb = assert_cb;
#endif
@ -44,58 +44,58 @@ int main()
void test()
{
#if defined(KERNAUX_ENABLE_GUARD_COND) || defined(KERNAUX_ENABLE_GUARD_NULL)
#ifdef KERNAUX_ENABLE_GUARD
unsigned int acc = 0;
#endif
struct KernAux_PFA pfa;
KernAux_PFA_initialize(&pfa);
#ifdef KERNAUX_ENABLE_GUARD_NULL
#ifdef KERNAUX_ENABLE_GUARD
KernAux_PFA_initialize(NULL);
if (kernaux_assert_cb) assert(count == ++acc);
#endif
#ifdef KERNAUX_ENABLE_GUARD_NULL
#ifdef KERNAUX_ENABLE_GUARD
assert(!KernAux_PFA_is_available(NULL, KERNAUX_PFA_PAGE_SIZE));
if (kernaux_assert_cb) assert(count == ++acc);
#endif
#ifdef KERNAUX_ENABLE_GUARD_COND
#ifdef KERNAUX_ENABLE_GUARD
assert(!KernAux_PFA_is_available(&pfa, 123));
if (kernaux_assert_cb) assert(count == ++acc);
#endif
#ifdef KERNAUX_ENABLE_GUARD_NULL
#ifdef KERNAUX_ENABLE_GUARD
KernAux_PFA_mark_available(NULL, 0, KERNAUX_PFA_PAGE_SIZE);
if (kernaux_assert_cb) assert(count == ++acc);
#endif
#ifdef KERNAUX_ENABLE_GUARD_COND
#ifdef KERNAUX_ENABLE_GUARD
KernAux_PFA_mark_available(&pfa, KERNAUX_PFA_PAGE_SIZE, 0);
if (kernaux_assert_cb) assert(count == ++acc);
#endif
#ifdef KERNAUX_ENABLE_GUARD_NULL
#ifdef KERNAUX_ENABLE_GUARD
KernAux_PFA_mark_unavailable(NULL, 0, KERNAUX_PFA_PAGE_SIZE);
if (kernaux_assert_cb) assert(count == ++acc);
#endif
#ifdef KERNAUX_ENABLE_GUARD_COND
#ifdef KERNAUX_ENABLE_GUARD
KernAux_PFA_mark_unavailable(&pfa, KERNAUX_PFA_PAGE_SIZE, 0);
if (kernaux_assert_cb) assert(count == ++acc);
#endif
#ifdef KERNAUX_ENABLE_GUARD_NULL
#ifdef KERNAUX_ENABLE_GUARD
assert(KernAux_PFA_alloc_pages(NULL, KERNAUX_PFA_PAGE_SIZE) == 0);
if (kernaux_assert_cb) assert(count == ++acc);
#endif
#ifdef KERNAUX_ENABLE_GUARD_NULL
#ifdef KERNAUX_ENABLE_GUARD
KernAux_PFA_free_pages(NULL, KERNAUX_PFA_PAGE_SIZE, KERNAUX_PFA_PAGE_SIZE);
if (kernaux_assert_cb) assert(count == ++acc);
#endif
#ifdef KERNAUX_ENABLE_GUARD_COND
#ifdef KERNAUX_ENABLE_GUARD
KernAux_PFA_free_pages(&pfa, 123, KERNAUX_PFA_PAGE_SIZE);
if (kernaux_assert_cb) assert(count == ++acc);
#endif