Commit Graph

19897 Commits

Author SHA1 Message Date
Corinna Vinschen 2b4c7f90d4 Cygwin: fhandler_mqueue::mq_open: set all required fhandler flags
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 22:43:41 +02:00
Corinna Vinschen fd3fb7a147 Cygwin: disable creating directories below /dev/mqueue
...as on Linux.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 22:05:13 +02:00
Corinna Vinschen 90e5dbfc24 Cygwin: fhandler_mqueue: fix method declarations
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 22:04:43 +02:00
Corinna Vinschen 782b338530 Cygwin: path_conv: fix mqueue path check
The check for a file or dir within /dev/mqueue is accidentally using
the incoming path, which could be a relative path.  Make sure to
restore the absolute POSIX path in path_copy and only then test the
path.

Also, move the actual check for a valid path below /dev/mqueue into
the fhandler_mqueue class.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 22:03:36 +02:00
Corinna Vinschen 4c09dc4f9c Cygwin: cwdstuff: check if /dev exists
/dev has been handled as virtual dir in cwdstuff, thus not allowing
to start native apps from /dev as CWD, even if /dev actually exists
on disk.  Unfortunately this also affects Cygwin executables started
from a debugger.

When chdir'ing to /dev, check if /dev exists on disk.  If so, treat
it as any other existing path.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 21:46:13 +02:00
Corinna Vinschen efef4b8bf1 Cygwin: POSIX msg queues: implement read(2)/lseek(2)
reuse fhandler_virtual implementation to implement read and lseek.
The output from read(2) is modelled after the output when reading
from an mq file on Linux.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 20:19:19 +02:00
Corinna Vinschen 517c7e79da Cygwin: POSIX msg queues: implement ioctl(2)
Call into fhandler_base::ioctl immediately, thus only allowing
FIONBIO to manipulate blocking behaviour.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 20:17:07 +02:00
Corinna Vinschen 46f3b0ce85 Cygwin: POSIX msg queues: move all mq_* functionality into fhandler_mqueue
The POSIX entry points are just wrappers now, calling into
fhandler_mqueue.  While at it, eliminate mqi_flags, replace with
standard fhandler nonblocking flag.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 20:15:16 +02:00
Corinna Vinschen e0cdd462f1 Cygwin: POSIX msg queues: allocate section views top down
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:55:38 +02:00
Corinna Vinschen fbcd61063b Cygwin: POSIX msg queues: Implement dup
Create a private method fhandler_mqueue::_dup and call it from
dup and fixup_after_fork methods.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:50:16 +02:00
Corinna Vinschen b62450cf17 Cygwin: POSIX msg queues: implement open/mq_open entirely in fhandler
The mq_open call is just a framework now.  This patch moves the
entire functionality into fhandler_mqueue.  To support standard
OS calls (as on Linux), make fhandler_mqueue a derived class from
fhandler_disk_file and keep the base handle the handle to the
default stream, to allow implementing O_PATH functionlaity as well
as reading from the file and NOT reading binary message queue data.

Implement a standard fhandler_mqueue::open method, allowing, for
instance, to touch a file under /dev/mqueue and if it doesn't exist,
to create a message queue file.

FIXME: This introduces a BAD HACK into path_conv::check, which needs
reviewing.

Keep the posix path intact in the fhandler, and change get_proc_fd_name
accordingly to return only the basename plus leading slash for
/proc/<PID>/fd.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:49:04 +02:00
Corinna Vinschen a4e074672a Cygwin: POSIX msg queues: slightly rephrase get_mqinfo
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:42:44 +02:00
Corinna Vinschen 2cc914a34e Cygwin: POSIX msg queues: simplify mq_close
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:41:45 +02:00
Corinna Vinschen 15c96f2b26 Cygwin: get_nt_native_path: allow to append suffix
POSIX message queues will be moved into NTFS streams.
Extend get_nt_native_path to provide a filename suffix which is not
subject to special character transposition, to allow specifying
a colon.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:31:26 +02:00
Corinna Vinschen 4ea7c12a20 Cygwin: POSIX msg queues: move definition of struct msg_hdr
...to mqueue_types.h header.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:17:58 +02:00
Corinna Vinschen 49b84cb264 Cygwin: POSIX msg queues: improve error output in fixup_after_fork
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-22 18:03:01 +02:00
Jon Turney a9c8050c36
Cygwin: Ensure PSAPI_VERSION is 1 when building ldd
The default PSAPI_VERSION is controlled by WIN32_WINNT, which we set to
0x0a00 when building ldd, which gets PSAPI_VERSION=2.

