Bring loader in sync with stg/sc

Change-Id: I684522c442de0872007a7e4da8919067fc7b42b3


[ROCm/ROCR-Runtime commit: c798c60343]
This commit is contained in:
Konstantin Zhuravlyov
2016-12-13 16:30:25 -05:00
parent 046929d5ac
commit cdcc5ec921
12 ha cambiato i file con 1179 aggiunte e 133 eliminazioni
@@ -41,6 +41,7 @@
////////////////////////////////////////////////////////////////////////////////
#include "amd_elf_image.hpp"
#include "amd_hsa_code_util.hpp"
#include <gelf.h>
#include <errno.h>
#include <cstring>
@@ -50,7 +51,6 @@
#include <cassert>
#include <cstdlib>
#include <algorithm>
#include "amd_hsa_code_util.hpp"
#ifdef _WIN32
#include <Windows.h>
#define alignof __alignof
@@ -60,17 +60,38 @@
#ifndef _WIN32
#define _open open
#define _close close
#define _tempnam tempnam
#include <fcntl.h>
#include <unistd.h>
#endif
#if defined(USE_MEMFILE)
#include "memfile.h"
#define OpenTemp(f) mem_open(NULL, 0, 0)
#define CloseTemp(f) mem_close(f)
#define _read(f, b, l) mem_read((f), (b), (l))
#define _write(f, b, l) mem_write((f), (b), (l))
#define _lseek(f, l, w) mem_lseek((f), (l), (w))
#define _ftruncate(f, l) mem_ftruncate((f), (size_t)(l))
#define sendfile(o, i, p, s) mem_sendfile((o), (i), (p), (s))
#else // USE_MEMFILE
#define OpenTemp(f) amd::hsa::OpenTempFile(f);
#define CloseTemp(f) amd::hsa::CloseTempFile(f);
#ifndef _WIN32
#define _read read
#define _write write
#define _lseek lseek
#define _ftruncate ftruncate
#define _tempnam tempnam
#include <sys/sendfile.h>
#include <fcntl.h>
#include <unistd.h>
#else
#define _ftruncate _chsize
#endif
#endif // !_WIN32
#endif // !USE_MEMFILE
#if !defined(BSD_LIBELF)
#define elf_setshstrndx elfx_update_shstrndx
@@ -115,7 +136,7 @@ namespace amd {
FileImage::~FileImage()
{
if (d >= 0) { amd::hsa::CloseTempFile(d); }
if (d != -1) { CloseTemp(d); }
}
bool FileImage::error(const char* msg)
@@ -153,8 +174,8 @@ namespace amd {
bool FileImage::create()
{
d = amd::hsa::OpenTempFile("amdelf");
if (d < 0) { return error("Failed to open temporary file for elf image"); }
d = OpenTemp("amdelf");
if (d == -1) { return error("Failed to open temporary file for elf image"); }
return true;
}