Skip to content

Commit 9e45d4a

Browse files
author
git apple-llvm automerger
committed
Merge commit '3675e147a1cc' from llvm.org/main into next
2 parents ddd2477 + 3675e14 commit 9e45d4a

File tree

6 files changed

+87
-76
lines changed

6 files changed

+87
-76
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7543,19 +7543,24 @@ INTERCEPTOR(struct __sanitizer_ttyent *, getttynam, char *name) {
75437543
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ttyent, struct_ttyent_sz);
75447544
return ttyent;
75457545
}
7546+
#define INIT_TTYENT \
7547+
COMMON_INTERCEPT_FUNCTION(getttyent); \
7548+
COMMON_INTERCEPT_FUNCTION(getttynam);
7549+
#else
7550+
#define INIT_TTYENT
7551+
#endif
7552+
7553+
#if SANITIZER_INTERCEPT_TTYENTPATH
75467554
INTERCEPTOR(int, setttyentpath, char *path) {
75477555
void *ctx;
75487556
COMMON_INTERCEPTOR_ENTER(ctx, setttyentpath, path);
75497557
if (path)
75507558
COMMON_INTERCEPTOR_READ_RANGE(ctx, path, internal_strlen(path) + 1);
75517559
return REAL(setttyentpath)(path);
75527560
}
7553-
#define INIT_TTYENT \
7554-
COMMON_INTERCEPT_FUNCTION(getttyent); \
7555-
COMMON_INTERCEPT_FUNCTION(getttynam); \
7556-
COMMON_INTERCEPT_FUNCTION(setttyentpath)
7561+
#define INIT_TTYENTPATH COMMON_INTERCEPT_FUNCTION(setttyentpath);
75577562
#else
7558-
#define INIT_TTYENT
7563+
#define INIT_TTYENTPATH
75597564
#endif
75607565

75617566
#if SANITIZER_INTERCEPT_PROTOENT

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,8 @@
521521
#define SANITIZER_INTERCEPT_DEVNAME_R (SI_NETBSD || SI_FREEBSD)
522522
#define SANITIZER_INTERCEPT_FGETLN (SI_NETBSD || SI_FREEBSD)
523523
#define SANITIZER_INTERCEPT_STRMODE (SI_NETBSD || SI_FREEBSD)
524-
#define SANITIZER_INTERCEPT_TTYENT SI_NETBSD
524+
#define SANITIZER_INTERCEPT_TTYENT (SI_NETBSD || SI_FREEBSD)
525+
#define SANITIZER_INTERCEPT_TTYENTPATH SI_NETBSD
525526
#define SANITIZER_INTERCEPT_PROTOENT (SI_LINUX || SI_NETBSD || SI_FREEBSD)
526527
#define SANITIZER_INTERCEPT_PROTOENT_R SI_GLIBC
527528
#define SANITIZER_INTERCEPT_NETENT (SI_LINUX || SI_NETBSD || SI_FREEBSD)

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#include <term.h>
7575
#include <termios.h>
7676
#include <time.h>
77+
#include <ttyent.h>
7778
#include <utime.h>
7879
#include <utmpx.h>
7980
#include <vis.h>
@@ -174,6 +175,8 @@ const int wordexp_wrde_dooffs = WRDE_DOOFFS;
174175

175176
unsigned path_max = PATH_MAX;
176177

178+
int struct_ttyent_sz = sizeof(struct ttyent);
179+
177180
// ioctl arguments
178181
unsigned struct_ifreq_sz = sizeof(struct ifreq);
179182
unsigned struct_termios_sz = sizeof(struct termios);

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ extern const int wordexp_wrde_dooffs;
383383

384384
extern unsigned path_max;
385385

386+
extern int struct_ttyent_sz;
387+
386388
struct __sanitizer_wordexp_t {
387389
uptr we_wordc;
388390
char **we_wordv;
@@ -412,6 +414,16 @@ struct __sanitizer_ifconf {
412414
} ifc_ifcu;
413415
};
414416

417+
struct __sanitizer__ttyent {
418+
char *ty_name;
419+
char *ty_getty;
420+
char *ty_type;
421+
int ty_status;
422+
char *ty_window;
423+
char *ty_comment;
424+
char *ty_group;
425+
};
426+
415427
# define IOC_NRBITS 8
416428
# define IOC_TYPEBITS 8
417429
# if defined(__powerpc__) || defined(__powerpc64__) || defined(__mips__)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// RUN: %clangxx -O0 -g %s -o %t
2+
//
3+
// REQUIRES: freebsd, netbsd
4+
5+
#include <assert.h>
6+
#include <stdlib.h>
7+
#include <ttyent.h>
8+
9+
#include <assert.h>
10+
#include <stdlib.h>
11+
#include <ttyent.h>
12+
13+
void test1() {
14+
struct ttyent *typ = getttyent();
15+
assert(typ && typ->ty_name != nullptr);
16+
assert(typ->ty_type != nullptr);
17+
endttyent();
18+
}
19+
20+
void test2() {
21+
struct ttyent *typ = getttynam("console");
22+
assert(typ && typ->ty_name != nullptr);
23+
assert(typ->ty_type != nullptr);
24+
endttyent();
25+
}
26+
27+
void test3() {
28+
if (!setttyent())
29+
exit(1);
30+
31+
struct ttyent *typ = getttyent();
32+
assert(typ && typ->ty_name != nullptr);
33+
assert(typ->ty_type != nullptr);
34+
endttyent();
35+
}
36+
37+
#if defined(__NetBSD__)
38+
void test4() {
39+
if (!setttyentpath(_PATH_TTYS))
40+
exit(1);
41+
42+
struct ttyent *typ = getttyent();
43+
assert(typ && typ->ty_name != nullptr);
44+
assert(typ->ty_type != nullptr);
45+
assert(typ->ty_class != nullptr);
46+
47+
endttyent();
48+
}
49+
#endif
50+
51+
int main(void) {
52+
test1();
53+
test2();
54+
test3();
55+
#if defined(__NetBSD__)
56+
test4();
57+
#endif
58+
59+
return 0;
60+
}

compiler-rt/test/sanitizer_common/TestCases/NetBSD/ttyent.cpp

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)