From 284f7166b756351a760f42134b3a52aaab8a04fb Mon Sep 17 00:00:00 2001 From: oliverschmidt Date: Tue, 12 Oct 2010 11:03:53 +0000 Subject: [PATCH] Allow standalone win32 programs to exit the Contiki process by calling LOAD_UNLOAD(). --- platform/win32/Makefile.win32 | 4 ++- platform/win32/contiki-conf.h | 2 ++ platform/win32/loader/unload.c | 46 ++++++++++++++++++++++++++++++++++ platform/win32/loader/unload.h | 43 +++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 platform/win32/loader/unload.c create mode 100644 platform/win32/loader/unload.h diff --git a/platform/win32/Makefile.win32 b/platform/win32/Makefile.win32 index 291858dc6..3fc83e54f 100644 --- a/platform/win32/Makefile.win32 +++ b/platform/win32/Makefile.win32 @@ -30,7 +30,7 @@ # # Author: Oliver Schmidt # -# $Id: Makefile.win32,v 1.19 2010/01/30 11:52:01 oliverschmidt Exp $ +# $Id: Makefile.win32,v 1.20 2010/10/12 11:03:53 oliverschmidt Exp $ # TARGET_LIBFILES = /lib/w32api/libws2_32.a /lib/w32api/libiphlpapi.a @@ -53,6 +53,8 @@ ifdef PLATFORM_BUILD CFLAGS += -DPLATFORM_BUILD -DWITH_LOADER_ARCH -DAUTOSTART_ENABLE LDFLAGS += -Wl,--out-implib=contiki-main.$(TARGET).a \ -u _cfs_open -u _cfs_opendir -u _uiplib_ipaddrconv +else + CONTIKI_TARGET_SOURCEFILES += unload.c endif ### Set a target-specific variable value diff --git a/platform/win32/contiki-conf.h b/platform/win32/contiki-conf.h index 0e6f10c1e..f13080fe4 100644 --- a/platform/win32/contiki-conf.h +++ b/platform/win32/contiki-conf.h @@ -127,6 +127,8 @@ typedef unsigned short uip_stats_t; #ifdef PLATFORM_BUILD #define LOADER_CONF_ARCH "loader/dll-loader.h" +#else /* PLATFORM_BUILD */ +#define LOADER_CONF_ARCH "loader/unload.h" #endif /* PLATFORM_BUILD */ #define PROGRAM_HANDLER_CONF_MAX_NUMDSCS 10 diff --git a/platform/win32/loader/unload.c b/platform/win32/loader/unload.c new file mode 100644 index 000000000..43ba5f22b --- /dev/null +++ b/platform/win32/loader/unload.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Oliver Schmidt + * + * $Id: unload.c,v 1.1 2010/10/12 11:03:53 oliverschmidt Exp $ + */ + +#include + +#include "ctk/ctk-draw.h" + +/*-----------------------------------------------------------------------------------*/ +void +unload(void) +{ + exit(EXIT_SUCCESS); +} +/*-----------------------------------------------------------------------------------*/ diff --git a/platform/win32/loader/unload.h b/platform/win32/loader/unload.h new file mode 100644 index 000000000..ad8ab7b8c --- /dev/null +++ b/platform/win32/loader/unload.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * Author: Oliver Schmidt + * + * $Id: unload.h,v 1.1 2010/10/12 11:03:53 oliverschmidt Exp $ + */ + +#ifndef __UNLOAD_H__ +#define __UNLOAD_H__ + +#define LOADER_UNLOAD unload + +void unload(void); + +#endif /* __UNLOAD_H__ */