This causes K32GetModuleFileNameEx to be used for GetModuleFileNameEx,
which isn't available on Windows Vista.

Define PSAPI_VERSION as 1 for the built executable to work on Windows
Vista.
2021-05-22 16:06:51 +01:00
Corinna Vinschen bce3563e98 Cygwin: POSIX msg queues: destroy msg queue fhandler in case of error
...and don't leave a descriptor dangling

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 15:26:51 +02:00
Corinna Vinschen 723f38b10a Cygwin: POSIX msg queues: move handling of memory map into fhandler
This encapsulated creation, duplication, and closing of all
Windows objects connected to the message queue in the fhandler.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 15:25:37 +02:00
Corinna Vinschen 5b380b1ca6 Cygwin: POSIX ipc: fix evaluation of naming rules
The function evaluating correctness of ipc object names was a
bit half-hearted.  Fix the tests to follow more closely the
desriptions in the Linux man pages.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 15:21:29 +02:00
Corinna Vinschen 5f621bd38f Cygwin: posix_ipc.cc: fix typo
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 15:18:38 +02:00
Corinna Vinschen 65cb82839a Cygwin: POSIX msg queues: create fhandler with object name
build_fh_dev can take the POSIX object name as parameter anyway,
so use that and drop from mqinfo call.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 13:43:51 +02:00
Corinna Vinschen 3342549fcf Cygwin: POSIX msg queues: move IPC object creation into fhandler
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 13:43:51 +02:00
Corinna Vinschen 438764a9de Cygwin: fix formatting in mqueue_types.h
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 13:43:51 +02:00
Corinna Vinschen 6c901b928f Cygwin: POSIX msg queues: use queue name as key
Drop creating a unique ID, the queue name itself is already
unique.  This allows to move ipc object generation into the
fhandler in the next step.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 13:43:51 +02:00
Corinna Vinschen 4fc922b2c8 Cygwin: POSIX msg queues: Convert mqd_t to a descriptor
So far, the mqd_t type returned a pointer to an allocated
area under the hood.  The mutex and event objects attached
to the message queue were implemented as inheritable types.

As unfortunate side effect the HANDLEs to these objects
were inherited by exec'd child processes, even though all
other message queue properties are not inherted, per POSIX.

Fix this by converting an mqd_t to a descriptor, and create a
matching fhandler_mqueue object to handle various aspects of
the message queues inside the fhandler.  Especially, create the
IPC objects as non-inheritable and duplicate the HANDLEs as
part of the fixup_after_fork mechanism.

Drop using mmap and create the memory map with NT functions.
This allows to control duplication of handle and mapping in the
forked child process, without the requirement to regenerate the
map in the same spot.  It also allows to dup() the descriptor,
as on Linux, albeit this isn't implemented yet.

This patch is the first cut.  There's a bit more to do, like
moving more functionality from the POSIX functions into the
fhandler and making sure the mqd_t type can't be used in other
descriptor-related functions willy-nilly.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 13:43:24 +02:00
Christian Franke c0949782b7 Cygwin: utils: chattr: Allow to clear all attributes with '='.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
2021-05-21 12:56:59 +02:00
Corinna Vinschen 6462a0844d Cygwin: utils: ldd: use GetFinalPathNameByHandleW
drop replacement function GetFileNameFromHandle which was
only required pre-Vista.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-20 23:07:05 +02:00
Corinna Vinschen 8c6c9b097d Cygwin: utils: avoid warning when building path_testsuite-path.o
Avoid this warning:

[...]/winsup/utils/mingw/../path.cc:569:1: warning: 'void read_mounts() ' defined but not used [-Wunused-function]
  569 | read_mounts ()
      | ^~~~~~~~~~~

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-20 22:47:44 +02:00
Corinna Vinschen 3053632389 Cygwin: utils: chattr: do not default to CWD
Drop the unexpected behaviour to run chattr in the CWD if no file has
been specified on the command line.  Bail out with usage info instead.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-20 22:39:25 +02:00
Corinna Vinschen f8eecf22db Cygwin: utils: chattr: fix recursive behaviour
chattr [mode] dir

