diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/unexmacosx.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/unexmacosx.c b/src/unexmacosx.c index 827eda56e08..bdacc8b540b 100644 --- a/src/unexmacosx.c +++ b/src/unexmacosx.c | |||
| @@ -103,9 +103,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 103 | #include <stdio.h> | 103 | #include <stdio.h> |
| 104 | #include <fcntl.h> | 104 | #include <fcntl.h> |
| 105 | #include <stdarg.h> | 105 | #include <stdarg.h> |
| 106 | #include <stdint.h> | ||
| 106 | #include <sys/types.h> | 107 | #include <sys/types.h> |
| 107 | #include <unistd.h> | 108 | #include <unistd.h> |
| 108 | #include <mach/mach.h> | 109 | #include <mach/mach.h> |
| 110 | #include <mach/vm_map.h> | ||
| 109 | #include <mach-o/loader.h> | 111 | #include <mach-o/loader.h> |
| 110 | #include <mach-o/reloc.h> | 112 | #include <mach-o/reloc.h> |
| 111 | #ifdef HAVE_MALLOC_MALLOC_H | 113 | #ifdef HAVE_MALLOC_MALLOC_H |
| @@ -217,10 +219,27 @@ unexec_read (void *dest, size_t n) | |||
| 217 | static int | 219 | static int |
| 218 | unexec_write (off_t dest, const void *src, size_t count) | 220 | unexec_write (off_t dest, const void *src, size_t count) |
| 219 | { | 221 | { |
| 222 | task_t task = mach_task_self(); | ||
| 223 | if (task == MACH_PORT_NULL || task == MACH_PORT_DEAD) | ||
| 224 | return false; | ||
| 225 | |||
| 220 | if (lseek (outfd, dest, SEEK_SET) != dest) | 226 | if (lseek (outfd, dest, SEEK_SET) != dest) |
| 221 | return 0; | 227 | return 0; |
| 222 | 228 | ||
| 223 | return write (outfd, src, count) == count; | 229 | /* We use the Mach virtual memory API to read our process memory |
| 230 | because using src directly would be undefined behavior and fails | ||
| 231 | under Address Sanitizer. */ | ||
| 232 | bool success = false; | ||
| 233 | vm_offset_t data; | ||
| 234 | mach_msg_type_number_t data_count; | ||
| 235 | if (vm_read (task, (uintptr_t) src, count, &data, &data_count) | ||
| 236 | == KERN_SUCCESS) | ||
| 237 | { | ||
| 238 | success = | ||
| 239 | write (outfd, (const void *) (uintptr_t) data, data_count) == count; | ||
| 240 | vm_deallocate (task, data, data_count); | ||
| 241 | } | ||
| 242 | return success; | ||
| 224 | } | 243 | } |
| 225 | 244 | ||
| 226 | /* Write COUNT bytes of zeros to outfd starting at offset DEST. | 245 | /* Write COUNT bytes of zeros to outfd starting at offset DEST. |