2015-11-08 06:37:25 +00:00
|
|
|
# Copyright (c) 2011-2015 Ryan Prichard
|
2012-03-23 10:11:34 +00:00
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to
|
|
|
|
# deal in the Software without restriction, including without limitation the
|
|
|
|
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
# sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
# IN THE SOFTWARE.
|
|
|
|
|
2015-11-07 04:08:24 +00:00
|
|
|
# Use make -n to see the actual command-lines make would run.
|
|
|
|
|
|
|
|
default : all
|
|
|
|
|
2012-07-11 18:50:51 +00:00
|
|
|
PREFIX ?= /usr/local
|
2015-11-07 04:08:24 +00:00
|
|
|
UNIX_ADAPTER_EXE ?= console.exe
|
|
|
|
|
|
|
|
# Include config.mk but complain if it hasn't been created yet.
|
|
|
|
ifeq "$(wildcard config.mk)" ""
|
|
|
|
$(error config.mk does not exist. Please run ./configure)
|
|
|
|
endif
|
2016-01-05 09:30:34 +00:00
|
|
|
|
|
|
|
MINGW_OPTIMIZATION_FLAGS ?= -O2
|
|
|
|
|
2015-11-07 04:08:24 +00:00
|
|
|
include config.mk
|
|
|
|
|
2016-01-18 06:16:45 +00:00
|
|
|
VERSION := $(shell cat VERSION.txt | tr -d '\r\n')
|
|
|
|
|
2015-11-08 03:19:03 +00:00
|
|
|
COMMON_CXXFLAGS += \
|
2016-01-18 06:16:45 +00:00
|
|
|
-DWINPTY_VERSION=$(VERSION) \
|
2015-11-08 03:19:03 +00:00
|
|
|
-DWINPTY_VERSION_SUFFIX=$(VERSION_SUFFIX) \
|
|
|
|
-DWINPTY_COMMIT_HASH=$(COMMIT_HASH) \
|
2015-11-07 04:08:24 +00:00
|
|
|
-MMD -Wall \
|
|
|
|
-DUNICODE \
|
|
|
|
-D_UNICODE \
|
Improve named pipe security
* Set the PIPE_REJECT_REMOTE_CLIENTS flag on Vista and up.
* Set a DACL on named pipes that gives full control to the built-in
administrators, the local system account, and the current security
token's owner SID. This is the same DACL that is used by default,
except that the default also grants read access to the Everyone group
and the anonymous account.
* Also define WINVER=0x0501, because MinGW's sddl.h only defines
ConvertSidToStringSidW and ConvertStringSidToSidW if WINVER is defined.
(Ordinarily, defining _WIN32_WINNT is sufficient, and it's even
sufficient with the i686-pc-mingw32-g++ compiler packaged with Cygwin.)
* The createSecurityDescriptorOwnerFullControlEveryoneWrite function is
not currently used (or tested), but I think I'll use it in the debug
server to allow collecting trace output from other accounts on the
machine. (I think I'll make that behavior optional.)
I tested this commit with all of the supported compilers: MSYS1 MinGW,
Cygwin MinGW, MSYS2 MinGW-w64, Cygwin MinGW-w64, MSVC2013, and MSVC2015.
The code compiles and runs in all of them. I also examined the DACL
attached to the control pipe, and its SDDL string looked correct.
2016-01-16 02:14:44 +00:00
|
|
|
-DWINVER=0x0501 \
|
2015-11-08 03:19:03 +00:00
|
|
|
-D_WIN32_WINNT=0x0501
|
|
|
|
|
|
|
|
UNIX_CXXFLAGS += \
|
|
|
|
$(COMMON_CXXFLAGS)
|
|
|
|
|
|
|
|
MINGW_CXXFLAGS += \
|
|
|
|
$(COMMON_CXXFLAGS) \
|
2016-01-05 09:30:34 +00:00
|
|
|
$(MINGW_OPTIMIZATION_FLAGS) \
|
Initial draft of a rewritten libwinpty with a new API.
The new API improves upon the old API in a number of ways:
* The old API provided a single data pipe for input and output, and it
provided the pipe in the form of a HANDLE opened with
FILE_FLAG_OVERLAPPED. Using a bare HANDLE is difficult in higher-level
languages, and overlapped/asynchronous I/O is hard to get right.
winpty_close closed the data pipe, which also didn't help things, though
I think the handle could have been duplicated.
Using a single handle for input and output complicates shutdown. When
the child process exits, the agent scrapes the final output, then closes
the data pipe once its written. It's possible that a winpty client will
first detect the closed pipe when it's writing *input* rather than
reading output, which seems wrong. (On the other hand, the agent
doesn't implement "backpressure" for either input or output (yet), and
if it did, it's possible that post-exit shutdown should interrupt a
blocked write into the console input queue. I need to think about it
more.)
The new API splits the data pipe into CONIN and CONOUT pipes, which are
accessed by filename. After `winpty_open` returns, the client queries
pipe names using `winpty_conin_name` and `winpty_conout_name`, then
opens them using any mechanism, low-level or high-level, blocking or
overlapped.
(There are still many open design issues in this part of the API.)
* The old libwinpty handled errors by killing the process. The new
libwinpty uses C++ exceptions internally and translates exceptions at
API boundaries using:
- a boolean error result (e.g. BOOL, NULL-vs-non-NULL)
- a potentially heap-allocated winpty_error_t object returned via an
optional winpty_error_ptr_t parameter. That parameter can be NULL.
If it isn't, then an error code and message can be queried from the
error object. The winpty_error_t object must be freed with
winpty_error_free.
* winpty_start_process is renamed to winpty_spawn. winpty_open and
winpty_spawn accept a "config" object which holds parameters. New
configuration options can be added without disturbing the source or
binary API. There are various flags I'm planning to add, which are
currently documented but not implemented.
* The winpty_get_exit_code and winpty_get_process_id APIs are removed.
The winpty_spawn function has an out parameter providing the child's
process and thread HANDLEs (duplicated from the agent via
DuplicateHandle). The winpty client can call GetExitCodeProcess and
GetProcessId (as well as the WaitForXXX APIs to wait for child exit).
As of this libwinpty rewrite, all code outside the UNIX adapter uses a
subset of C++11. The code will build with MSVC2013 or newer. The oldest
MinGW G++ I see on my machine is the somewhat broken MinGW (not MinGW-w64)
compiler distributed with Cygwin. That compiler is G++ 4.7.3, which is
new enough.
2016-01-05 03:05:02 +00:00
|
|
|
-std=c++11
|
2012-07-11 18:50:51 +00:00
|
|
|
|
2015-11-07 04:08:24 +00:00
|
|
|
MINGW_LDFLAGS += -static -static-libgcc -static-libstdc++
|
|
|
|
UNIX_LDFLAGS += $(UNIX_LDFLAGS_STATIC)
|
2012-01-22 01:30:41 +00:00
|
|
|
|
2016-01-18 06:10:02 +00:00
|
|
|
define def_unix_target
|
|
|
|
build/$1/%.o : src/%.cc VERSION.txt
|
|
|
|
@echo Compiling $$<
|
|
|
|
@mkdir -p $$$$(dirname $$@)
|
|
|
|
@$$(UNIX_CXX) $$(UNIX_CXXFLAGS) $2 -I src/include -c -o $$@ $$<
|
|
|
|
endef
|
|
|
|
|
|
|
|
define def_mingw_target
|
|
|
|
build/$1/%.o : src/%.cc VERSION.txt
|
|
|
|
@echo Compiling $$<
|
|
|
|
@mkdir -p $$$$(dirname $$@)
|
|
|
|
@$$(MINGW_CXX) $$(MINGW_CXXFLAGS) $2 -I src/include -c -o $$@ $$<
|
|
|
|
endef
|
|
|
|
|
2015-11-29 09:50:06 +00:00
|
|
|
include src/subdir.mk
|
2015-11-07 04:08:24 +00:00
|
|
|
|
|
|
|
all : $(ALL_TARGETS)
|
|
|
|
|
|
|
|
tests : $(TEST_PROGRAMS)
|
2015-08-23 23:02:23 +00:00
|
|
|
|
2012-07-11 18:50:51 +00:00
|
|
|
install : all
|
|
|
|
mkdir -p $(PREFIX)/bin
|
2015-11-07 04:08:24 +00:00
|
|
|
install -m 755 -p -s build/$(UNIX_ADAPTER_EXE) $(PREFIX)/bin
|
2015-10-15 21:47:00 +00:00
|
|
|
install -m 755 -p -s build/winpty.dll $(PREFIX)/bin
|
|
|
|
install -m 755 -p -s build/winpty-agent.exe $(PREFIX)/bin
|
|
|
|
install -m 755 -p -s build/winpty-debugserver.exe $(PREFIX)/bin
|
2012-07-11 18:50:51 +00:00
|
|
|
|
2012-01-22 01:30:41 +00:00
|
|
|
clean :
|
2015-11-07 04:08:24 +00:00
|
|
|
rm -fr build
|
2012-04-17 16:50:19 +00:00
|
|
|
|
2016-01-16 19:27:52 +00:00
|
|
|
clean-msvs :
|
|
|
|
rm -fr src/Default
|
|
|
|
rm -f src/*.vcxproj
|
|
|
|
rm -f src/*.vcxproj.filters
|
|
|
|
rm -f src/*.sln
|
|
|
|
|
2012-04-17 16:50:19 +00:00
|
|
|
distclean : clean
|
2015-11-07 04:08:24 +00:00
|
|
|
rm -f config.mk
|
|
|
|
|
2016-01-16 19:27:52 +00:00
|
|
|
.PHONY : default all tests install clean clean-msvs distclean
|
2015-11-07 04:08:24 +00:00
|
|
|
|
2016-01-16 18:49:05 +00:00
|
|
|
src/%.h :
|
|
|
|
@echo "Missing header file $@ (stale dependency file?)"
|