incorrectly recurses one level into the given directory, even if the
--recursive option has not been used.  This patch adds a test to avoid
this bug.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-20 22:32:37 +02:00
Christian Franke cb674a4ad1 Cygwin: utils: chattr: Improve option parsing, fix some messages.
Allow multiple characters also in first '-mode' argument.
Use '-H' instead of '-h' for '--help' to fix ambiguity with
hidden attribute.  Fix help and usage texts and documentation.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2021-05-20 22:29:58 +02:00
Joel Sherrill 0c0f3df224 sys/stat.h: Enable UTIME_NOW and UTIME_OMIT for RTEMS 2021-05-20 10:04:07 +02:00
Corinna Vinschen 9b24fc9505 Cygwin: autoload: fix case in DLL name for sanity
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-20 10:04:07 +02:00
Corinna Vinschen 23d071229d Cygwin: Add missing IsWow64Process2 declaration
The previous patch is accidentally missing the declaration of
IsWow64Process2.  Add it belatedly.

Fixes: 1865a41cb383 ("Cygwin: suppress FAST_CWD warnings on ARM64")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-20 10:04:07 +02:00
Jeremy Drake 338548f82f Cygwin: suppress FAST_CWD warnings on ARM64
The old check was insufficient: new insider preview builds of Windows
allow running x86_64 process on ARM64.  The IsWow64Process2 function
seems to be the intended way to figure this situation out.
2021-05-19 14:40:51 +02:00
Jeremy Drake c8949d0400 Cygwin: Handle virtual drives as non-symlinks
This avoids MAX_PATH-related problems in native tools in case the
virtual drive points to a deep directory

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-19 14:40:51 +02:00
Corinna Vinschen 7b8edba625 Cygwin: POSIX message queues: simplify sync object creation
Introduce new inline function mq_ipc_init to create all three
required sync objects.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-12 11:04:44 +02:00
Jon Turney 079c3a5587
Cygwin: Use parallel make on AppVeyor
We're bumping up against the 1hr free job duration limit on AppVeyor, so
use 'make -j$(nproc)' to allow things to build slightly faster.

Restructure the way build_script: is written in YAML, so it's slightly less
repetitive and easier to add that.

