/*
* \brief ldso test program
* \author Sebastian Sumpf
* \date 2009-11-05
*/
/*
* Copyright (C) 2009-2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#include
#include
#include
#include
using namespace Genode;
/* shared-lib includes */
#include "test-ldso.h"
namespace Libc {
#include
#include
#include
}
/********************************************************************
** Helpers to test construction and destruction of global objects **
********************************************************************/
struct Global_1
{
int x { 0x05060708 };
Global_1() { printf("%s %x\n", __func__, --x); }
void global_1() { printf("%s %x\n", __func__, --x); }
~Global_1() { printf("%s %x\n", __func__, --x); x=0; }
}
global_1;
static struct Global_2
{
int x { 0x01020304 };
Global_2() { printf("%s %x\n", __func__, --x); }
void global_2() { printf("%s %x\n", __func__, --x); }
~Global_2() { printf("%s %x\n", __func__, --x); x=0; }
}
global_2;
/**************************************************************************
** Helpers to test construction and destruction of local static objects **
**************************************************************************/
struct Local_1
{
int x { 0x50607080 };
Local_1() { printf("%s %x\n", __func__, --x); }
void local_1() { printf("%s %x\n", __func__, --x); }
~Local_1() { printf("%s %x\n", __func__, --x); x=0; }
};
struct Local_2
{
int x { 0x10203040 };
Local_2() { printf("%s %x\n", __func__, --x); }
void local_2() { printf("%s %x\n", __func__, --x); }
~Local_2() { printf("%s %x\n", __func__, --x); x=0; }
};
Local_1 * local_1()
{
static Local_1 s;
return &s;
}
static Local_2 * local_2()
{
static Local_2 s;
return &s;
}
/************************************************************************
** Helpers to test function attributes 'constructor' and 'destructor' **
************************************************************************/
unsigned pod_1 { 0x80706050 };
static unsigned pod_2 { 0x40302010 };
static void attr_constructor_1()__attribute__((constructor));
void attr_constructor_2()__attribute__((constructor));
void attr_destructor_1() __attribute__((destructor));
static void attr_destructor_2() __attribute__((destructor));
static void attr_constructor_1() { printf("%s %x\n", __func__, --pod_1); }
void attr_constructor_2() { printf("%s %x\n", __func__, --pod_2); }
void attr_destructor_1() { printf("%s %x\n", __func__, --pod_1); pod_1=0; }
static void attr_destructor_2() { printf("%s %x\n", __func__, --pod_2); pod_2=0; }
/********************************************
** Helpers to test C++ exception handling **
********************************************/
static void exception() { throw 666; }
extern void __ldso_raise_exception();
/*************************************
** Helpers to test stack alignment **
*************************************/
static void test_stack_align(char const *fmt, ...) __attribute__((noinline));
static void test_stack_align(char const *fmt, ...)
{
va_list list;
va_start(list, fmt);
vprintf(fmt, list);
va_end(list);
}
struct Test_stack_align_thread : Thread<0x2000>
{
Test_stack_align_thread() : Thread<0x2000>("test_stack_align") { }
void entry() { test_stack_align("%f\n%g\n", 3.142, 2.718); }
};
/******************
** Dynamic cast **
******************/
struct Object_base
{
virtual void func() { printf("'Object_base' called: failed\n"); }
};
struct Object : Object_base
{
void func() { printf("'Object' called: good\n"); }
};
void test_dynamic_cast_call(Object_base *o)
{
Object *b = dynamic_cast