microsoft / microsoft/WSL

ioctl `TCGETS2` and friends

Open
#2,595 5 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
C++
Stars
33.7k
Forks
1.8k
Avg merge
3d 17h
Merged PRs (30d)
116

Description

Hi,

using the TCGETS2 ioctl on serial ports yields Inappropriate ioctl for device in Windows Version 10.0.16299.15. Attaching this small demo program here:

#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

#include <asm-generic/termbits.h>
#include <sys/ioctl.h>

int main(int argc, char *argv[])
{
    struct termios2 old;

    int fd = open(argv[1], O_RDWR | O_NOCTTY | O_NDELAY);
    int rc = ioctl(fd, TCGETS2, &old);
    if (rc<0) {
        perror("fail");
        return rc;
    }

    close(fd);
    printf("fine\n");
    
    return 0;
}

Which, when compiling with g++ main.cpp and running with sudo strace ./a.out /dev/ttyS7, produces the following output:

execve("./a.out", ["./a.out", "/dev/ttyS7"], [/* 15 vars */]) = 0
brk(0)                                  = 0xc2d000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fffd6e80000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=62066, ...}) = 0
mmap(NULL, 62066, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fffd6e70000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P \2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1857312, ...}) = 0
mmap(NULL, 3965632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fffd6830000
mprotect(0x7fffd69ee000, 2097152, PROT_NONE) = 0
mmap(0x7fffd6bee000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1be000) = 0x7fffd6bee000
mmap(0x7fffd6bf4000, 17088, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fffd6bf4000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fffd6e60000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fffd6e50000
arch_prctl(ARCH_SET_FS, 0x7fffd6e50740) = 0
mprotect(0x7fffd6bee000, 16384, PROT_READ) = 0
mprotect(0x600000, 4096, PROT_READ)     = 0
mprotect(0x7fffd6e22000, 4096, PROT_READ) = 0
munmap(0x7fffd6e70000, 62066)           = 0
open("/dev/ttyS7", O_RDWR|O_NOCTTY|O_NONBLOCK) = 3
ioctl(3, TCGETS2, 0x7fffdd40e0c0)       = -1 ENOTTY (Inappropriate ioctl for device)
dup(2)                                  = 4
fcntl(4, F_GETFL)                       = 0x1 (flags O_WRONLY)
close(4)                                = 0
write(2, "fail: Inappropriate ioctl for de"..., 37fail: Inappropriate ioctl for device
) = 37
exit_group(-1)                          = ?
+++ exited with 255 +++

Any plans on supporting this ioctl in later builds?

Greetings

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the attached C++ reproducer and verify the TCGETS2 failure on the stated Windows version against a serial device such as /dev/ttyS7. Trace how WSL handles serial-port ioctl requests and determine whether the ioctl can be supported; done means the reproducer succeeds without ENOTTY and existing ioctl behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.