From: Martin Ling Date: Mon, 20 Jan 2020 02:01:38 +0000 (+0000) Subject: windows: Use a fixed worst-case WRITEFILE_MAX_SIZE. X-Git-Url: https://sigrok.org/gitweb/?p=libserialport.git;a=commitdiff_plain;h=e9d78d82c4a2bc10863af5511baeae9a954f50db windows: Use a fixed worst-case WRITEFILE_MAX_SIZE. This saves needing to include and isolate the DDK headers. --- diff --git a/Makefile.am b/Makefile.am index 10493de..bbc4b3b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,7 +32,7 @@ if LINUX libserialport_la_SOURCES += linux.c linux_termios.c linux_termios.h endif if WIN32 -libserialport_la_SOURCES += windows.c windows_ddk.c windows_ddk.h +libserialport_la_SOURCES += windows.c endif if MACOSX libserialport_la_SOURCES += macosx.c diff --git a/libserialport_internal.h b/libserialport_internal.h index fde4883..49f36d7 100644 --- a/libserialport_internal.h +++ b/libserialport_internal.h @@ -51,7 +51,11 @@ static const GUID name = { l,w1,w2,{ b1,b2,b3,b4,b5,b6,b7,b8 } } #include #include -#include "windows_ddk.h" +/* The largest size that can be passed to WriteFile() safely + * on any architecture. This arises from the expression: + * PAGE_SIZE * (65535 - sizeof(MDL)) / sizeof(ULONG_PTR) + * and this worst-case value is found on x64. */ +#define WRITEFILE_MAX_SIZE 33525760 #else #include #include diff --git a/windows_ddk.c b/windows_ddk.c deleted file mode 100644 index 34f6a56..0000000 --- a/windows_ddk.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This file is part of the libserialport project. - * - * Copyright (C) 2019 Martin Ling - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -/* - * We can't include DDK headers in serialport.c because they conflict with - * user space headers. So this file exists to isolate the definitions which - * use the kernel declarations. - */ - -#include - -const size_t WRITEFILE_MAX_SIZE = ((65535 - sizeof(MDL)) / sizeof(ULONG_PTR)) * PAGE_SIZE; diff --git a/windows_ddk.h b/windows_ddk.h deleted file mode 100644 index 8e3e599..0000000 --- a/windows_ddk.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is part of the libserialport project. - * - * Copyright (C) 2019 Martin Ling - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef LIBSERIALPORT_WINDOWS_DDK_H -#define LIBSERIALPORT_WINDOWS_DDK_H - -SP_PRIV extern const size_t WRITEFILE_MAX_SIZE; - -#endif