msvcrt: add support for _chsize_s
morphiend
morphiend at gmail.com
Wed Aug 14 14:08:57 CDT 2013
This patch adds the _chsize_s() to the mscvrt and corresponding mscvr*s.
This was tested on Ubuntu 12.10 using IDA 6.4 as a test application.
Without the implementation of _chsize_s(), certain binaries caused an
internal crash of IDA. This patch fixed that crash.
Also, updated from the original deferred patch to add invalid parameter
invocation.
---
---
dlls/msvcr100/msvcr100.spec | 3 ++-
dlls/msvcr110/msvcr110.spec | 2 +-
dlls/msvcr80/msvcr80.spec | 2 +-
dlls/msvcr90/msvcr90.spec | 2 +-
dlls/msvcrt/file.c | 60
+++++++++++++++++++++++++++++++++++++++++++++
dlls/msvcrt/msvcrt.spec | 1 +
6 files changed, 66 insertions(+), 4 deletions(-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20130814/16af9aa0/attachment.html>
-------------- next part --------------
From 57656ea05b40aeb1a026f43da058191c9e65d656 Mon Sep 17 00:00:00 2001
From: Mike Koss <morphiend at gmail.com>
Date: Wed, 14 Aug 2013 15:03:44 -0400
Subject: Added _chsize_s implementation
---
dlls/msvcr100/msvcr100.spec | 3 ++-
dlls/msvcr110/msvcr110.spec | 2 +-
dlls/msvcr80/msvcr80.spec | 2 +-
dlls/msvcr90/msvcr90.spec | 2 +-
dlls/msvcrt/file.c | 60 +++++++++++++++++++++++++++++++++++++++++++++
dlls/msvcrt/msvcrt.spec | 1 +
6 files changed, 66 insertions(+), 4 deletions(-)
diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec
index 7e602ef..391dcbd 100644
--- a/dlls/msvcr100/msvcr100.spec
+++ b/dlls/msvcr100/msvcr100.spec
@@ -721,7 +721,8 @@
@ cdecl -arch=i386 -norelay _chkesp() msvcrt._chkesp
@ cdecl _chmod(str long) msvcrt._chmod
@ cdecl _chsize(long long) msvcrt._chsize
-@ stub _chsize_s
+@ cdecl _chsize_s(long int64) msvcrt._chsize
+#@ stub _chsize_s
@ cdecl _clearfp() msvcrt._clearfp
@ cdecl _close(long) msvcrt._close
@ cdecl _commit(long) msvcrt._commit
diff --git a/dlls/msvcr110/msvcr110.spec b/dlls/msvcr110/msvcr110.spec
index 6c2da4c..4df3161 100644
--- a/dlls/msvcr110/msvcr110.spec
+++ b/dlls/msvcr110/msvcr110.spec
@@ -1073,7 +1073,7 @@
@ cdecl -arch=i386 -norelay _chkesp() msvcrt._chkesp
@ cdecl _chmod(str long) msvcrt._chmod
@ cdecl _chsize(long long) msvcrt._chsize
-@ stub _chsize_s
+@ cdecl _chsize_s(long int64) msvcrt._chsize_s
@ cdecl _clearfp() msvcrt._clearfp
@ cdecl _close(long) msvcrt._close
@ cdecl _commit(long) msvcrt._commit
diff --git a/dlls/msvcr80/msvcr80.spec b/dlls/msvcr80/msvcr80.spec
index ec886eb..4b07fec 100644
--- a/dlls/msvcr80/msvcr80.spec
+++ b/dlls/msvcr80/msvcr80.spec
@@ -384,7 +384,7 @@
@ cdecl -arch=i386 -norelay _chkesp() msvcrt._chkesp
@ cdecl _chmod(str long) msvcrt._chmod
@ cdecl _chsize(long long) msvcrt._chsize
-@ stub _chsize_s
+@ cdecl _chsize_s(long int64) msvcrt._chsize_s
@ cdecl _clearfp() msvcrt._clearfp
@ cdecl _close(long) msvcrt._close
@ cdecl _commit(long) msvcrt._commit
diff --git a/dlls/msvcr90/msvcr90.spec b/dlls/msvcr90/msvcr90.spec
index d5eebb4..9af3d1d 100644
--- a/dlls/msvcr90/msvcr90.spec
+++ b/dlls/msvcr90/msvcr90.spec
@@ -367,7 +367,7 @@
@ cdecl -arch=i386 -norelay _chkesp() msvcrt._chkesp
@ cdecl _chmod(str long) msvcrt._chmod
@ cdecl _chsize(long long) msvcrt._chsize
-@ stub _chsize_s
+@ cdecl _chsize_s(long int64) msvcrt._chsize_s
@ cdecl _clearfp() msvcrt._clearfp
@ cdecl _close(long) msvcrt._close
@ cdecl _commit(long) msvcrt._commit
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 8403b4b..1e6d6d5 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -1275,6 +1275,66 @@ int CDECL MSVCRT__chsize(int fd, MSVCRT_long size)
}
/*********************************************************************
+ * _chsize_s (MSVCRT.@)
+ */
+int CDECL MSVCRT__chsize_s(int fd, __int64 size)
+{
+ LARGE_INTEGER cur, pos;
+ LARGE_INTEGER temp = { 0 };
+ HANDLE handle;
+ int ret = 0;
+
+ TRACE("(fd=%d, size=%lld)\n", fd, size);
+
+ LOCK_FILES();
+
+ handle = msvcrt_fdtoh(fd);
+ if (!MSVCRT_CHECK_PMT_ERR(handle == INVALID_HANDLE_VALUE, MSVCRT_EBADF) ||
+ !MSVCRT_CHECK_PMT_ERR(size < 0, MSVCRT_EINVAL))
+ {
+ ret = *MSVCRT__errno();
+ }
+ else
+ {
+ /* save the current file pointer */
+ if (!SetFilePointerEx(handle, temp, &cur, FILE_CURRENT))
+ {
+ msvcrt_set_errno(GetLastError());
+ ret = *MSVCRT__errno();
+ }
+ else
+ {
+ /* SetFilePointerEx uses NtSetInformationFile which
+ uses ftruncate() to extend the file size. This will
+ init bytes to 0, and thereby meet the MSDN doc for
+ _chsize_s() */
+ pos.QuadPart = size;
+ if (!SetFilePointerEx(handle, pos, &temp, FILE_BEGIN))
+ {
+ msvcrt_set_errno(GetLastError());
+ ret = *MSVCRT__errno();
+ }
+ else
+ {
+ SetEndOfFile(handle);
+ ret = SetEndOfFile(handle);
+ if (!ret)
+ {
+ msvcrt_set_errno(GetLastError());
+ ret = *MSVCRT__errno();
+ }
+
+ /* restore the file pointer */
+ MSVCRT__lseek(fd, cur.QuadPart, SEEK_SET);
+ }
+ }
+ }
+
+ UNLOCK_FILES();
+ return ret;
+}
+
+/*********************************************************************
* clearerr (MSVCRT.@)
*/
void CDECL MSVCRT_clearerr(MSVCRT_FILE* file)
diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec
index 7511129..f901971 100644
--- a/dlls/msvcrt/msvcrt.spec
+++ b/dlls/msvcrt/msvcrt.spec
@@ -355,6 +355,7 @@
@ cdecl -arch=i386 -norelay _chkesp()
@ cdecl _chmod(str long) MSVCRT__chmod
@ cdecl _chsize(long long) MSVCRT__chsize
+@ cdecl _chsize_s(long int64) MSVCRT__chsize
# stub _chsize_s(long int64)
# stub _chvalidator(long long)
# stub _chvalidator_l(ptr long long)
--
1.8.1.2
More information about the wine-patches
mailing list