mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-29 03:31:17 -06:00
WIP: Moved sources int src/, separated most of the source code from Perl.
The XS was left only for the unit / integration tests, and it links libslic3r only. No wxWidgets are allowed to be used from Perl starting from now.
This commit is contained in:
parent
3ddaccb641
commit
0558b53493
1706 changed files with 7413 additions and 7638 deletions
4
src/avrdude/windows/.cvsignore
Normal file
4
src/avrdude/windows/.cvsignore
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
.cvsignore
|
||||
.deps
|
||||
Makefile
|
||||
Makefile.in
|
||||
57
src/avrdude/windows/Makefile.am
Normal file
57
src/avrdude/windows/Makefile.am
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#
|
||||
# avrdude - A Downloader/Uploader for AVR device programmers
|
||||
# Copyright (C) 2003 Theodore A. Roth <troth@openavr.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 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 General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
#
|
||||
# This Makefile will only be used on windows based systems.
|
||||
#
|
||||
|
||||
local_install_list = \
|
||||
giveio.sys \
|
||||
install_giveio.bat \
|
||||
remove_giveio.bat \
|
||||
status_giveio.bat
|
||||
|
||||
EXTRA_DIST = \
|
||||
giveio.c \
|
||||
$(local_install_list)
|
||||
|
||||
bin_PROGRAMS = loaddrv
|
||||
|
||||
loaddrv_SOURCES = \
|
||||
loaddrv.c \
|
||||
loaddrv.h
|
||||
|
||||
install-exec-local:
|
||||
$(mkinstalldirs) $(DESTDIR)$(bindir)
|
||||
@list='$(local_install_list)'; for file in $$list; do \
|
||||
echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) \
|
||||
$(srcdir)/$$file $(DESTDIR)$(bindir)/$$file"; \
|
||||
$(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $(srcdir)/$$file \
|
||||
$(DESTDIR)$(bindir)/$$file; \
|
||||
done
|
||||
|
||||
uninstall-local:
|
||||
@for file in $(local_install_list); do \
|
||||
echo " rm -f $(DESTDIR)$(bindir)/$$file"; \
|
||||
rm -f $(DESTDIR)$(bindir)/$$file; \
|
||||
done
|
||||
|
||||
1258
src/avrdude/windows/getopt.c
Normal file
1258
src/avrdude/windows/getopt.c
Normal file
File diff suppressed because it is too large
Load diff
188
src/avrdude/windows/getopt.h
Normal file
188
src/avrdude/windows/getopt.h
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
|
||||
/* getopt.h */
|
||||
/* Declarations for getopt.
|
||||
Copyright (C) 1989-1994, 1996-1999, 2001 Free Software
|
||||
Foundation, Inc. This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library 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 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
The GNU C Library 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 Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General
|
||||
Public License along with the GNU C Library; if not, write
|
||||
to the Free Software Foundation, Inc., 59 Temple Place,
|
||||
Suite 330, Boston, MA 02111-1307 USA. */
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef _GETOPT_H
|
||||
|
||||
#ifndef __need_getopt
|
||||
# define _GETOPT_H 1
|
||||
#endif
|
||||
|
||||
/* If __GNU_LIBRARY__ is not already defined, either we are being used
|
||||
standalone, or this is the first header included in the source file.
|
||||
If we are being used with glibc, we need to include <features.h>, but
|
||||
that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
|
||||
not defined, include <ctype.h>, which will pull in <features.h> for us
|
||||
if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
|
||||
doesn't flood the namespace with stuff the way some other headers do.) */
|
||||
#if !defined __GNU_LIBRARY__
|
||||
# include <ctype.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* For communication from `getopt' to the caller.
|
||||
When `getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when `ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
|
||||
extern char *optarg;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `getopt'.
|
||||
|
||||
On entry to `getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `getopt' returns -1, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
extern int optind;
|
||||
|
||||
/* Callers store zero here to inhibit the error message `getopt' prints
|
||||
for unrecognized options. */
|
||||
|
||||
extern int opterr;
|
||||
|
||||
/* Set to an option character which was unrecognized. */
|
||||
|
||||
extern int optopt;
|
||||
|
||||
#ifndef __need_getopt
|
||||
/* Describe the long-named options requested by the application.
|
||||
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
|
||||
of `struct option' terminated by an element containing a name which is
|
||||
zero.
|
||||
|
||||
The field `has_arg' is:
|
||||
no_argument (or 0) if the option does not take an argument,
|
||||
required_argument (or 1) if the option requires an argument,
|
||||
optional_argument (or 2) if the option takes an optional argument.
|
||||
|
||||
If the field `flag' is not NULL, it points to a variable that is set
|
||||
to the value given in the field `val' when the option is found, but
|
||||
left unchanged if the option is not found.
|
||||
|
||||
To have a long-named option do something other than set an `int' to
|
||||
a compiled-in constant, such as set a value from `optarg', set the
|
||||
option's `flag' field to zero and its `val' field to a nonzero
|
||||
value (the equivalent single-letter option character, if there is
|
||||
one). For long options that have a zero `flag' field, `getopt'
|
||||
returns the contents of the `val' field. */
|
||||
|
||||
struct option
|
||||
{
|
||||
# if (defined __STDC__ && __STDC__) || defined __cplusplus
|
||||
const char *name;
|
||||
# else
|
||||
char *name;
|
||||
# endif
|
||||
/* has_arg can't be an enum because some compilers complain about
|
||||
type mismatches in all the code that assumes it is an int. */
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
|
||||
/* Names for the values of the `has_arg' field of `struct option'. */
|
||||
|
||||
# define no_argument 0
|
||||
# define required_argument 1
|
||||
# define optional_argument 2
|
||||
#endif /* need getopt */
|
||||
|
||||
|
||||
/* Get definitions and prototypes for functions to process the
|
||||
arguments in ARGV (ARGC of them, minus the program name) for
|
||||
options given in OPTS.
|
||||
|
||||
Return the option character from OPTS just read. Return -1 when
|
||||
there are no more options. For unrecognized options, or options
|
||||
missing arguments, `optopt' is set to the option letter, and '?' is
|
||||
returned.
|
||||
|
||||
The OPTS string is a list of characters which are recognized option
|
||||
letters, optionally followed by colons, specifying that that letter
|
||||
takes an argument, to be placed in `optarg'.
|
||||
|
||||
If a letter in OPTS is followed by two colons, its argument is
|
||||
optional. This behavior is specific to the GNU `getopt'.
|
||||
|
||||
The argument `--' causes premature termination of argument
|
||||
scanning, explicitly telling `getopt' that there are no more
|
||||
options.
|
||||
|
||||
If OPTS begins with `--', then non-option arguments are treated as
|
||||
arguments to the option '\0'. This behavior is specific to the GNU
|
||||
`getopt'. */
|
||||
|
||||
#if (defined __STDC__ && __STDC__) || defined __cplusplus
|
||||
# ifdef __GNU_LIBRARY__
|
||||
/* Many other libraries have conflicting prototypes for getopt, with
|
||||
differences in the consts, in stdlib.h. To avoid compilation
|
||||
errors, only prototype getopt for the GNU C library. */
|
||||
extern int getopt (int ___argc, char *const *___argv, const char *__shortopts);
|
||||
# else /* not __GNU_LIBRARY__ */
|
||||
extern int getopt ();
|
||||
# endif /* __GNU_LIBRARY__ */
|
||||
|
||||
# ifndef __need_getopt
|
||||
extern int getopt_long (int ___argc, char *const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind);
|
||||
extern int getopt_long_only (int ___argc, char *const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind);
|
||||
|
||||
/* Internal only. Users should not call this directly. */
|
||||
extern int _getopt_internal (int ___argc, char *const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
int __long_only);
|
||||
# endif
|
||||
#else /* not __STDC__ */
|
||||
extern int getopt ();
|
||||
# ifndef __need_getopt
|
||||
extern int getopt_long ();
|
||||
extern int getopt_long_only ();
|
||||
|
||||
extern int _getopt_internal ();
|
||||
# endif
|
||||
#endif /* __STDC__ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make sure we later can get all the definitions and declarations. */
|
||||
#undef __need_getopt
|
||||
|
||||
#endif /* getopt.h */
|
||||
168
src/avrdude/windows/giveio.c
Normal file
168
src/avrdude/windows/giveio.c
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
/*********************************************************************
|
||||
|
||||
Author: Dale Roberts
|
||||
Date: 8/30/95
|
||||
Program: GIVEIO.SYS
|
||||
Compile: Use DDK BUILD facility
|
||||
|
||||
Purpose: Give direct port I/O access to a user mode process.
|
||||
|
||||
*********************************************************************/
|
||||
#include <ntddk.h>
|
||||
|
||||
/*
|
||||
* The name of our device driver.
|
||||
*/
|
||||
#define DEVICE_NAME_STRING L"giveio"
|
||||
|
||||
/*
|
||||
* This is the "structure" of the IOPM. It is just a simple
|
||||
* character array of length 0x2000.
|
||||
*
|
||||
* This holds 8K * 8 bits -> 64K bits of the IOPM, which maps the
|
||||
* entire 64K I/O space of the x86 processor. Any 0 bits will give
|
||||
* access to the corresponding port for user mode processes. Any 1
|
||||
* bits will disallow I/O access to the corresponding port.
|
||||
*/
|
||||
#define IOPM_SIZE 0x2000
|
||||
typedef UCHAR IOPM[IOPM_SIZE];
|
||||
|
||||
/*
|
||||
* This will hold simply an array of 0's which will be copied
|
||||
* into our actual IOPM in the TSS by Ke386SetIoAccessMap().
|
||||
* The memory is allocated at driver load time.
|
||||
*/
|
||||
IOPM *IOPM_local = 0;
|
||||
|
||||
/*
|
||||
* These are the two undocumented calls that we will use to give
|
||||
* the calling process I/O access.
|
||||
*
|
||||
* Ke386IoSetAccessMap() copies the passed map to the TSS.
|
||||
*
|
||||
* Ke386IoSetAccessProcess() adjusts the IOPM offset pointer so that
|
||||
* the newly copied map is actually used. Otherwise, the IOPM offset
|
||||
* points beyond the end of the TSS segment limit, causing any I/O
|
||||
* access by the user mode process to generate an exception.
|
||||
*/
|
||||
void Ke386SetIoAccessMap(int, IOPM *);
|
||||
void Ke386QueryIoAccessMap(int, IOPM *);
|
||||
void Ke386IoSetAccessProcess(PEPROCESS, int);
|
||||
|
||||
/*********************************************************************
|
||||
Release any allocated objects.
|
||||
*********************************************************************/
|
||||
VOID GiveioUnload(IN PDRIVER_OBJECT DriverObject)
|
||||
{
|
||||
WCHAR DOSNameBuffer[] = L"\\DosDevices\\" DEVICE_NAME_STRING;
|
||||
UNICODE_STRING uniDOSString;
|
||||
|
||||
if(IOPM_local)
|
||||
MmFreeNonCachedMemory(IOPM_local, sizeof(IOPM));
|
||||
|
||||
RtlInitUnicodeString(&uniDOSString, DOSNameBuffer);
|
||||
IoDeleteSymbolicLink (&uniDOSString);
|
||||
IoDeleteDevice(DriverObject->DeviceObject);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
Set the IOPM (I/O permission map) of the calling process so that it
|
||||
is given full I/O access. Our IOPM_local[] array is all zeros, so
|
||||
the IOPM will be all zeros. If OnFlag is 1, the process is given I/O
|
||||
access. If it is 0, access is removed.
|
||||
*********************************************************************/
|
||||
VOID SetIOPermissionMap(int OnFlag)
|
||||
{
|
||||
Ke386IoSetAccessProcess(PsGetCurrentProcess(), OnFlag);
|
||||
Ke386SetIoAccessMap(1, IOPM_local);
|
||||
}
|
||||
|
||||
void GiveIO(void)
|
||||
{
|
||||
SetIOPermissionMap(1);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
Service handler for a CreateFile() user mode call.
|
||||
|
||||
This routine is entered in the driver object function call table by
|
||||
the DriverEntry() routine. When the user mode application calls
|
||||
CreateFile(), this routine gets called while still in the context of
|
||||
the user mode application, but with the CPL (the processor's Current
|
||||
Privelege Level) set to 0. This allows us to do kernel mode
|
||||
operations. GiveIO() is called to give the calling process I/O
|
||||
access. All the user mode application needs do to obtain I/O access
|
||||
is open this device with CreateFile(). No other operations are
|
||||
required.
|
||||
*********************************************************************/
|
||||
NTSTATUS GiveioCreateDispatch(
|
||||
IN PDEVICE_OBJECT DeviceObject,
|
||||
IN PIRP Irp
|
||||
)
|
||||
{
|
||||
GiveIO(); // give the calling process I/O access
|
||||
|
||||
Irp->IoStatus.Information = 0;
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
Driver Entry routine.
|
||||
|
||||
This routine is called only once after the driver is initially
|
||||
loaded into memory. It allocates everything necessary for the
|
||||
driver's operation. In our case, it allocates memory for our IOPM
|
||||
array, and creates a device which user mode applications can open.
|
||||
It also creates a symbolic link to the device driver. This allows
|
||||
a user mode application to access our driver using the \\.\giveio
|
||||
notation.
|
||||
*********************************************************************/
|
||||
NTSTATUS DriverEntry(
|
||||
IN PDRIVER_OBJECT DriverObject,
|
||||
IN PUNICODE_STRING RegistryPath
|
||||
)
|
||||
{
|
||||
PDEVICE_OBJECT deviceObject;
|
||||
NTSTATUS status;
|
||||
WCHAR NameBuffer[] = L"\\Device\\" DEVICE_NAME_STRING;
|
||||
WCHAR DOSNameBuffer[] = L"\\DosDevices\\" DEVICE_NAME_STRING;
|
||||
UNICODE_STRING uniNameString, uniDOSString;
|
||||
|
||||
//
|
||||
// Allocate a buffer for the local IOPM and zero it.
|
||||
//
|
||||
IOPM_local = MmAllocateNonCachedMemory(sizeof(IOPM));
|
||||
if(IOPM_local == 0)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
RtlZeroMemory(IOPM_local, sizeof(IOPM));
|
||||
|
||||
//
|
||||
// Set up device driver name and device object.
|
||||
//
|
||||
RtlInitUnicodeString(&uniNameString, NameBuffer);
|
||||
RtlInitUnicodeString(&uniDOSString, DOSNameBuffer);
|
||||
|
||||
status = IoCreateDevice(DriverObject, 0,
|
||||
&uniNameString,
|
||||
FILE_DEVICE_UNKNOWN,
|
||||
0, FALSE, &deviceObject);
|
||||
|
||||
if(!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
status = IoCreateSymbolicLink (&uniDOSString, &uniNameString);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
//
|
||||
// Initialize the Driver Object with driver's entry points.
|
||||
// All we require are the Create and Unload operations.
|
||||
//
|
||||
DriverObject->MajorFunction[IRP_MJ_CREATE] = GiveioCreateDispatch;
|
||||
DriverObject->DriverUnload = GiveioUnload;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
BIN
src/avrdude/windows/giveio.sys
Normal file
BIN
src/avrdude/windows/giveio.sys
Normal file
Binary file not shown.
34
src/avrdude/windows/install_giveio.bat
Normal file
34
src/avrdude/windows/install_giveio.bat
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
@set DIRVERNAME=giveio
|
||||
@set DIRVERFILE=%DIRVERNAME%.sys
|
||||
|
||||
@echo Copying the driver to the windows directory
|
||||
@echo target file: %WINDIR%\%DIRVERFILE%
|
||||
@copy %DIRVERFILE% %WINDIR%\%DIRVERFILE%
|
||||
|
||||
@echo Remove a running service if needed...
|
||||
@loaddrv stop %DIRVERNAME% >NUL
|
||||
@if errorlevel 2 goto install
|
||||
|
||||
@loaddrv remove %DIRVERNAME% >NUL
|
||||
@if errorlevel 1 goto install
|
||||
|
||||
:install
|
||||
@echo Installing Windows NT/2k/XP driver: %DIRVERNAME%
|
||||
|
||||
@loaddrv install %DIRVERNAME% %WINDIR%\%DIRVERFILE%
|
||||
@if errorlevel 3 goto error
|
||||
|
||||
@loaddrv start %DIRVERNAME%
|
||||
@if errorlevel 1 goto error
|
||||
|
||||
@loaddrv starttype %DIRVERNAME% auto
|
||||
@if errorlevel 1 goto error
|
||||
|
||||
@echo Success
|
||||
@goto exit
|
||||
|
||||
:error
|
||||
@echo ERROR: Installation of %DIRVERNAME% failed
|
||||
|
||||
:exit
|
||||
|
||||
460
src/avrdude/windows/loaddrv.c
Normal file
460
src/avrdude/windows/loaddrv.c
Normal file
|
|
@ -0,0 +1,460 @@
|
|||
// loaddrv.c - Dynamic driver install/start/stop/remove
|
||||
// based on Paula Tomlinson's LOADDRV program.
|
||||
// She describes it in her May 1995 article in Windows/DOS Developer's
|
||||
// Journal (now Windows Developer's Journal).
|
||||
// Modified by Chris Liechti <cliechti@gmx.net>
|
||||
// I removed the old/ugly dialog, it now accepts command line options and
|
||||
// prints error messages with textual description from the OS.
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "loaddrv.h"
|
||||
|
||||
// globals
|
||||
SC_HANDLE hSCMan = NULL;
|
||||
|
||||
//get ext messages for windows error codes:
|
||||
void DisplayErrorText(DWORD dwLastError) {
|
||||
LPSTR MessageBuffer;
|
||||
DWORD dwBufferLength;
|
||||
|
||||
DWORD dwFormatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM;
|
||||
|
||||
dwBufferLength = FormatMessageA(
|
||||
dwFormatFlags,
|
||||
NULL, // module to get message from (NULL == system)
|
||||
dwLastError,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language
|
||||
(LPSTR) &MessageBuffer,
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
if (dwBufferLength) {
|
||||
// Output message
|
||||
puts(MessageBuffer);
|
||||
// Free the buffer allocated by the system.
|
||||
LocalFree(MessageBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
int exists(char *filename) {
|
||||
FILE * pFile;
|
||||
pFile = fopen(filename, "r");
|
||||
return pFile != NULL;
|
||||
}
|
||||
|
||||
void usage(void) {
|
||||
printf("USGAE: loaddrv command drivername [args...]\n\n"
|
||||
"NT/2k/XP Driver and Service modification tool.\n"
|
||||
"(C)2002 Chris Liechti <cliechti@gmx.net>\n\n"
|
||||
"Suported commands:\n\n"
|
||||
" install [fullpathforinstall]\n"
|
||||
" Install new service. Loaded from given path. If path is not present,\n"
|
||||
" the local directory is searched for a .sys file. If the service\n"
|
||||
" already exists, it must be removed first.\n"
|
||||
" start\n"
|
||||
" Start service. It must be installed in advance.\n"
|
||||
" stop\n"
|
||||
" Stop service.\n"
|
||||
" remove\n"
|
||||
" Remove service. It must be stopped in advance.\n"
|
||||
" status\n"
|
||||
" Show status information about service.\n"
|
||||
" starttype auto|manual|system|disable\n"
|
||||
" Change startup type to the given type.\n"
|
||||
);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
DWORD status = 0;
|
||||
int level = 0;
|
||||
if (argc < 3) {
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
LoadDriverInit();
|
||||
if (strcmp(argv[1], "start") == 0) {
|
||||
printf("starting %s... ", argv[2]);
|
||||
status = DriverStart(argv[2]);
|
||||
if ( status != OKAY) {
|
||||
printf("start failed (status %ld):\n", status);
|
||||
level = 1;
|
||||
} else {
|
||||
printf("ok.\n");
|
||||
}
|
||||
} else if (strcmp(argv[1], "stop") == 0) {
|
||||
printf("stoping %s... ", argv[2]);
|
||||
status = DriverStop(argv[2]);
|
||||
if ( status != OKAY) {
|
||||
printf("stop failed (status %ld):\n", status);
|
||||
level = 1;
|
||||
} else {
|
||||
printf("ok.\n");
|
||||
}
|
||||
} else if (strcmp(argv[1], "install") == 0) {
|
||||
char path[MAX_PATH*2];
|
||||
if (argc<4) {
|
||||
char cwd[MAX_PATH];
|
||||
getcwd(cwd, sizeof cwd);
|
||||
sprintf(path, "%s\\%s.sys", cwd, argv[2]);
|
||||
} else {
|
||||
strncpy(path, argv[3], MAX_PATH);
|
||||
}
|
||||
if (exists(path)) {
|
||||
printf("installing %s from %s... ", argv[2], path);
|
||||
status = DriverInstall(path, argv[2]);
|
||||
if ( status != OKAY) {
|
||||
printf("install failed (status %ld):\n", status);
|
||||
level = 2;
|
||||
} else {
|
||||
printf("ok.\n");
|
||||
}
|
||||
} else {
|
||||
printf("install failed, file not found: %s\n", path);
|
||||
level = 1;
|
||||
}
|
||||
} else if (strcmp(argv[1], "remove") == 0) {
|
||||
printf("removing %s... ", argv[2]);
|
||||
status = DriverRemove(argv[2]);
|
||||
if ( status != OKAY) {
|
||||
printf("remove failed (status %ld):\n", status);
|
||||
level = 1;
|
||||
} else {
|
||||
printf("ok.\n");
|
||||
}
|
||||
} else if (strcmp(argv[1], "status") == 0) {
|
||||
printf("status of %s:\n", argv[2]);
|
||||
status = DriverStatus(argv[2]);
|
||||
if ( status != OKAY) {
|
||||
printf("stat failed (status %ld):\n", status);
|
||||
level = 1;
|
||||
} else {
|
||||
printf("ok.\n");
|
||||
}
|
||||
} else if (strcmp(argv[1], "starttype") == 0) {
|
||||
if (argc < 4) {
|
||||
printf("Error: need start type (string) as argument.\n");
|
||||
level = 2;
|
||||
} else {
|
||||
DWORD type = 0;
|
||||
printf("set start type of %s to %s... ", argv[2], argv[3]);
|
||||
if (strcmp(argv[1], "boot") == 0) {
|
||||
type = SERVICE_BOOT_START;
|
||||
} else if (strcmp(argv[3], "system") == 0) {
|
||||
type = SERVICE_SYSTEM_START;
|
||||
} else if (strcmp(argv[3], "auto") == 0) {
|
||||
type = SERVICE_AUTO_START;
|
||||
} else if (strcmp(argv[3], "manual") == 0) {
|
||||
type = SERVICE_DEMAND_START;
|
||||
} else if (strcmp(argv[3], "disabled") == 0) {
|
||||
type = SERVICE_DISABLED;
|
||||
} else {
|
||||
printf("unknown type\n");
|
||||
level = 1;
|
||||
}
|
||||
if (level == 0) {
|
||||
status = DriverStartType(argv[2], type);
|
||||
if ( status != OKAY) {
|
||||
printf("set start type failed (status %ld):\n", status);
|
||||
level = 1;
|
||||
} else {
|
||||
printf("ok.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
usage();
|
||||
level = 1;
|
||||
}
|
||||
if (status) DisplayErrorText(status);
|
||||
LoadDriverCleanup();
|
||||
exit(level);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
DWORD LoadDriverInit(void) {
|
||||
// connect to local service control manager
|
||||
if ((hSCMan = OpenSCManager(NULL, NULL,
|
||||
SC_MANAGER_ALL_ACCESS)) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return OKAY;
|
||||
}
|
||||
|
||||
void LoadDriverCleanup(void) {
|
||||
if (hSCMan != NULL) CloseServiceHandle(hSCMan);
|
||||
}
|
||||
|
||||
/**-----------------------------------------------------**/
|
||||
DWORD DriverInstall(LPSTR lpPath, LPSTR lpDriver) {
|
||||
BOOL dwStatus = OKAY;
|
||||
SC_HANDLE hService = NULL;
|
||||
|
||||
// add to service control manager's database
|
||||
if ((hService = CreateService(hSCMan, lpDriver,
|
||||
lpDriver, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,
|
||||
SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, lpPath,
|
||||
NULL, NULL, NULL, NULL, NULL)) == NULL)
|
||||
dwStatus = GetLastError();
|
||||
else CloseServiceHandle(hService);
|
||||
|
||||
return dwStatus;
|
||||
} // DriverInstall
|
||||
|
||||
/**-----------------------------------------------------**/
|
||||
DWORD DriverStart(LPSTR lpDriver) {
|
||||
BOOL dwStatus = OKAY;
|
||||
SC_HANDLE hService = NULL;
|
||||
|
||||
// get a handle to the service
|
||||
if ((hService = OpenService(hSCMan, lpDriver,
|
||||
SERVICE_ALL_ACCESS)) != NULL)
|
||||
{
|
||||
// start the driver
|
||||
if (!StartService(hService, 0, NULL))
|
||||
dwStatus = GetLastError();
|
||||
} else dwStatus = GetLastError();
|
||||
|
||||
if (hService != NULL) CloseServiceHandle(hService);
|
||||
return dwStatus;
|
||||
} // DriverStart
|
||||
|
||||
/**-----------------------------------------------------**/
|
||||
DWORD DriverStop(LPSTR lpDriver)
|
||||
{
|
||||
BOOL dwStatus = OKAY;
|
||||
SC_HANDLE hService = NULL;
|
||||
SERVICE_STATUS serviceStatus;
|
||||
|
||||
// get a handle to the service
|
||||
if ((hService = OpenService(hSCMan, lpDriver,
|
||||
SERVICE_ALL_ACCESS)) != NULL)
|
||||
{
|
||||
// stop the driver
|
||||
if (!ControlService(hService, SERVICE_CONTROL_STOP,
|
||||
&serviceStatus))
|
||||
dwStatus = GetLastError();
|
||||
} else dwStatus = GetLastError();
|
||||
|
||||
if (hService != NULL) CloseServiceHandle(hService);
|
||||
return dwStatus;
|
||||
} // DriverStop
|
||||
|
||||
/**-----------------------------------------------------**/
|
||||
DWORD DriverRemove(LPSTR lpDriver)
|
||||
{
|
||||
BOOL dwStatus = OKAY;
|
||||
SC_HANDLE hService = NULL;
|
||||
|
||||
// get a handle to the service
|
||||
if ((hService = OpenService(hSCMan, lpDriver,
|
||||
SERVICE_ALL_ACCESS)) != NULL)
|
||||
{ // remove the driver
|
||||
if (!DeleteService(hService))
|
||||
dwStatus = GetLastError();
|
||||
} else dwStatus = GetLastError();
|
||||
|
||||
if (hService != NULL) CloseServiceHandle(hService);
|
||||
return dwStatus;
|
||||
} // DriverRemove
|
||||
|
||||
/**-----------------------------------------------------**/
|
||||
////extensions by Lch
|
||||
/**-----------------------------------------------------**/
|
||||
DWORD DriverStatus(LPSTR lpDriver) {
|
||||
BOOL dwStatus = OKAY;
|
||||
SC_HANDLE hService = NULL;
|
||||
DWORD dwBytesNeeded;
|
||||
|
||||
// get a handle to the service
|
||||
if ((hService = OpenService(hSCMan, lpDriver,
|
||||
SERVICE_ALL_ACCESS)) != NULL)
|
||||
{
|
||||
LPQUERY_SERVICE_CONFIG lpqscBuf;
|
||||
//~ LPSERVICE_DESCRIPTION lpqscBuf2;
|
||||
// Allocate a buffer for the configuration information.
|
||||
if ((lpqscBuf = (LPQUERY_SERVICE_CONFIG) LocalAlloc(
|
||||
LPTR, 4096)) != NULL)
|
||||
{
|
||||
//~ if ((lpqscBuf2 = (LPSERVICE_DESCRIPTION) LocalAlloc(
|
||||
//~ LPTR, 4096)) != NULL)
|
||||
{
|
||||
// Get the configuration information.
|
||||
if (QueryServiceConfig(
|
||||
hService,
|
||||
lpqscBuf,
|
||||
4096,
|
||||
&dwBytesNeeded) //&&
|
||||
//~ QueryServiceConfig2(
|
||||
//~ hService,
|
||||
//~ SERVICE_CONFIG_DESCRIPTION,
|
||||
//~ lpqscBuf2,
|
||||
//~ 4096,
|
||||
//~ &dwBytesNeeded
|
||||
)
|
||||
{
|
||||
// Print the configuration information.
|
||||
printf("Type: [0x%02lx] ", lpqscBuf->dwServiceType);
|
||||
switch (lpqscBuf->dwServiceType) {
|
||||
case SERVICE_WIN32_OWN_PROCESS:
|
||||
printf("The service runs in its own process.");
|
||||
break;
|
||||
case SERVICE_WIN32_SHARE_PROCESS:
|
||||
printf("The service shares a process with other services.");
|
||||
break;
|
||||
case SERVICE_KERNEL_DRIVER:
|
||||
printf("Kernel driver.");
|
||||
break;
|
||||
case SERVICE_FILE_SYSTEM_DRIVER:
|
||||
printf("File system driver.");
|
||||
break;
|
||||
case SERVICE_INTERACTIVE_PROCESS:
|
||||
printf("The service can interact with the desktop.");
|
||||
break;
|
||||
default:
|
||||
printf("Unknown type.");
|
||||
}
|
||||
printf("\nStart Type: [0x%02lx] ", lpqscBuf->dwStartType);
|
||||
switch (lpqscBuf->dwStartType) {
|
||||
case SERVICE_BOOT_START:
|
||||
printf("Boot");
|
||||
break;
|
||||
case SERVICE_SYSTEM_START:
|
||||
printf("System");
|
||||
break;
|
||||
case SERVICE_AUTO_START:
|
||||
printf("Automatic");
|
||||
break;
|
||||
case SERVICE_DEMAND_START:
|
||||
printf("Manual");
|
||||
break;
|
||||
case SERVICE_DISABLED:
|
||||
printf("Disabled");
|
||||
break;
|
||||
default:
|
||||
printf("Unknown.");
|
||||
}
|
||||
printf("\nError Control: [0x%02lx] ", lpqscBuf->dwErrorControl);
|
||||
switch (lpqscBuf->dwErrorControl) {
|
||||
case SERVICE_ERROR_IGNORE:
|
||||
printf("IGNORE: Ignore.");
|
||||
break;
|
||||
case SERVICE_ERROR_NORMAL:
|
||||
printf("NORMAL: Display a message box.");
|
||||
break;
|
||||
case SERVICE_ERROR_SEVERE:
|
||||
printf("SEVERE: Restart with last-known-good config.");
|
||||
break;
|
||||
case SERVICE_ERROR_CRITICAL:
|
||||
printf("CRITICAL: Restart w/ last-known-good config.");
|
||||
break;
|
||||
default:
|
||||
printf("Unknown.");
|
||||
}
|
||||
printf("\nBinary path: %s\n", lpqscBuf->lpBinaryPathName);
|
||||
|
||||
if (lpqscBuf->lpLoadOrderGroup != NULL)
|
||||
printf("Load order grp: %s\n", lpqscBuf->lpLoadOrderGroup);
|
||||
if (lpqscBuf->dwTagId != 0)
|
||||
printf("Tag ID: %ld\n", lpqscBuf->dwTagId);
|
||||
if (lpqscBuf->lpDependencies != NULL)
|
||||
printf("Dependencies: %s\n", lpqscBuf->lpDependencies);
|
||||
if (lpqscBuf->lpServiceStartName != NULL)
|
||||
printf("Start Name: %s\n", lpqscBuf->lpServiceStartName);
|
||||
//~ if (lpqscBuf2->lpDescription != NULL)
|
||||
//~ printf("Description: %s\n", lpqscBuf2->lpDescription);
|
||||
}
|
||||
//~ LocalFree(lpqscBuf2);
|
||||
}
|
||||
LocalFree(lpqscBuf);
|
||||
} else {
|
||||
dwStatus = GetLastError();
|
||||
}
|
||||
} else {
|
||||
dwStatus = GetLastError();
|
||||
}
|
||||
|
||||
if (hService != NULL) CloseServiceHandle(hService);
|
||||
return dwStatus;
|
||||
} // DriverStatus
|
||||
|
||||
/**-----------------------------------------------------**/
|
||||
DWORD DriverStartType(LPSTR lpDriver, DWORD dwStartType) {
|
||||
BOOL dwStatus = OKAY;
|
||||
SC_HANDLE hService = NULL;
|
||||
|
||||
SC_LOCK sclLock;
|
||||
LPQUERY_SERVICE_LOCK_STATUS lpqslsBuf;
|
||||
DWORD dwBytesNeeded;
|
||||
|
||||
// Need to acquire database lock before reconfiguring.
|
||||
sclLock = LockServiceDatabase(hSCMan);
|
||||
|
||||
// If the database cannot be locked, report the details.
|
||||
if (sclLock == NULL) {
|
||||
// Exit if the database is not locked by another process.
|
||||
if (GetLastError() == ERROR_SERVICE_DATABASE_LOCKED) {
|
||||
|
||||
// Allocate a buffer to get details about the lock.
|
||||
lpqslsBuf = (LPQUERY_SERVICE_LOCK_STATUS) LocalAlloc(
|
||||
LPTR, sizeof(QUERY_SERVICE_LOCK_STATUS)+256);
|
||||
if (lpqslsBuf != NULL) {
|
||||
// Get and print the lock status information.
|
||||
if (QueryServiceLockStatus(
|
||||
hSCMan,
|
||||
lpqslsBuf,
|
||||
sizeof(QUERY_SERVICE_LOCK_STATUS)+256,
|
||||
&dwBytesNeeded) )
|
||||
{
|
||||
if (lpqslsBuf->fIsLocked) {
|
||||
printf("Locked by: %s, duration: %ld seconds\n",
|
||||
lpqslsBuf->lpLockOwner,
|
||||
lpqslsBuf->dwLockDuration
|
||||
);
|
||||
} else {
|
||||
printf("No longer locked\n");
|
||||
}
|
||||
}
|
||||
LocalFree(lpqslsBuf);
|
||||
}
|
||||
}
|
||||
dwStatus = GetLastError();
|
||||
} else {
|
||||
// The database is locked, so it is safe to make changes.
|
||||
// Open a handle to the service.
|
||||
hService = OpenService(
|
||||
hSCMan, // SCManager database
|
||||
lpDriver, // name of service
|
||||
SERVICE_CHANGE_CONFIG
|
||||
); // need CHANGE access
|
||||
if (hService != NULL) {
|
||||
// Make the changes.
|
||||
if (!ChangeServiceConfig(
|
||||
hService, // handle of service
|
||||
SERVICE_NO_CHANGE, // service type: no change
|
||||
dwStartType, // change service start type
|
||||
SERVICE_NO_CHANGE, // error control: no change
|
||||
NULL, // binary path: no change
|
||||
NULL, // load order group: no change
|
||||
NULL, // tag ID: no change
|
||||
NULL, // dependencies: no change
|
||||
NULL, // account name: no change
|
||||
NULL, // password: no change
|
||||
NULL) ) // display name: no change
|
||||
{
|
||||
dwStatus = GetLastError();
|
||||
}
|
||||
}
|
||||
// Release the database lock.
|
||||
UnlockServiceDatabase(sclLock);
|
||||
}
|
||||
|
||||
if (hService != NULL) CloseServiceHandle(hService);
|
||||
return dwStatus;
|
||||
} // DriverStartType
|
||||
20
src/avrdude/windows/loaddrv.h
Normal file
20
src/avrdude/windows/loaddrv.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef LOADDRV_H
|
||||
#define LOADDRV_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#define OKAY 0
|
||||
#define UNEXPECTED_ERROR 9999
|
||||
|
||||
//prototypes
|
||||
DWORD LoadDriverInit(void);
|
||||
void LoadDriverCleanup(void);
|
||||
DWORD DriverInstall(LPSTR, LPSTR);
|
||||
DWORD DriverStart(LPSTR);
|
||||
DWORD DriverStop(LPSTR);
|
||||
DWORD DriverRemove(LPSTR);
|
||||
DWORD DriverStatus(LPSTR);
|
||||
DWORD DriverStartType(LPSTR, DWORD);
|
||||
#endif //LOADDRV_H
|
||||
|
||||
|
||||
14
src/avrdude/windows/remove_giveio.bat
Normal file
14
src/avrdude/windows/remove_giveio.bat
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
@set DIRVERNAME=giveio
|
||||
|
||||
@loaddrv stop %DIRVERNAME%
|
||||
@if errorlevel 2 goto error
|
||||
|
||||
@loaddrv remove %DIRVERNAME%
|
||||
@if errorlevel 1 goto error
|
||||
|
||||
@goto exit
|
||||
|
||||
:error
|
||||
@echo ERROR: Deinstallation of %DIRVERNAME% failed
|
||||
|
||||
:exit
|
||||
12
src/avrdude/windows/status_giveio.bat
Normal file
12
src/avrdude/windows/status_giveio.bat
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
@set DIRVERNAME=giveio
|
||||
|
||||
@loaddrv status %DIRVERNAME%
|
||||
@if errorlevel 1 goto error
|
||||
|
||||
@goto exit
|
||||
|
||||
:error
|
||||
@echo ERROR: Status querry for %DIRVERNAME% failed
|
||||
|
||||
:exit
|
||||
|
||||
44
src/avrdude/windows/unistd.cpp
Normal file
44
src/avrdude/windows/unistd.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include "unistd.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
int usleep(unsigned usec)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(usec));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// SO: https://stackoverflow.com/questions/10905892/equivalent-of-gettimeday-for-windows
|
||||
int gettimeofday(struct timeval *tp, struct timezone *tzp)
|
||||
{
|
||||
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
|
||||
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
|
||||
// until 00:00:00 January 1, 1970
|
||||
static const std::uint64_t EPOCH = ((std::uint64_t) 116444736000000000ULL);
|
||||
|
||||
SYSTEMTIME system_time;
|
||||
FILETIME file_time;
|
||||
std::uint64_t time;
|
||||
|
||||
GetSystemTime(&system_time);
|
||||
SystemTimeToFileTime(&system_time, &file_time);
|
||||
time = ((std::uint64_t)file_time.dwLowDateTime);
|
||||
time += ((std::uint64_t)file_time.dwHighDateTime) << 32;
|
||||
|
||||
tp->tv_sec = (long)((time - EPOCH) / 10000000L);
|
||||
tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
85
src/avrdude/windows/unistd.h
Normal file
85
src/avrdude/windows/unistd.h
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
#ifndef SLIC3R_AVRDUDE_UNISTD_H
|
||||
#define SLIC3R_AVRDUDE_UNISTD_H 1
|
||||
|
||||
/* This is intended as a drop-in replacement for unistd.h on Windows.
|
||||
* Please add functionality as neeeded.
|
||||
* https://stackoverflow.com/a/826027/1202830
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <io.h>
|
||||
#include <getopt.h> /* getopt at: https://gist.github.com/ashelly/7776712 */
|
||||
#include <process.h> /* for getpid() and the exec..() family */
|
||||
#include <direct.h> /* for _getcwd() and _chdir() */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h> /* both for stat() */
|
||||
|
||||
#ifndef __cplusplus
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
#define __func__ __FUNCTION__
|
||||
|
||||
#define srandom srand
|
||||
#define random rand
|
||||
|
||||
/* Values for the second argument to access.
|
||||
These may be OR'd together. */
|
||||
#define R_OK 4 /* Test for read permission. */
|
||||
#define W_OK 2 /* Test for write permission. */
|
||||
//#define X_OK 1 /* execute permission - unsupported in windows*/
|
||||
#define F_OK 0 /* Test for existence. */
|
||||
|
||||
#define access _access
|
||||
#define dup2 _dup2
|
||||
#define execve _execve
|
||||
#define ftruncate _chsize
|
||||
#define unlink _unlink
|
||||
#define fileno _fileno
|
||||
#define getcwd _getcwd
|
||||
#define chdir _chdir
|
||||
#define isatty _isatty
|
||||
#define lseek _lseek
|
||||
#define snprintf _snprintf
|
||||
#define strncasecmp _strnicmp
|
||||
#define strcasecmp _stricmp
|
||||
#define stat _stat
|
||||
/* read, write, and close are NOT being #defined here, because while there are file handle specific versions for Windows, they probably don't work for sockets. You need to look at your app and consider whether to call e.g. closesocket(). */
|
||||
|
||||
#ifdef _WIN64
|
||||
#define ssize_t __int64
|
||||
#else
|
||||
#define ssize_t long
|
||||
#endif
|
||||
|
||||
#define STDIN_FILENO 0
|
||||
#define STDOUT_FILENO 1
|
||||
#define STDERR_FILENO 2
|
||||
|
||||
#ifndef __cplusplus
|
||||
/* should be in some equivalent to <sys/types.h> */
|
||||
typedef __int8 int8_t;
|
||||
typedef __int16 int16_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#endif
|
||||
|
||||
|
||||
int usleep(unsigned usec);
|
||||
int gettimeofday(struct timeval *tp, struct timezone *tzp);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* unistd.h */
|
||||
Loading…
Add table
Add a link
Reference in a new issue