Also skip 'make check' on x86, since it currently just hangs. :(
2021-05-10 16:57:41 +01:00
Jon Turney 71e8b45007
Get rid of relative include paths in strace.cc 2021-05-10 14:41:41 +01:00
Jon Turney b8bd9d1b01
Move source files used in utils/mingw/ into that subdirectory
Move all the source files used in utils/mingw/ into that subdirectory,
so the built objects are in the expected place.

(path.cc requires some more unpicking, and even then there is genuinely
some shared code, so use a trivial file which includes the real path.cc
so the object file is generated where expected)
2021-05-10 14:41:40 +01:00
Jon Turney 9ce70bf450
Unpick cygpath TESTSUITE
Rather than having testsuite.h do various things, depending on defines,
just have it do one thing, and then explicitly redirect to test stubs in
path.cc when building test.
2021-05-10 14:41:39 +01:00
Corinna Vinschen 44eb416323 Cygwin: fetch Windows directory on all platforms and use throughout
Rather than fetching the system Windows directory at dll init time
only on 32 bit, fetch it on all platforms.  Store as WCHAR and
UNICODE_STRING.  Use where appropriate to simplify code.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-07 23:05:24 +02:00
Corinna Vinschen 19d59ce75d Cygwin: path_conv: Rework handling native symlinks as inner path components
commit 456c3a4638 was only going half-way.  It handled symlinks and
junction points as inner path components and made realpath return the
correct path, but it ignored drive letter substitution, i. e., virtual
drives created with, e. g.

  subst X: C:\foo\bar

It was also too simple.  Just returning an error code from
symlink_info::check puts an unnecessary onus on the symlink evaluation
loop in path_conv::check.

Rework the code to use GetFinalPathNameByHandle, and only do this after
checking the current file for being a symlink failed.

If the final path returned by GetFinalPathNameByHandle is not the same
as the incoming path, replace the incoming path with the POSIXified
final path.  This also short-circuits path evaluation, because
path_conv::check doesn't have to recurse over the inner path components
multiple times if all symlinks are of a native type, while still getting
the final path as end result.

Virtual drives are now handled like symlinks.  This is a necessary change
from before to make sure virtual drives are handled identically across
different access methods.  An example is realpath(1) from coreutils.  It
doesn't call readlink(2), but iterates over all path components using
lstat/readlink calls.  Both methods should result in the same real path.

Fixes: 456c3a4638 ("path_conv: Try to handle native symlinks more sanely")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-07 22:52:16 +02:00
Corinna Vinschen 9ea0f37667 Cygwin: revert handwritten tags/ctags target, take 2
Fix accidental checkin of the wrong test version

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-06 13:35:26 +02:00
Corinna Vinschen a5b24cb241 Cygwin: revert handwritten tags/ctags target
Converting to automake dropped the former, handwritten tags/ctags
target.  This leads to a couple of problems:

- For no good reason the tags file gets written to the builddir
  instead of to the srcdir where it's needed.

- `make tags' requires etags to exist, rather than checking if it
  exists and skipping it.

- Adding the extra ctags arguments to AM_CTAGSFLAGS still results
  in a shortened tags file.

(Temporary?) solution: Revert the old tags/ctags rules and silence
the automake warnings.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-06 11:12:46 +02:00
Corinna Vinschen 895f6d2b59 Cygwin: autogen.sh: Allow running from any directory
autogen.sh expects to run from within the winsup dir, so
set CWD accordingly before running autotools.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-06 10:56:20 +02:00
Ola Olsson 84d068971d Nano-malloc: Fix for unwanted external heap fragmentation
The only reason why it is tough for us to use nano malloc
is because of the small shortcoming where nano_malloc()
splits a bigger chunk from the free list into two pieces
while handing back the second one (the tail) to the user.
This is error prone and especially bad for smaller heaps,
where nano malloc is supposed to be superior. The normal
malloc doesn't have this issue and we need to use it even
though it costs us ~2k bytes compared to nano-malloc.

The problem arise especially after giving back _every_
malloced memory to the heap and then starting to exercise
the heap again by allocating something small. This small
item might split the whole heap in two equally big parts
depending on how the heap has been exercised before.

I have uploaded the smallest possible application
(only tested on ST and Nordic devices) to show the issue
while the real customer applications are far more complicated:
https://drive.google.com/file/d/1kfSC2KOm3Os3mI7EBd-U0j63qVs8xMbt/view?usp=sharing

The application works like the following pseudo code,
where we assume a heap of 100 bytes
(I haven't taken padding and other nitty and gritty
details into account. Everything to simplify understanding):

void *ptr = malloc(52); // We get 52 bytes and we have
                        // 48 bytes to use.
free(ptr); // Hand back the 52 bytes to nano_malloc
           // This is the magic line that shows the issue of
           // nano_malloc
ptr = malloc(1); // Nano malloc will split the 52 bytes
                 // in the free list and hand you a pointer
                 // somewhere in the
                 // middle of the heap.
ptr2 = malloc(52); // Out of memory...

I have done a fix which hands back the first part of the
splitted chunk. Once this is fixed we obviously
have the 1 byte placed in position 0 of the heap instead
of somewhere in the middle.

However, this won't let us malloc 52 new bytes even though
we potentially have 99 bytes left to use in the heap. The
reason is that when we try to do the allocation,
nano-malloc looks into the free list and sees a 51 byte
chunk to be used.
This is not big enough so nano-malloc decides to call
sbrk for _another_ 52 bytes which is not possible since
there is only 48 bytes left to ask for.

The solution for this problem is to check if the last
item in the free list is adjacent to sbrk(0). If it is,
as it is in this case, we can just ask sbrk for the
remainder of what is needed. In this case 1 byte.

NB! I have only tested the solution on our ST device.
2021-05-03 13:00:33 +02:00
Jon Turney b05b790689 Cygwin: Ensure toollibdir exists before installing a link there
This helps 'make install -j2' work.
2021-04-30 21:06:33 +02:00
Brian Inglis 6914b40c14 format_proc_swaps: ensure space between fields for clarity
page/swap space name >= 40 or size/used >= 8 leaves no space between fields;
ensure a space after name and add extra tabs after size and used fields;
output appears like Linux 5.8 after changes to mm/swapfile(swap_show);

proc-swaps-space-before.log:
==> /proc/swaps <==
Filename				Type		Size	Used	Priority
/mnt/c/pagefile.sys                     file            11567748292920  0
/mnt/d/pagefile.sys                     file            12582912205960  0

proc-swaps-space-after.log:
==> /proc/swaps <==
Filename				Type		Size		Used		Priority
/mnt/c/pagefile.sys			file		11567748	241024		0
/mnt/d/pagefile.sys			file		12582912	182928		0
2021-04-30 21:05:11 +02:00