This is an archive of the discontinued LLVM Phabricator instance.

[Msan] Add ptsname, ptsname_r interceptors
ClosedPublic

Authored by vitalybuka on Sep 30 2020, 3:03 AM.

Diff Detail

Event Timeline

vitalybuka created this revision.Sep 30 2020, 3:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 30 2020, 3:03 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
vitalybuka requested review of this revision.Sep 30 2020, 3:03 AM
MaskRay added inline comments.
compiler-rt/test/sanitizer_common/TestCases/Linux/ptsname.c
5

600 in glibc

12

Consider supporting the case that posix_openpt return -1 (the effective user cannot create a pseudo terminal)

13

The coding standard prefers char *

vitalybuka updated this revision to Diff 295385.EditedSep 30 2020, 1:06 PM
vitalybuka marked 2 inline comments as done.

addressed @MaskRay comments

vitalybuka added inline comments.Sep 30 2020, 1:07 PM
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
4876

@eugenis implementation uses static buffer which can result in data race if called from multiple threads
I made this consistent with ttyname, but I am no sure if we maybe want to apply tsan to this buffer.
In this patch I'll keep COMMON_INTERCEPTOR_INITIALIZE_RANGE, but maybe we want to switch this behavior later?

4885

BTW on some platforms including glibc ptsname is implemented with ptsname_r

compiler-rt/test/sanitizer_common/TestCases/Linux/ptsname.c
5

switched to getpt

eugenis accepted this revision.Sep 30 2020, 1:23 PM

LGTM

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
4876

This is exactly what INITIALIZE_RANGE is for - it's a write from MSan PoV, but not for TSan.

4885

Does it break anything? I hope it does not use ptsname_r to initialize the common static buffer - that would be a data race.

This revision is now accepted and ready to land.Sep 30 2020, 1:23 PM
MaskRay accepted this revision.Sep 30 2020, 1:28 PM

(glibc uses __ptsname_internal to implement ptsname, so technically for the lldb issue ptsname_r does not need to be intercepted)

I still slightly prefer posix_openpt because it works on FreeBSD automatically. FreeBSD does not have openpt

vitalybuka added inline comments.Sep 30 2020, 1:47 PM
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
4885

Nevermind, both use "__ptsname_r", not ptsname_r, so ptsname is not going to call ptsname_r inteceptor

switch to posix_openpt

(glibc uses __ptsname_internal to implement ptsname, so technically for the lldb issue ptsname_r does not need to be intercepted)

I still slightly prefer posix_openpt because it works on FreeBSD automatically. FreeBSD does not have openpt

done

MaskRay added inline comments.Sep 30 2020, 2:12 PM
compiler-rt/test/sanitizer_common/TestCases/Linux/ptsname.c
20

If you want to be nicer to FreeBSD... it does not have ptsname_r

I'll not push this argument too hard because this directory is Linux :)

This revision was landed with ongoing or failed builds.Sep 30 2020, 3:01 PM
This revision was automatically updated to reflect the committed changes.