diff options
Diffstat (limited to 'main/xbmc/fix-fileemu.patch')
-rw-r--r-- | main/xbmc/fix-fileemu.patch | 449 |
1 files changed, 449 insertions, 0 deletions
diff --git a/main/xbmc/fix-fileemu.patch b/main/xbmc/fix-fileemu.patch new file mode 100644 index 0000000000..f853168c63 --- /dev/null +++ b/main/xbmc/fix-fileemu.patch @@ -0,0 +1,449 @@ +diff -ru xbmc-12.3-Frodo.orig/xbmc/cores/DllLoader/exports/emu_msvcrt.cpp xbmc-12.3-Frodo/xbmc/cores/DllLoader/exports/emu_msvcrt.cpp +--- xbmc-12.3-Frodo.orig/xbmc/cores/DllLoader/exports/emu_msvcrt.cpp 2013-12-12 21:47:49.000000000 +0000 ++++ xbmc-12.3-Frodo/xbmc/cores/DllLoader/exports/emu_msvcrt.cpp 2014-04-15 07:51:22.843024856 +0000 +@@ -49,6 +49,7 @@ + #include <fcntl.h> + #include <time.h> + #include <signal.h> ++#include <paths.h> + #ifdef _LINUX + #include "PlatformDefs.h" // for __stat64 + #endif +@@ -479,13 +480,10 @@ + EmuFileObject* o = g_emuFileWrapper.GetFileObjectByDescriptor(fd); + if (o) + { +- if(!o->used) +- return NULL; +- + int nmode = convert_fmode(mode); + if( (o->mode & nmode) != nmode) + CLog::Log(LOGWARNING, "dll_fdopen - mode 0x%x differs from fd mode 0x%x", nmode, o->mode); +- return &o->file_emu; ++ return g_emuFileWrapper.GetStreamByFileObject(o); + } + else if (!IS_STD_DESCRIPTOR(fd)) + { +@@ -548,7 +546,7 @@ + return -1; + } + object->mode = iMode; +- return g_emuFileWrapper.GetDescriptorByStream(&object->file_emu); ++ return g_emuFileWrapper.GetDescriptorByFileObject(object); + } + delete pFile; + return -1; +@@ -1194,8 +1192,8 @@ + { + FILE* file = NULL; + #if defined(_LINUX) && !defined(TARGET_DARWIN) && !defined(__FreeBSD__) && !defined(__ANDROID__) +- if (strcmp(filename, MOUNTED) == 0 +- || strcmp(filename, MNTTAB) == 0) ++ if (strcmp(filename, _PATH_MOUNTED) == 0 ++ || strcmp(filename, _PATH_MNTTAB) == 0) + { + CLog::Log(LOGINFO, "%s - something opened the mount file, let's hope it knows what it's doing", __FUNCTION__); + return fopen(filename, mode); +@@ -1586,7 +1584,7 @@ + int ret; + + ret = dll_fgetpos64(stream, &tmpPos); +-#if !defined(_LINUX) || defined(TARGET_DARWIN) || defined(__FreeBSD__) || defined(__ANDROID__) ++#if !defined(GLIBC) || defined(TARGET_DARWIN) || defined(__FreeBSD__) || defined(__ANDROID__) + *pos = (fpos_t)tmpPos; + #else + pos->__pos = (off_t)tmpPos.__pos; +@@ -1599,8 +1597,9 @@ + CFile* pFile = g_emuFileWrapper.GetFileXbmcByStream(stream); + if (pFile != NULL) + { +-#if !defined(_LINUX) || defined(TARGET_DARWIN) || defined(__FreeBSD__) || defined(__ANDROID__) +- *pos = pFile->GetPosition(); ++#if !defined(GLIBC) || defined(TARGET_DARWIN) || defined(__FreeBSD__) || defined(__ANDROID__) ++ uint64_t *ppos = (uint64_t *) pos; ++ *ppos = pFile->GetPosition(); + #else + pos->__pos = pFile->GetPosition(); + #endif +@@ -1621,8 +1620,9 @@ + int fd = g_emuFileWrapper.GetDescriptorByStream(stream); + if (fd >= 0) + { +-#if !defined(_LINUX) || defined(TARGET_DARWIN) || defined(__FreeBSD__) || defined(__ANDROID__) +- if (dll_lseeki64(fd, *pos, SEEK_SET) >= 0) ++#if !defined(GLIBC) || defined(TARGET_DARWIN) || defined(__FreeBSD__) || defined(__ANDROID__) ++ const uint64_t *ppos = (const uint64_t *) pos; ++ if (dll_lseeki64(fd, *ppos, SEEK_SET) >= 0) + #else + if (dll_lseeki64(fd, (__off64_t)pos->__pos, SEEK_SET) >= 0) + #endif +@@ -1654,7 +1654,7 @@ + if (fd >= 0) + { + fpos64_t tmpPos; +-#if !defined(_LINUX) || defined(TARGET_DARWIN) || defined(__FreeBSD__) || defined(__ANDROID__) ++#if !defined(GLIBC) || defined(TARGET_DARWIN) || defined(__FreeBSD__) || defined(__ANDROID__) + tmpPos= *pos; + #else + tmpPos.__pos = (off64_t)(pos->__pos); +diff -ru xbmc-12.3-Frodo.orig/xbmc/cores/DllLoader/exports/emu_msvcrt.h xbmc-12.3-Frodo/xbmc/cores/DllLoader/exports/emu_msvcrt.h +--- xbmc-12.3-Frodo.orig/xbmc/cores/DllLoader/exports/emu_msvcrt.h 2014-04-15 05:52:42.214313750 +0000 ++++ xbmc-12.3-Frodo/xbmc/cores/DllLoader/exports/emu_msvcrt.h 2014-04-15 05:55:24.897232874 +0000 +@@ -26,7 +26,7 @@ + #define _onexit_t void* + #endif + +-#if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD) ++#if defined(TARGET_DARWIN) || defined(TARGET_FREEBSD) || !defined(GLIBC) + typedef off_t __off_t; + typedef int64_t off64_t; + typedef off64_t __off64_t; +@@ -46,9 +46,9 @@ + + typedef void ( *PFV)(void); + +-#define __IS_STDIN_STREAM(stream) (stream == stdin || stream->_file == stdin->_file || stream->_file == 0) +-#define __IS_STDOUT_STREAM(stream) (stream == stdout || stream->_file == stdout->_file || stream->_file == 1) +-#define __IS_STDERR_STREAM(stream) (stream == stderr || stream->_file == stderr->_file || stream->_file == 2) ++#define __IS_STDIN_STREAM(stream) (stream == stdin || fileno(stream) == fileno(stdin) || fileno(stream) == 0) ++#define __IS_STDOUT_STREAM(stream) (stream == stdout || fileno(stream) == fileno(stdout) || fileno(stream) == 1) ++#define __IS_STDERR_STREAM(stream) (stream == stderr || fileno(stream) == fileno(stderr) || fileno(stream) == 2) + #define IS_STDIN_STREAM(stream) (stream != NULL && __IS_STDIN_STREAM(stream)) + #define IS_STDOUT_STREAM(stream) (stream != NULL && __IS_STDOUT_STREAM(stream)) + #define IS_STDERR_STREAM(stream) (stream != NULL && __IS_STDERR_STREAM(stream)) +diff -ru xbmc-12.3-Frodo.orig/xbmc/cores/DllLoader/exports/util/EmuFileWrapper.cpp xbmc-12.3-Frodo/xbmc/cores/DllLoader/exports/util/EmuFileWrapper.cpp +--- xbmc-12.3-Frodo.orig/xbmc/cores/DllLoader/exports/util/EmuFileWrapper.cpp 2013-12-12 21:47:49.000000000 +0000 ++++ xbmc-12.3-Frodo/xbmc/cores/DllLoader/exports/util/EmuFileWrapper.cpp 2014-04-15 09:48:39.551659175 +0000 +@@ -27,12 +27,7 @@ + CEmuFileWrapper::CEmuFileWrapper() + { + // since we always use dlls we might just initialize it directly +- for (int i = 0; i < MAX_EMULATED_FILES; i++) +- { +- memset(&m_files[i], 0, sizeof(EmuFileObject)); +- m_files[i].used = false; +- m_files[i].file_emu._file = -1; +- } ++ memset(m_files, 0, sizeof(m_files)); + } + + CEmuFileWrapper::~CEmuFileWrapper() +@@ -43,22 +38,7 @@ + { + CSingleLock lock(m_criticalSection); + for (int i = 0; i < MAX_EMULATED_FILES; i++) +- { +- if (m_files[i].used) +- { +- m_files[i].file_xbmc->Close(); +- delete m_files[i].file_xbmc; +- +- if (m_files[i].file_lock) +- { +- delete m_files[i].file_lock; +- m_files[i].file_lock = NULL; +- } +- memset(&m_files[i], 0, sizeof(EmuFileObject)); +- m_files[i].used = false; +- m_files[i].file_emu._file = -1; +- } +- } ++ UnRegisterFileObject(&m_files[i], true); + } + + EmuFileObject* CEmuFileWrapper::RegisterFileObject(XFILE::CFile* pFile) +@@ -69,13 +49,11 @@ + + for (int i = 0; i < MAX_EMULATED_FILES; i++) + { +- if (!m_files[i].used) ++ if (!m_files[i].file_xbmc) + { + // found a free location + object = &m_files[i]; +- object->used = true; + object->file_xbmc = pFile; +- object->file_emu._file = (i + FILE_WRAPPER_OFFSET); + object->file_lock = new CCriticalSection(); + break; + } +@@ -84,82 +62,71 @@ + return object; + } + +-void CEmuFileWrapper::UnRegisterFileObjectByDescriptor(int fd) ++void CEmuFileWrapper::UnRegisterFileObject(EmuFileObject *object, bool free_file) + { +- int i = fd - FILE_WRAPPER_OFFSET; +- if (i >= 0 && i < MAX_EMULATED_FILES) ++ if (object && object->file_xbmc) + { +- if (m_files[i].used) ++ if (object->file_xbmc && free_file) + { +- CSingleLock lock(m_criticalSection); +- +- // we assume the emulated function alreay deleted the CFile object +- if (m_files[i].used) +- { +- if (m_files[i].file_lock) +- { +- delete m_files[i].file_lock; +- m_files[i].file_lock = NULL; +- } +- memset(&m_files[i], 0, sizeof(EmuFileObject)); +- m_files[i].used = false; +- m_files[i].file_emu._file = -1; +- } ++ object->file_xbmc->Close(); ++ delete object->file_xbmc; + } ++ if (object->file_lock) ++ { ++ delete object->file_lock; ++ } ++ ++ memset(object, 0, sizeof(*object)); + } + } + ++void CEmuFileWrapper::UnRegisterFileObjectByDescriptor(int fd) ++{ ++ CSingleLock lock(m_criticalSection); ++ UnRegisterFileObject(GetFileObjectByDescriptor(fd), false); ++} ++ + void CEmuFileWrapper::UnRegisterFileObjectByStream(FILE* stream) + { +- if (stream != NULL) +- { +- return UnRegisterFileObjectByDescriptor(stream->_file); +- } ++ CSingleLock lock(m_criticalSection); ++ UnRegisterFileObject(GetFileObjectByStream(stream), false); + } + + void CEmuFileWrapper::LockFileObjectByDescriptor(int fd) + { +- int i = fd - FILE_WRAPPER_OFFSET; +- if (i >= 0 && i < MAX_EMULATED_FILES) ++ EmuFileObject* object = GetFileObjectByDescriptor(fd); ++ if (object && object->file_xbmc) + { +- if (m_files[i].used) +- { +- m_files[i].file_lock->lock(); +- } ++ object->file_lock->lock(); + } + } + + bool CEmuFileWrapper::TryLockFileObjectByDescriptor(int fd) +-{ +- int i = fd - FILE_WRAPPER_OFFSET; +- if (i >= 0 && i < MAX_EMULATED_FILES) +- { +- if (m_files[i].used) +- { +- return m_files[i].file_lock->try_lock(); +- } ++{ ++ EmuFileObject* object = GetFileObjectByDescriptor(fd); ++ if (object && object->file_xbmc) ++ { ++ return object->file_lock->try_lock(); + } ++ + return false; + } + + void CEmuFileWrapper::UnlockFileObjectByDescriptor(int fd) +-{ +- int i = fd - FILE_WRAPPER_OFFSET; +- if (i >= 0 && i < MAX_EMULATED_FILES) +- { +- if (m_files[i].used) +- { +- m_files[i].file_lock->unlock(); +- } ++{ ++ EmuFileObject* object = GetFileObjectByDescriptor(fd); ++ if (object && object->file_xbmc) ++ { ++ object->file_lock->unlock(); + } + } + + EmuFileObject* CEmuFileWrapper::GetFileObjectByDescriptor(int fd) + { +- int i = fd - FILE_WRAPPER_OFFSET; ++ int i = fd - 0x7000000; + if (i >= 0 && i < MAX_EMULATED_FILES) + { +- if (m_files[i].used) ++ if (m_files[i].file_xbmc) + { + return &m_files[i]; + } +@@ -167,20 +134,38 @@ + return NULL; + } + +-EmuFileObject* CEmuFileWrapper::GetFileObjectByStream(FILE* stream) ++int CEmuFileWrapper::GetDescriptorByFileObject(EmuFileObject *object) + { +- if (stream != NULL) ++ int i = object - m_files; ++ if (i >= 0 && i < MAX_EMULATED_FILES) + { +- return GetFileObjectByDescriptor(stream->_file); ++ return 0x7000000 + i; + } ++ return -1; ++} + ++EmuFileObject* CEmuFileWrapper::GetFileObjectByStream(FILE* stream) ++{ ++ EmuFileObject *object = (EmuFileObject*) stream; ++ if (object >= &m_files[0] || object < &m_files[MAX_EMULATED_FILES]) ++ { ++ if (object->file_xbmc) ++ { ++ return object; ++ } ++ } + return NULL; + } + ++FILE* CEmuFileWrapper::GetStreamByFileObject(EmuFileObject *object) ++{ ++ return (FILE*) object; ++} ++ + XFILE::CFile* CEmuFileWrapper::GetFileXbmcByDescriptor(int fd) + { + EmuFileObject* object = GetFileObjectByDescriptor(fd); +- if (object != NULL && object->used) ++ if (object != NULL) + { + return object->file_xbmc; + } +@@ -191,8 +176,8 @@ + { + if (stream != NULL) + { +- EmuFileObject* object = GetFileObjectByDescriptor(stream->_file); +- if (object != NULL && object->used) ++ EmuFileObject* object = GetFileObjectByStream(stream); ++ if (object != NULL) + { + return object->file_xbmc; + } +@@ -202,42 +187,20 @@ + + int CEmuFileWrapper::GetDescriptorByStream(FILE* stream) + { +- if (stream != NULL) +- { +- int i = stream->_file - FILE_WRAPPER_OFFSET; +- if (i >= 0 && i < MAX_EMULATED_FILES) +- { +- return stream->_file; +- } +- } +- return -1; ++ return GetDescriptorByFileObject(GetFileObjectByStream(stream)); + } + + FILE* CEmuFileWrapper::GetStreamByDescriptor(int fd) + { +- EmuFileObject* object = GetFileObjectByDescriptor(fd); +- if (object != NULL && object->used) +- { +- return &object->file_emu; +- } +- return NULL; ++ return GetStreamByFileObject(GetFileObjectByDescriptor(fd)); + } + + bool CEmuFileWrapper::DescriptorIsEmulatedFile(int fd) + { +- int i = fd - FILE_WRAPPER_OFFSET; +- if (i >= 0 && i < MAX_EMULATED_FILES) +- { +- return true; +- } +- return false; ++ return GetFileObjectByDescriptor(fd) != NULL; + } + + bool CEmuFileWrapper::StreamIsEmulatedFile(FILE* stream) + { +- if (stream != NULL) +- { +- return DescriptorIsEmulatedFile(stream->_file); +- } +- return false; ++ return GetFileObjectByStream(stream) != NULL; + } +diff -ru xbmc-12.3-Frodo.orig/xbmc/cores/DllLoader/exports/util/EmuFileWrapper.h xbmc-12.3-Frodo/xbmc/cores/DllLoader/exports/util/EmuFileWrapper.h +--- xbmc-12.3-Frodo.orig/xbmc/cores/DllLoader/exports/util/EmuFileWrapper.h 2014-04-15 05:52:42.214313750 +0000 ++++ xbmc-12.3-Frodo/xbmc/cores/DllLoader/exports/util/EmuFileWrapper.h 2014-04-15 08:00:04.209129880 +0000 +@@ -27,12 +27,7 @@ + #include "system.h" + #include "threads/CriticalSection.h" + +-#if defined(_LINUX) && !defined(TARGET_DARWIN) && !defined(__FreeBSD__) && !defined(__ANDROID__) +-#define _file _fileno +-#endif +- + #define MAX_EMULATED_FILES 50 +-#define FILE_WRAPPER_OFFSET 0x00000100 + + namespace XFILE + { +@@ -41,11 +36,9 @@ + + typedef struct stEmuFileObject + { +- bool used; +- FILE file_emu; +- XFILE::CFile* file_xbmc; ++ XFILE::CFile* file_xbmc; + CCriticalSection *file_lock; +- int mode; ++ int mode; + } EmuFileObject; + + class CEmuFileWrapper +@@ -60,13 +53,16 @@ + void CleanUp(); + + EmuFileObject* RegisterFileObject(XFILE::CFile* pFile); ++ void UnRegisterFileObject(EmuFileObject*, bool free_file); + void UnRegisterFileObjectByDescriptor(int fd); + void UnRegisterFileObjectByStream(FILE* stream); + void LockFileObjectByDescriptor(int fd); + bool TryLockFileObjectByDescriptor(int fd); + void UnlockFileObjectByDescriptor(int fd); +- EmuFileObject* GetFileObjectByDescriptor(int fd); +- EmuFileObject* GetFileObjectByStream(FILE* stream); ++ EmuFileObject* GetFileObjectByDescriptor(int fd); ++ int GetDescriptorByFileObject(EmuFileObject*); ++ EmuFileObject* GetFileObjectByStream(FILE* stream); ++ FILE* GetStreamByFileObject(EmuFileObject*); + XFILE::CFile* GetFileXbmcByDescriptor(int fd); + XFILE::CFile* GetFileXbmcByStream(FILE* stream); + int GetDescriptorByStream(FILE* stream); +diff -ru xbmc-12.3-Frodo.orig/xbmc/cores/DllLoader/exports/wrapper.c xbmc-12.3-Frodo/xbmc/cores/DllLoader/exports/wrapper.c +--- xbmc-12.3-Frodo.orig/xbmc/cores/DllLoader/exports/wrapper.c 2013-12-12 21:47:49.000000000 +0000 ++++ xbmc-12.3-Frodo/xbmc/cores/DllLoader/exports/wrapper.c 2014-04-15 07:51:55.146945331 +0000 +@@ -39,7 +39,7 @@ + #endif + #include <dlfcn.h> + +-#if defined(TARGET_DARWIN) || defined(__FreeBSD__) || defined(__ANDROID__) ++#if defined(TARGET_DARWIN) || defined(__FreeBSD__) || defined(__ANDROID__) || !defined(GLIBC) + typedef off_t __off_t; + typedef int64_t off64_t; + typedef off64_t __off64_t; |