diff --git a/mingw-w64-hclient/.gitignore b/mingw-w64-hclient/.gitignore new file mode 100644 index 0000000000..5c6fb78c8c --- /dev/null +++ b/mingw-w64-hclient/.gitignore @@ -0,0 +1 @@ +wds diff --git a/mingw-w64-hclient/01-includes.patch b/mingw-w64-hclient/01-includes.patch new file mode 100644 index 0000000000..18ee7dda8a --- /dev/null +++ b/mingw-w64-hclient/01-includes.patch @@ -0,0 +1,11 @@ +--- a/buffers.h ++++ b/buffers.h +@@ -24,6 +24,8 @@ Revision History: + #ifndef _BUFFERS_H_ + #define _BUFFERS_H_ + ++#include ++ + typedef struct _REPORT_BUFFER + { + _Field_size_(iBufferSize) diff --git a/mingw-w64-hclient/02-intsafe.patch b/mingw-w64-hclient/02-intsafe.patch new file mode 100644 index 0000000000..8266340dd0 --- /dev/null +++ b/mingw-w64-hclient/02-intsafe.patch @@ -0,0 +1,11 @@ +--- a/buffers.c ++++ b/buffers.c +@@ -79,7 +79,7 @@ + return (FALSE); + } + +- if(S_OK != ULongMult(sizeof(REPORT_BUFFER), nBuffers, &reportBuffersSize)) ++ if(__builtin_mul_overflow(sizeof(REPORT_BUFFER), nBuffers, &reportBuffersSize)) + { + free(pNewDisplay); + return (FALSE); diff --git a/mingw-w64-hclient/03-read-thread-proc.patch b/mingw-w64-hclient/03-read-thread-proc.patch new file mode 100644 index 0000000000..4cf0c35ead --- /dev/null +++ b/mingw-w64-hclient/03-read-thread-proc.patch @@ -0,0 +1,45 @@ +--- a/hclient.c ++++ b/hclient.c +@@ -3692,10 +3692,10 @@ DestroyDeviceListCallback( + } + + DWORD WINAPI +-AsynchReadThreadProc( +- PREAD_THREAD_CONTEXT Context +-) ++AsynchReadThreadProc( ++ LPVOID c) + { ++ PREAD_THREAD_CONTEXT Context = c; + HANDLE completionEvent; + BOOL readStatus; + DWORD waitStatus; +@@ -3818,9 +3818,9 @@ AsyncRead_End: + + DWORD WINAPI + SynchReadThreadProc( +- PREAD_THREAD_CONTEXT Context +-) ++ LPVOID c) + { ++ PREAD_THREAD_CONTEXT Context = c; + ULONG numReadsDone = 0; + do + { +--- a/hclient.h ++++ b/hclient.h +@@ -140,12 +140,12 @@ vDisplayValueAttributes( + + DWORD WINAPI + AsynchReadThreadProc( +- PREAD_THREAD_CONTEXT Context ++ LPVOID + ); + + DWORD WINAPI + SynchReadThreadProc( +- PREAD_THREAD_CONTEXT Context ++ LPVOID + ); + + #endif diff --git a/mingw-w64-hclient/04-bad-comparison.patch b/mingw-w64-hclient/04-bad-comparison.patch new file mode 100644 index 0000000000..e62ddfe3cc --- /dev/null +++ b/mingw-w64-hclient/04-bad-comparison.patch @@ -0,0 +1,11 @@ +--- a/hclient.c ++++ b/hclient.c +@@ -3560,7 +3560,7 @@ Routine Description: + // + if(iByteIndex + (UINT)4 > uiBufferSize) + { +- if(sizeof(szString) <= uiStringSize) ++ + { + StringCbPrintf(szString, uiStringSize, "ERR"); + } diff --git a/mingw-w64-hclient/05-other-bad-comparison.patch b/mingw-w64-hclient/05-other-bad-comparison.patch new file mode 100644 index 0000000000..fc64b24e52 --- /dev/null +++ b/mingw-w64-hclient/05-other-bad-comparison.patch @@ -0,0 +1,11 @@ +--- a/strings.c ++++ b/strings.c +@@ -196,7 +196,7 @@ Routine Description: + goto Done; + } + +- if(ByteOffset + DataBuffer > CurrentBufferOffset+ByteOffset) ++ if(ByteOffset + DataBuffer > (PCHAR)CurrentBufferOffset+ByteOffset) + { + goto Done; + } diff --git a/mingw-w64-hclient/06-size-t.patch b/mingw-w64-hclient/06-size-t.patch new file mode 100644 index 0000000000..ce58bce400 --- /dev/null +++ b/mingw-w64-hclient/06-size-t.patch @@ -0,0 +1,11 @@ +--- a/ecdisp.c ++++ b/ecdisp.c +@@ -155,7 +155,7 @@ + #define OUTSTRING(win, str) SendMessage(win, LB_ADDSTRING, 0, (LPARAM) str) + #define OUTWSTRING(win, str) \ + { \ +- SIZE_T nBytes; \ ++ size_t nBytes; \ + \ + errno_t result = wcstombs_s(&nBytes, szTempBuffer, TEMP_BUFFER_SIZE, str, TEMP_BUFFER_SIZE-1); \ + if (0 != result) { \ diff --git a/mingw-w64-hclient/07-dialog-proc.patch b/mingw-w64-hclient/07-dialog-proc.patch new file mode 100644 index 0000000000..7a8fccae75 --- /dev/null +++ b/mingw-w64-hclient/07-dialog-proc.patch @@ -0,0 +1,168 @@ +--- a/ecdisp.c ++++ b/ecdisp.c +@@ -499,7 +499,7 @@ + OUT INT *nReportIDs + ); + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bSetUsagesDlgProc( + HWND hDlg, + UINT message, +@@ -507,7 +507,7 @@ + LPARAM lParam + ); + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bSetValueDlgProc( + HWND hDlg, + UINT message, +@@ -515,7 +515,7 @@ + LPARAM lParam + ); + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bSetInputBuffDlgProc( + HWND hDlg, + UINT message, +@@ -523,7 +523,7 @@ + LPARAM lParam + ); + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bSetDataDlgProc( + HWND hDlg, + UINT message, +@@ -531,7 +531,7 @@ + LPARAM lParam + ); + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bSetBufLenDlgProc( + HWND hDlg, + UINT message, +@@ -539,7 +539,7 @@ + LPARAM lParam + ); + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bSetInputBuffersDlgProc( + HWND hDlg, + UINT message, +@@ -547,7 +547,7 @@ + LPARAM lParam + ); + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bGetIndexedDlgProc( + HWND hDlg, + UINT message, +@@ -555,7 +555,7 @@ + LPARAM lParam + ); + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bGetUsageDiffDlgProc( + HWND hDlg, + UINT message, +@@ -629,7 +629,7 @@ + /* Global function definitions + /*****************************************************************************/ + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bExtCallDlgProc( + HWND hDlg, + UINT message, +@@ -3313,7 +3313,7 @@ + return; + } + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bSetUsagesDlgProc( + HWND hDlg, + UINT message, +@@ -3378,7 +3378,7 @@ + return (FALSE); + } + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bSetValueDlgProc( + HWND hDlg, + UINT message, +@@ -3449,7 +3449,7 @@ + return (FALSE); + } + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bSetInputBuffDlgProc( + HWND hDlg, + UINT message, +@@ -3510,7 +3510,7 @@ + return (FALSE); + } + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bSetDataDlgProc( + HWND hDlg, + UINT message, +@@ -3687,7 +3687,7 @@ + return (FALSE); + } + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bSetBufLenDlgProc( + HWND hDlg, + UINT message, +@@ -3749,7 +3749,7 @@ + return (FALSE); + } + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bSetInputBuffersDlgProc( + HWND hDlg, + UINT message, +@@ -3810,7 +3810,7 @@ + return (FALSE); + } + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bGetIndexedDlgProc( + HWND hDlg, + UINT message, +@@ -3883,7 +3883,7 @@ + return (FALSE); + } + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bGetUsageDiffDlgProc( + HWND hDlg, + UINT message, +diff --git a/hid/hclient/ecdisp.h b/hid/hclient/ecdisp.h +index ea0bd0f..6d13b83 100644 +--- a/ecdisp.h ++++ b/ecdisp.h +@@ -71,7 +71,7 @@ + /* Global Extended Call display function declarations + /*****************************************************************************/ + +-LRESULT CALLBACK ++INT_PTR CALLBACK + bExtCallDlgProc( + HWND hDlg, + UINT message, diff --git a/mingw-w64-hclient/PKGBUILD b/mingw-w64-hclient/PKGBUILD new file mode 100644 index 0000000000..bf310a3969 --- /dev/null +++ b/mingw-w64-hclient/PKGBUILD @@ -0,0 +1,88 @@ +# Maintainer: David Grayson + +_realname=hclient +pkgbase=mingw-w64-${_realname} +pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git" +provides="${MINGW_PACKAGE_PREFIX}-${_realname}" +conflicts="${MINGW_PACKAGE_PREFIX}-${_realname}" +pkgver=37.efd8c0a +pkgrel=1 +pkgdesc='Sample GUI for communicating with HIDs (mingw-w64)' +arch=('any') +url='https://github.com/Microsoft/Windows-driver-samples/tree/master/hid/hclient' +license=('custom') +makedepends=("${MINGW_PACKAGE_PREFIX}-gcc") +depends=() +options=('strip') +source=( + "wds::git+https://github.com/Microsoft/Windows-driver-samples" + '01-includes.patch' + '02-intsafe.patch' + '03-read-thread-proc.patch' + '04-bad-comparison.patch' + '05-other-bad-comparison.patch' + '06-size-t.patch' + '07-dialog-proc.patch' +) + +sha256sums=('SKIP' + 'c5e16ddaa76e5d2dbcf3d8b5083f9a2dfca74f869419c2e5be9b7444b05a72db' + '6c73b234ff46a20cae7de86e6d96f53629624c9b3d005d72030500e95616b826' + '6f2f2ffe160cf71c43fb0224efabf045490ef0202921600f79c45b0bab527e45' + '8c879599a1cf95ed838be8030acb2d74d85989de10a61c7ac1e9243266d1c361' + 'e673215729689b21fd4b6b246e70ed4a8d75fea871dac6b0ec410bf4fc87d60c' + '94b4ebd39a372cf105d45daa1be9c5286dc307a82325273c9925253985c736c8' + 'c2caed5841c2212ec43b7799b0140fcdd5e217b0488f8cfe9318a19841e0eb32') + +pkgver() { + cd "${srcdir}/wds" + printf "%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" +} + +prepare() { + cd "${srcdir}/wds/hid/${_realname}" + + patch -p1 -i "${srcdir}/01-includes.patch" + + # GCC distinguishes between unsigned long and unsigned int. + patch -p1 -i "${srcdir}/02-intsafe.patch" + + # GCC distinguishes between void pointers and other pointers. + patch -p1 -i "${srcdir}/03-read-thread-proc.patch" + + # GCC warns about this because sizeof() for an array parameter + # just returns the size of a pointer. + patch -p1 -i "${srcdir}/04-bad-comparison.patch" + + # Fix a compile warning from comparing two different pointer types without a + # cast. + patch -p1 -i "${srcdir}/05-other-bad-comparison.patch" + + # size_t is different from SIZE_T + patch -p1 -i "${srcdir}/06-size-t.patch" + + # DlgProcs are supposed to return INT_PTR, which is different from LRESULT. + patch -p1 -i "${srcdir}/07-dialog-proc.patch" +} + +build() { + cd "${srcdir}" + rm -rf "build-${MINGW_CHOST}" + mkdir -p "build-${MINGW_CHOST}" + cd "build-${MINGW_CHOST}" + + windres ../wds/hid/hclient/hclient.rc rc.so + + gcc -mwindows --std=c99 ${CFLAGS} ${LDFLAGS} \ + ../wds/hid/hclient/*.c rc.so \ + -lsetupapi -lhid \ + -o hclient.exe +} + +package() { + cd "${srcdir}/wds" + install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE" + cd "${srcdir}/build-${MINGW_CHOST}" + mkdir "${pkgdir}${MINGW_PREFIX}/bin" + install -Dm755 hclient.exe "${pkgdir}${MINGW_PREFIX}/bin" +}