Once we start instrumenting globals, all addresses including those of string literals that we pass to the operating system will start being tagged. Since we can't rely on the operating system to be able to cope with these addresses, we need to untag them before passing them to the operating system. This change introduces a macro that does so and uses it everywhere it is needed. Differential Revision: https://reviews.llvm.org/D65768 llvm-svn: 367938
31 lines
655 B
C
31 lines
655 B
C
#pragma once
|
|
|
|
#include <stdarg.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#define UNTAG(x) (typeof((x) + 0))(((uintptr_t)(x)) & 0xffffffffffffff)
|
|
|
|
__attribute__((no_sanitize("hwaddress")))
|
|
int untag_printf(const char *fmt, ...) {
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
int ret = vprintf(UNTAG(fmt), ap);
|
|
va_end(ap);
|
|
return ret;
|
|
}
|
|
|
|
__attribute__((no_sanitize("hwaddress")))
|
|
int untag_fprintf(FILE *stream, const char *fmt, ...) {
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
int ret = vfprintf(stream, UNTAG(fmt), ap);
|
|
va_end(ap);
|
|
return ret;
|
|
}
|
|
|
|
int untag_strcmp(const char *s1, const char *s2) {
|
|
return strcmp(UNTAG(s1), UNTAG(s2));
|
|
}
|