mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 19:16:43 +00:00
[Sanitizer] add internal_{close,read,write} functions to sanitizer_libc
llvm-svn: 157990
This commit is contained in:
parent
696835bb03
commit
03c8b846c4
@ -33,7 +33,11 @@ void *internal_mmap(void *addr, uptr length, int prot, int flags,
|
||||
int fd, u64 offset);
|
||||
|
||||
typedef int fd_t;
|
||||
const fd_t kInvalidFd = -1;
|
||||
int internal_close(fd_t fd);
|
||||
fd_t internal_open(const char *filename, bool write);
|
||||
uptr internal_read(fd_t fd, void *buf, uptr count);
|
||||
uptr internal_write(fd_t fd, const void *buf, uptr count);
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
|
@ -34,11 +34,23 @@ void *internal_mmap(void *addr, uptr length, int prot, int flags,
|
||||
#endif
|
||||
}
|
||||
|
||||
int internal_close(fd_t fd) {
|
||||
return syscall(__NR_close, fd);
|
||||
}
|
||||
|
||||
fd_t internal_open(const char *filename, bool write) {
|
||||
return syscall(__NR_open, filename,
|
||||
write ? O_WRONLY | O_CREAT | O_CLOEXEC : O_RDONLY, 0660);
|
||||
}
|
||||
|
||||
uptr internal_read(fd_t fd, void *buf, uptr count) {
|
||||
return (uptr)syscall(__NR_read, fd, buf, count);
|
||||
}
|
||||
|
||||
uptr internal_write(fd_t fd, const void *buf, uptr count) {
|
||||
return (uptr)syscall(__NR_write, fd, buf, count);
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
#endif // __linux__
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace __sanitizer {
|
||||
|
||||
@ -29,11 +30,23 @@ void *internal_mmap(void *addr, size_t length, int prot, int flags,
|
||||
return mmap(addr, length, prot, flags, fd, offset);
|
||||
}
|
||||
|
||||
int internal_close(fd_t fd) {
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
fd_t internal_open(const char *filename, bool write) {
|
||||
return open(filename,
|
||||
write ? O_WRONLY | O_CREAT | O_CLOEXEC : O_RDONLY, 0660);
|
||||
}
|
||||
|
||||
uptr internal_read(fd_t fd, void *buf, uptr count) {
|
||||
return read(fd, buf, count);
|
||||
}
|
||||
|
||||
uptr internal_write(fd_t fd, const void *buf, uptr count) {
|
||||
return write(fd, buf, count);
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
#endif // __APPLE__
|
||||
|
@ -29,11 +29,35 @@ void *internal_mmap(void *addr, uptr length, int prot, int flags,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int internal_close(fd_t fd) {
|
||||
UNIMPLEMENTED_WIN();
|
||||
return 0;
|
||||
}
|
||||
|
||||
fd_t internal_open(const char *filename, bool write) {
|
||||
UNIMPLEMENTED_WIN();
|
||||
return 0;
|
||||
}
|
||||
|
||||
uptr internal_read(fd_t fd, void *buf, uptr count) {
|
||||
UNIMPLEMENTED_WIN();
|
||||
return 0;
|
||||
}
|
||||
|
||||
uptr internal_write(fd_t fd, const void *buf, uptr count) {
|
||||
if (fd != 2) {
|
||||
UNIMPLEMENTED_WIN();
|
||||
return 0;
|
||||
}
|
||||
HANDLE err = GetStdHandle(STD_ERROR_HANDLE);
|
||||
if (err == 0)
|
||||
return 0; // FIXME: this might not work on some apps.
|
||||
DWORD ret;
|
||||
if (!WriteFile(err, buf, count, &ret, 0))
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
#endif // _WIN32
|
||||
|
Loading…
x
Reference in New Issue
Block a user