Where is the userpace shell for the ioctl system call defined on x86_64 Linux?

I (out of curiosity) wondered where the user space shell for the ioctl system call is defined on x86_64 Linux. My first thought was glibc - after checking the open characters in the installed version on my Fedora 24 block, I see that (if I'm not mistaken) libc provides the ioctl character as "W", which means that it is a weak character with a default implementation. By default, the implementation in the glibc source tree in misc / ioctl.c appears to be a stub, although it simply sets errno to ENOSYS and returns -1.

However, ioctl works (obviously, or my system is not very usable). I know that this is probably assembly code somewhere in a file that is somehow assembled and linked, thereby overriding the weak character open by glibc. I also know that applications can be directly invoked by ioctl using a system call, either through the glibc syscall shell, or directly using the assembly.

However, given the source code of the library that I accidentally observed (libdrm), it includes the standard ioctl / usr / include / sys / ioctl.h header and doesn't seem to contain its own shell implementation, which I can see, I wonder where I must watch.

This is part of my push to better understand the lower levels of the GNU / Linux system. Thanks for any pointers and apologies if this has been asked before, but I don't see any answer if it has.

UPDATE: I neglected the mention above, but I also checked the vdso virtual library displayed by the kernel - I could only find the following in it:

0000000000000a00 W clock_gettime 0000000000000db0 W getcpu 0000000000000c40 W gettimeofday 0000000000000000 A LINUX_2.6 0000000000000d90 W time 0000000000000a00 T __vdso_clock_gettime 0000000000000db0 T __vdso_getcpu 0000000000000c40 T __vdso_gettimeofday 0000000000000d90 T __vdso_time 

UPDATE: it would seem that I was mistaken in the fact that the default definition of glibc is a stub. As pointed out in the comments, the demo shows that it is making a real system call. I wrote an answer to reflect this.

+6
source share
1 answer

As mentioned in a comment on my original question, it is really defined in libc, in my case as follows:

 00000000000f8ce0 <ioctl>: f8ce0: b8 10 00 00 00 mov $0x10,%eax f8ce5: 0f 05 syscall f8ce7: 48 3d 01 f0 ff ff cmp $0xfffffffffffff001,%rax f8ced: 73 01 jae f8cf0 <ioctl+0x10> f8cef: c3 retq f8cf0: 48 8b 0d 71 31 2c 00 mov 0x2c3171(%rip),%rcx # 3bbe68 <_DYNAMIC+0x308> f8cf7: f7 d8 neg %eax f8cf9: 64 89 01 mov %eax,%fs:(%rcx) f8cfc: 48 83 c8 ff or $0xffffffffffffffff,%rax f8d00: c3 retq f8d01: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) f8d08: 00 00 00 f8d0b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 

A system call is explicitly made here - as nos says, it should be auto-generated, so I could not find it directly in the glibc source tree.

0
source

Source: https://habr.com/ru/post/1013353/


All Articles