X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/cd1ed48ddbbb487a40bbf2ecc55ca1d8377c1819..d267aea2424783f5eefb6e733a6806ffd3323fa0:/src/unexmacosx.c diff --git a/src/unexmacosx.c b/src/unexmacosx.c index 89971bb8a7..bdacc8b540 100644 --- a/src/unexmacosx.c +++ b/src/unexmacosx.c @@ -1,12 +1,12 @@ /* Dump Emacs in Mach-O format for use on Mac OS X. - Copyright (C) 2001-2014 Free Software Foundation, Inc. + Copyright (C) 2001-2016 Free Software Foundation, Inc. This file is part of GNU Emacs. GNU Emacs is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. +the Free Software Foundation, either version 3 of the License, or (at +your option) any later version. GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -99,12 +99,15 @@ along with GNU Emacs. If not, see . */ #include "unexec.h" #include "lisp.h" +#include #include #include #include +#include #include #include #include +#include #include #include #ifdef HAVE_MALLOC_MALLOC_H @@ -216,10 +219,27 @@ unexec_read (void *dest, size_t n) static int unexec_write (off_t dest, const void *src, size_t count) { + task_t task = mach_task_self(); + if (task == MACH_PORT_NULL || task == MACH_PORT_DEAD) + return false; + if (lseek (outfd, dest, SEEK_SET) != dest) return 0; - return write (outfd, src, count) == count; + /* We use the Mach virtual memory API to read our process memory + because using src directly would be undefined behavior and fails + under Address Sanitizer. */ + bool success = false; + vm_offset_t data; + mach_msg_type_number_t data_count; + if (vm_read (task, (uintptr_t) src, count, &data, &data_count) + == KERN_SUCCESS) + { + success = + write (outfd, (const void *) (uintptr_t) data, data_count) == count; + vm_deallocate (task, data, data_count); + } + return success; } /* Write COUNT bytes of zeros to outfd starting at offset DEST. @@ -1264,14 +1284,14 @@ unexec (const char *outfile, const char *infile) infd = emacs_open (infile, O_RDONLY, 0); if (infd < 0) { - unexec_error ("cannot open input file `%s'", infile); + unexec_error ("%s: %s", infile, strerror (errno)); } outfd = emacs_open (outfile, O_WRONLY | O_TRUNC | O_CREAT, 0777); if (outfd < 0) { emacs_close (infd); - unexec_error ("cannot open output file `%s'", outfile); + unexec_error ("%s: %s", outfile, strerror (errno)); } build_region_list ();