From: Gabriel Corona Date: Fri, 4 Apr 2014 13:19:43 +0000 (+0200) Subject: Merge branch 'mc' X-Git-Tag: v3_11~159 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f60c6c67576ca97e84d781811f9076c18f183b11?hp=a88e134d6e42882cd3c0bdebc5775e12083947de Merge branch 'mc' --- diff --git a/src/bindings/java/surf.i b/src/bindings/java/surf.i index fe5a852425..1553e77060 100644 --- a/src/bindings/java/surf.i +++ b/src/bindings/java/surf.i @@ -93,6 +93,7 @@ public: void updateLatency(double value, double date=surf_get_clock()); }; +%nodefaultctor Action; class Action { public: Model *getModel(); @@ -101,6 +102,7 @@ public: void setBound(double bound); }; +%nodefaultctor CpuAction; class CpuAction : public Action { public: %extend { diff --git a/src/msg/msg_io.c b/src/msg/msg_io.c index 3b77073b5d..3f7e1f89d2 100644 --- a/src/msg/msg_io.c +++ b/src/msg/msg_io.c @@ -322,7 +322,7 @@ msg_error_t MSG_file_rcopy (msg_file_t file, msg_host_t host, const char* fullpa /* Find the real host destination where the file will be physically stored */ xbt_dict_cursor_t cursor = NULL; char *mount_name, *storage_name, *file_mount_name, *host_name_dest; - msg_storage_t storage_dest; + msg_storage_t storage_dest = NULL; msg_host_t host_dest; size_t longest_prefix_length = 0; diff --git a/src/simix/smx_context.c b/src/simix/smx_context.c index 0bfad29665..186b1236df 100644 --- a/src/simix/smx_context.c +++ b/src/simix/smx_context.c @@ -14,7 +14,20 @@ #include "simgrid/sg_config.h" #include "internal_config.h" #include "simgrid/modelchecker.h" + + +#ifdef _WIN32 +#include +#else #include +#endif + +#ifdef __MINGW32__ +#define _aligned_malloc __mingw_aligned_malloc +#define _aligned_free __mingw_aligned_free +#endif //MINGW + + #ifdef HAVE_VALGRIND_VALGRIND_H # include @@ -119,14 +132,19 @@ void *SIMIX_context_stack_new(void) char *alloc = xbt_malloc0(size + xbt_pagesize); stack = alloc - ((uintptr_t)alloc & (xbt_pagesize - 1)) + xbt_pagesize; *((void **)stack - 1) = alloc; -#else +#elif !defined(WIN32) if (posix_memalign(&stack, xbt_pagesize, size) != 0) xbt_die("Failed to allocate stack."); +#else + stack = _aligned_malloc(size, xbt_pagesize); #endif + +#ifndef WIN32 if (mprotect(stack, smx_context_guard_size, PROT_NONE) == -1) { XBT_WARN("Failed to protect stack: %s", strerror(errno)); /* That's not fatal, pursue anyway. */ } +#endif stack = (char *)stack + smx_context_guard_size; } else { stack = xbt_malloc0(smx_context_stack_size); @@ -154,6 +172,7 @@ void SIMIX_context_stack_delete(void *stack) VALGRIND_STACK_DEREGISTER(valgrind_stack_id); #endif +#ifndef WIN32 if (smx_context_guard_size > 0 && !MC_is_active()) { stack = (char *)stack - smx_context_guard_size; if (mprotect(stack, smx_context_guard_size, @@ -166,6 +185,8 @@ void SIMIX_context_stack_delete(void *stack) stack = *((void **)stack - 1); #endif } +#endif + xbt_free(stack); } diff --git a/src/simix/smx_context_thread.c b/src/simix/smx_context_thread.c index ee35dfdf64..fbde818409 100644 --- a/src/simix/smx_context_thread.c +++ b/src/simix/smx_context_thread.c @@ -152,14 +152,14 @@ static void smx_ctx_thread_stop(smx_context_t pcontext) static void *smx_ctx_thread_wrapper(void *param) { smx_ctx_thread_t context = (smx_ctx_thread_t) param; - +#ifndef WIN32 /* Install alternate signal stack, for SIGSEGV handler. */ stack_t stack; stack.ss_sp = sigsegv_stack; stack.ss_size = sizeof sigsegv_stack; stack.ss_flags = 0; sigaltstack(&stack, NULL); - +#endif /* Tell the maestro we are starting, and wait for its green light */ xbt_os_sem_release(context->end); xbt_os_sem_acquire(context->begin); diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index 71a85a4b3d..a169f8d9e6 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -40,6 +40,7 @@ static void _XBT_CALL inthandler(int ignored) exit(1); } +#ifndef WIN32 static void _XBT_CALL segvhandler(int signum, siginfo_t *siginfo, void *context) { if (siginfo->si_signo == SIGSEGV && siginfo->si_code == SEGV_ACCERR) { @@ -103,6 +104,7 @@ static void install_segvhandler(void) } } +#endif /********************************* SIMIX **************************************/ XBT_INLINE double SIMIX_timer_next(void) @@ -160,9 +162,10 @@ void SIMIX_global_init(int *argc, char **argv) /* Prepare to display some more info when dying on Ctrl-C pressing */ signal(SIGINT, inthandler); +#ifndef WIN32 /* Install SEGV handler */ install_segvhandler(); - +#endif /* register a function to be called by SURF after the environment creation */ sg_platf_init(); sg_platf_postparse_add_cb(SIMIX_post_create_environment); diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index 10b39e9207..969991b74e 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -201,11 +201,9 @@ int SIMIX_file_unlink(smx_process_t process, smx_file_t fd) sg_host_name(host)); } - if (surf_workstation_unlink(host, fd->surf_file)){ - xbt_free(fd); - return 1; - } else - return 0; + int res = surf_workstation_unlink(host, fd->surf_file); + xbt_free(fd); + return !!res; } sg_size_t SIMIX_pre_file_get_size(smx_simcall_t simcall, smx_file_t fd) diff --git a/src/simix/smx_private.h b/src/simix/smx_private.h index db37ffb679..1cb5514f45 100644 --- a/src/simix/smx_private.h +++ b/src/simix/smx_private.h @@ -209,7 +209,9 @@ typedef struct s_smx_action { void SIMIX_context_mod_init(void); void SIMIX_context_mod_exit(void); +#ifndef WIN32 XBT_PUBLIC_DATA(char sigsegv_stack[SIGSTKSZ]); +#endif /* We are using the bottom of the stack to save some information, like the * valgrind_stack_id. Define smx_context_usable_stack_size to give the remaining diff --git a/src/smpi/smpi_bench.c b/src/smpi/smpi_bench.c index 9bd3882fd9..f7464dbd2a 100644 --- a/src/smpi/smpi_bench.c +++ b/src/smpi/smpi_bench.c @@ -574,7 +574,6 @@ void* smpi_shared_set_call(const char* func, const char* input, void* data) { -#ifndef WIN32 #define TOPAGE(addr) (void *)(((unsigned long)(addr) / xbt_pagesize) * xbt_pagesize) @@ -763,5 +762,3 @@ void smpi_destroy_global_memory_segments(){ } - -#endif diff --git a/src/surf/cpu_cas01.hpp b/src/surf/cpu_cas01.hpp index 685cd4cbc2..438f3c2ff4 100644 --- a/src/surf/cpu_cas01.hpp +++ b/src/surf/cpu_cas01.hpp @@ -81,7 +81,6 @@ class CpuCas01Action: public CpuAction { friend CpuActionPtr CpuCas01::execute(double size); friend CpuActionPtr CpuCas01::sleep(double duration); public: - CpuCas01Action() {}; CpuCas01Action(ModelPtr model, double cost, bool failed, double power, lmm_constraint_t constraint); ~CpuCas01Action() {}; diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 7e2203f05c..cd953f58ee 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -213,11 +213,6 @@ public: class CpuAction : public Action { friend CpuPtr getActionCpu(CpuActionPtr action); public: - /** - * @brief CpuAction constructor - */ - CpuAction() {}; - /** * @brief CpuAction constructor * diff --git a/src/surf/cpu_ti.hpp b/src/surf/cpu_ti.hpp index b44ff9713b..752754a285 100644 --- a/src/surf/cpu_ti.hpp +++ b/src/surf/cpu_ti.hpp @@ -159,7 +159,6 @@ class CpuTiAction: public CpuAction { friend void CpuTi::updateRemainingAmount(double now);//FIXME public: - CpuTiAction() {}; CpuTiAction(CpuTiModelPtr model, double cost, bool failed, CpuTiPtr cpu); diff --git a/src/surf/storage_interface.hpp b/src/surf/storage_interface.hpp index d0e7df6038..357200e7a9 100644 --- a/src/surf/storage_interface.hpp +++ b/src/surf/storage_interface.hpp @@ -262,11 +262,6 @@ typedef enum { */ class StorageAction : public Action { public: - /** - * @brief StorageAction constructor - */ - StorageAction() : m_type(READ) {};//FIXME:REMOVE - /** * @brief StorageAction constructor * diff --git a/src/surf/storage_n11.hpp b/src/surf/storage_n11.hpp index 93f4f3a636..d479002b5f 100644 --- a/src/surf/storage_n11.hpp +++ b/src/surf/storage_n11.hpp @@ -70,7 +70,6 @@ public: class StorageN11Action : public StorageAction { public: - StorageN11Action() {}; //FIXME:REMOVE StorageN11Action(ModelPtr model, double cost, bool failed, StoragePtr storage, e_surf_action_storage_type_t type); void suspend(); int unref(); diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 93506d614b..7cf6ef8b67 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -759,26 +759,29 @@ const char *surf_action_state_names[6] = { "SURF_ACTION_NOT_IN_THE_SYSTEM" }; -Action::Action() -: m_refcount(1) -{} +void Action::initialize(ModelPtr model, double cost, bool failed, + lmm_variable_t var) +{ + m_priority = 1.0; + m_refcount = 1; + m_remains = cost; + m_maxDuration = NO_MAX_DURATION; + m_finish = -1.0; + m_failed = failed; + m_start = surf_get_clock(); + m_cost = cost; + p_model = model; + p_data = NULL; + p_variable = var; + m_lastValue = 0; + m_lastUpdate = 0; + m_suspended = false; + m_hat = NOTSET; +} Action::Action(ModelPtr model, double cost, bool failed) - : m_priority(1.0) - , m_refcount(1) - , m_remains(cost) - , m_maxDuration(NO_MAX_DURATION) - , m_finish(-1.0) - , m_failed(failed) - , m_start(surf_get_clock()) - , m_cost(cost) - , p_model(model) - , p_data(NULL) - , p_variable(NULL) - , m_lastValue(0) - , m_lastUpdate(0) - , m_suspended(false) { + initialize(model, cost, failed); #ifdef HAVE_TRACING p_category = NULL; #endif @@ -793,21 +796,8 @@ Action::Action(ModelPtr model, double cost, bool failed) } Action::Action(ModelPtr model, double cost, bool failed, lmm_variable_t var) - : m_priority(1.0) - , m_refcount(1) - , m_remains(cost) - , m_maxDuration(NO_MAX_DURATION) - , m_finish(-1.0) - , m_failed(failed) - , m_start(surf_get_clock()) - , m_cost(cost) - , p_model(model) - , p_data(NULL) - , p_variable(var) - , m_lastValue(0) - , m_lastUpdate(0) - , m_suspended(false) { + initialize(model, cost, failed, var); #ifdef HAVE_TRACING p_category = NULL; #endif diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 1b4a4c7909..36b1977761 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -390,12 +390,14 @@ void surf_action_lmm_update_index_heap(void *action, int i); * @details An action is an event generated by a resource (e.g.: a communication for the network) */ class Action : public actionHook, public actionLmmHook { -public: +private: /** - * @brief Action constructor + * @brief Common initializations for the constructors */ - Action(); + void initialize(ModelPtr model, double cost, bool failed, + lmm_variable_t var = NULL); +public: /** * @brief Action constructor * diff --git a/src/surf/workstation_interface.cpp b/src/surf/workstation_interface.cpp index ba19f668d3..f37bff3ae6 100644 --- a/src/surf/workstation_interface.cpp +++ b/src/surf/workstation_interface.cpp @@ -284,8 +284,8 @@ int Workstation::unlink(surf_file_t fd) { // Remove the file from storage xbt_dict_remove(st->p_content, fd->name); - free(fd->name); - free(fd->mount); + xbt_free(fd->name); + xbt_free(fd->mount); xbt_free(fd); return MSG_OK; } diff --git a/src/xbt/win32_ucontext.c b/src/xbt/win32_ucontext.c index 560b06cb1b..b538e09fb9 100644 --- a/src/xbt/win32_ucontext.c +++ b/src/xbt/win32_ucontext.c @@ -4,105 +4,105 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -/* - * win32-ucontext: Unix ucontext_t operations on Windows platforms - * Copyright(C) 2007 Panagiotis E. Hadjidoukas - * - * Contact Email: phadjido@cs.uoi.gr, xdoukas@ceid.upatras.gr - * - * win32-ucontext is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * win32-ucontext 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with SimGrid in the file LICENSE-LGPL-2.1; - * if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "win32_ucontext.h" - -int getcontext(ucontext_t * ucp) -{ - int ret; - - /* Retrieve the full machine context */ - ucp->uc_mcontext.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS; - ret = GetThreadContext(GetCurrentThread(), &ucp->uc_mcontext); - return (ret == 0) ? -1 : 0; -} - -int setcontext(const ucontext_t * ucp) -{ - int ret; - - /* Restore the full machine context (already set) */ - ret = SetThreadContext(GetCurrentThread(), &ucp->uc_mcontext); - return (ret == 0) ? -1 : 0; -} - -int makecontext(ucontext_t * ucp, void (*func) (), int argc, ...) -{ - int i; - va_list ap; - char *sp; - - /* Stack grows down */ - sp = (char *) (size_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size; - - /* Reserve stack space for the arguments (maximum possible: argc*(8 bytes per argument)) */ - sp -= argc * sizeof(void*); - if (sp < (char *) ucp->uc_stack.ss_sp) { - - /* errno = ENOMEM; */ - return -1; - } - - /* Set the instruction and the stack pointer */ - #ifdef _I_X86_ - ucp->uc_mcontext.Eip = (DWORD) func; - ucp->uc_mcontext.Esp = (DWORD) sp - sizeof(void*); - #endif - #ifdef _IA64_ - # error "_IA64_" - #endif - #ifdef _AMD64_ - ucp->uc_mcontext.Rip = (DWORD64) func; - ucp->uc_mcontext.Rsp = (DWORD64) sp - sizeof(void*); - #endif - - /* Save/Restore the full machine context */ - ucp->uc_mcontext.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS; - - /* Copy the arguments */ - va_start(ap, argc); - for (i = 0; i < argc; i++) { - memcpy(sp, ap, sizeof(void*)); - ap += sizeof(void*); - sp += sizeof(void*); - } - va_end(ap); - return 0; -} - -int swapcontext(ucontext_t * oucp, const ucontext_t * ucp) -{ - int ret; - if ((oucp == NULL) || (ucp == NULL)) { - - /*errno = EINVAL; */ - return -1; - } - ret = getcontext(oucp); - if (ret == 0) { - ret = setcontext(ucp); - } - return ret; -} - +/* + * win32-ucontext: Unix ucontext_t operations on Windows platforms + * Copyright(C) 2007 Panagiotis E. Hadjidoukas + * + * Contact Email: phadjido@cs.uoi.gr, xdoukas@ceid.upatras.gr + * + * win32-ucontext is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * win32-ucontext 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with SimGrid in the file LICENSE-LGPL-2.1; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "xbt/win32_ucontext.h" + +int getcontext(ucontext_t * ucp) +{ + int ret; + + /* Retrieve the full machine context */ + ucp->uc_mcontext.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS; + ret = GetThreadContext(GetCurrentThread(), &ucp->uc_mcontext); + return (ret == 0) ? -1 : 0; +} + +int setcontext(const ucontext_t * ucp) +{ + int ret; + + /* Restore the full machine context (already set) */ + ret = SetThreadContext(GetCurrentThread(), &ucp->uc_mcontext); + return (ret == 0) ? -1 : 0; +} + +int makecontext(ucontext_t * ucp, void (*func) (), int argc, ...) +{ + int i; + va_list ap; + char *sp; + + /* Stack grows down */ + sp = (char *) (size_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size; + + /* Reserve stack space for the arguments (maximum possible: argc*(8 bytes per argument)) */ + sp -= argc * sizeof(void*); + if (sp < (char *) ucp->uc_stack.ss_sp) { + + /* errno = ENOMEM; */ + return -1; + } + + /* Set the instruction and the stack pointer */ + #ifdef _I_X86_ + ucp->uc_mcontext.Eip = (DWORD) func; + ucp->uc_mcontext.Esp = (DWORD) sp - sizeof(void*); + #endif + #ifdef _IA64_ + # error "_IA64_" + #endif + #ifdef _AMD64_ + ucp->uc_mcontext.Rip = (DWORD64) func; + ucp->uc_mcontext.Rsp = (DWORD64) sp - sizeof(void*); + #endif + + /* Save/Restore the full machine context */ + ucp->uc_mcontext.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS; + + /* Copy the arguments */ + va_start(ap, argc); + for (i = 0; i < argc; i++) { + memcpy(sp, ap, sizeof(void*)); + ap += sizeof(void*); + sp += sizeof(void*); + } + va_end(ap); + return 0; +} + +int swapcontext(ucontext_t * oucp, const ucontext_t * ucp) +{ + int ret; + if ((oucp == NULL) || (ucp == NULL)) { + + /*errno = EINVAL; */ + return -1; + } + ret = getcontext(oucp); + if (ret == 0) { + ret = setcontext(ucp); + } + return ret; +} + diff --git a/src/xbt/xbt_main.c b/src/xbt/xbt_main.c index 30c1a8427a..3af5c0371d 100644 --- a/src/xbt/xbt_main.c +++ b/src/xbt/xbt_main.c @@ -85,9 +85,13 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, static void xbt_preinit(void) { unsigned int seed = 2147483647; - +#ifndef WIN32 xbt_pagesize = sysconf(_SC_PAGESIZE); - +#else + SYSTEM_INFO si; + GetSystemInfo(&si); + xbt_pagesize = si.dwPageSize; +#endif #ifdef MMALLOC_WANT_OVERRIDE_LEGACY mmalloc_preinit(); #endif diff --git a/src/xbt/xbt_os_thread.c b/src/xbt/xbt_os_thread.c index f29549575c..c9dd6910b9 100644 --- a/src/xbt/xbt_os_thread.c +++ b/src/xbt/xbt_os_thread.c @@ -232,10 +232,14 @@ void xbt_os_thread_setstacksize(int stack_size) void xbt_os_thread_setguardsize(int guard_size) { +#ifdef WIN32 + THROW_UNIMPLEMENTED; //pthread_attr_setguardsize is not implemented in pthread.h on windows +#else size_t sz = guard_size; int res = pthread_attr_setguardsize(&thread_attr, sz); if (res) XBT_WARN("pthread_attr_setguardsize failed (%d) for size: %zd", res, sz); +#endif } const char *xbt_os_thread_name(xbt_os_thread_t t)