windows: Use a fixed worst-case WRITEFILE_MAX_SIZE.

This saves needing to include and isolate the DDK headers.
This commit is contained in:
Martin Ling 2020-01-20 02:01:38 +00:00
parent 8488868187
commit e9d78d82c4
4 changed files with 6 additions and 55 deletions

View File

@ -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

View File

@ -51,7 +51,11 @@
static const GUID name = { l,w1,w2,{ b1,b2,b3,b4,b5,b6,b7,b8 } }
#include <usbioctl.h>
#include <usbiodef.h>
#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 <limits.h>
#include <termios.h>

View File

@ -1,28 +0,0 @@
/*
* This file is part of the libserialport project.
*
* Copyright (C) 2019 Martin Ling <martin-libserialport@earth.li>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/*
* 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 <ddk/wdm.h>
const size_t WRITEFILE_MAX_SIZE = ((65535 - sizeof(MDL)) / sizeof(ULONG_PTR)) * PAGE_SIZE;

View File

@ -1,25 +0,0 @@
/*
* This file is part of the libserialport project.
*
* Copyright (C) 2019 Martin Ling <martin-libserialport@earth.li>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef LIBSERIALPORT_WINDOWS_DDK_H
#define LIBSERIALPORT_WINDOWS_DDK_H
SP_PRIV extern const size_t WRITEFILE_MAX_SIZE;
#endif