From 7d3a8cb8a5b8a4b7e077e6cf1a8c81fb66d0354c Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Mon, 11 Apr 2016 19:25:46 +0100 Subject: [PATCH 1/2] Better error reporting. Copied from Perforce Change: 190944 ServerID: perforce.ravenbrook.com --- mps/tool/noaslr.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/mps/tool/noaslr.c b/mps/tool/noaslr.c index 3ae73dc9362..7dbf58f8303 100644 --- a/mps/tool/noaslr.c +++ b/mps/tool/noaslr.c @@ -1,7 +1,7 @@ /* noaslr.c: Disable ASLR on OS X Mavericks * * $Id: //info.ravenbrook.com/project/mps/master/code/eventcnv.c#26 $ - * Copyright (c) 2014 Ravenbrook Limited. See end of file for license. + * Copyright (c) 2014-2016 Ravenbrook Limited. See end of file for license. * * This is a command-line tool that runs another program with address * space layout randomization (ASLR) disabled. @@ -16,6 +16,7 @@ * */ +#include #include #include #include @@ -31,6 +32,7 @@ int main(int argc, char **argv) pid_t pid; posix_spawnattr_t attr; int res, status = 1; + const char *program = argv[0]; char *default_argv[] = {"/bin/sh", NULL}; if (argc >= 2) @@ -39,16 +41,25 @@ int main(int argc, char **argv) argv = default_argv; res = posix_spawnattr_init(&attr); - if (res != 0) + if (res != 0) { + errno = res; + perror(program); return res; + } res = posix_spawnattr_setflags(&attr, _POSIX_SPAWN_DISABLE_ASLR); - if (res != 0) + if (res != 0) { + errno = res; + perror(program); return res; + } res = posix_spawn(&pid, argv[0], NULL, &attr, argv, environ); - if (res != 0) + if (res != 0) { + errno = res; + perror(program); return res; + } if (waitpid(pid, &status, 0) == -1) return 1; @@ -62,7 +73,7 @@ int main(int argc, char **argv) /* C. COPYRIGHT AND LICENSE * - * Copyright (C) 2014 Ravenbrook Limited . + * Copyright (C) 2014-2016 Ravenbrook Limited . * All rights reserved. This is an open source license. Contact * Ravenbrook for commercial licensing options. * From 72d14e139f504e6aa28767a1176db61e7f9f333f Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Tue, 12 Apr 2016 18:16:06 +0100 Subject: [PATCH 2/2] Guarding eventinit with the global lock, and removing the enforcement of the reference count, so that the event system can be used from classes, which get called before any arena. Copied from Perforce Change: 191018 ServerID: perforce.ravenbrook.com --- mps/code/event.c | 51 ++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/mps/code/event.c b/mps/code/event.c index cf9d4e0a8b5..0a15e064db3 100644 --- a/mps/code/event.c +++ b/mps/code/event.c @@ -1,19 +1,12 @@ /* event.c: EVENT LOGGING * * $Id$ - * Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license. + * Copyright (c) 2001-2016 Ravenbrook Limited. See end of file for license. * * .sources: mps.design.event * * TRANSGRESSIONS (rule.impl.trans) * - * .trans.ref: The reference counting used to destroy the mps_io object - * isn't right. - * - * .trans.log: The log file will be re-created if the lifetimes of - * arenas don't overlap, but shared if they do. mps_io_create cannot - * be called twice, but EventInit avoids this anyway. - * * .trans.ifdef: This file should logically be split into two, event.c * (which contains NOOP definitions, for general use) and eventdl.c, which * is specific to the logging variety and actually does logging (maybe). @@ -24,6 +17,7 @@ #include "mpm.h" #include "event.h" #include "mpsio.h" +#include "lock.h" SRCID(event, "$Id$"); @@ -34,7 +28,6 @@ SRCID(event, "$Id$"); static Bool eventInited = FALSE; static Bool eventIOInited = FALSE; static mps_io_t eventIO; -static Count eventUserCount; static Serial EventInternSerial; /* Buffers in which events are recorded, from the top down. */ @@ -207,25 +200,26 @@ void EventInit(void) AVER(EventBufferSIZE <= EventSizeMAX); /* Only if this is the first call. */ - if(!eventInited) { /* See .trans.log */ - EventKind kind; - for (kind = 0; kind < EventKindLIMIT; ++kind) { - AVER(EventLast[kind] == NULL); - AVER(EventWritten[kind] == NULL); - EventLast[kind] = EventWritten[kind] = EventBuffer[kind] + EventBufferSIZE; + if (!eventInited) { /* See .trans.log */ + LockClaimGlobalRecursive(); + if (!eventInited) { + EventKind kind; + for (kind = 0; kind < EventKindLIMIT; ++kind) { + AVER(EventLast[kind] == NULL); + AVER(EventWritten[kind] == NULL); + EventLast[kind] = EventWritten[kind] = EventBuffer[kind] + EventBufferSIZE; + } + eventInited = TRUE; + EventKindControl = (Word)mps_lib_telemetry_control(); + EventInternSerial = (Serial)1; /* 0 is reserved */ + (void)EventInternString(MPSVersion()); /* emit version */ + EVENT7(EventInit, EVENT_VERSION_MAJOR, EVENT_VERSION_MEDIAN, + EVENT_VERSION_MINOR, EventCodeMAX, EventNameMAX, MPS_WORD_WIDTH, + mps_clocks_per_sec()); + /* flush these initial events to get the first ClockSync out. */ + EventSync(); } - eventUserCount = (Count)1; - eventInited = TRUE; - EventKindControl = (Word)mps_lib_telemetry_control(); - EventInternSerial = (Serial)1; /* 0 is reserved */ - (void)EventInternString(MPSVersion()); /* emit version */ - EVENT7(EventInit, EVENT_VERSION_MAJOR, EVENT_VERSION_MEDIAN, - EVENT_VERSION_MINOR, EventCodeMAX, EventNameMAX, MPS_WORD_WIDTH, - mps_clocks_per_sec()); - /* flush these initial events to get the first ClockSync out. */ - EventSync(); - } else { - ++eventUserCount; + LockReleaseGlobalRecursive(); } } @@ -235,11 +229,8 @@ void EventInit(void) void EventFinish(void) { AVER(eventInited); - AVER(eventUserCount > 0); EventSync(); - - --eventUserCount; }