Skip to content

Commit 4b5c842

Browse files
committed
Use internal types, fix breakages
1 parent a07f443 commit 4b5c842

File tree

10 files changed

+93
-41
lines changed

10 files changed

+93
-41
lines changed

libc/hdr/types/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ add_proxy_header_library(
3030
libc.include.llvm-libc-types.struct_flock64
3131
)
3232

33+
add_proxy_header_library(
34+
struct_f_owner_ex
35+
HDRS
36+
struct_f_owner_ex.h
37+
FULL_BUILD_DEPENDS
38+
libc.include.llvm-libc-types.struct_f_owner_ex
39+
)
40+
3341
add_proxy_header_library(
3442
struct_timespec
3543
HDRS

libc/hdr/types/struct_f_owner_ex.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Proxy for struct f_owner_ex --------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_F_OWNER_EX_H
9+
#define LLVM_LIBC_HDR_TYPES_STRUCT_F_OWNER_EX_H
10+
11+
#ifdef LIBC_FULL_BUILD
12+
13+
#include "include/llvm-libc-types/struct_f_owner_ex.h"
14+
15+
#else
16+
17+
#include <fcntl.h>
18+
19+
#endif // LIBC_FULL_BUILD
20+
21+
#endif // LLVM_LIBC_HDR_TYPES_STRUCT_F_OWNER_EX_H

libc/include/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ add_gen_header(
4343
DEPENDS
4444
.llvm-libc-macros.fcntl_macros
4545
.llvm-libc-types.mode_t
46+
.llvm-libc-types.struct_flock
47+
.llvm-libc-types.struct_flock64
48+
.llvm-libc-types.off64
49+
.llvm-libc-types.pid_t
4650
.llvm-libc-types.off_t
4751
.llvm_libc_common_h
4852
)

libc/include/llvm-libc-types/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ add_header(stack_t HDR stack_t.h)
6262
add_header(suseconds_t HDR suseconds_t.h)
6363
add_header(struct_flock HDR struct_flock.h DEPENDS .off_t .pid_t)
6464
add_header(struct_flock64 HDR struct_flock64.h DEPENDS .off64_t .pid_t)
65+
add_header(struct_f_owner_ex HDR struct_f_owner_ex.h DEPENDS .pid_t)
6566
add_header(struct_timeval HDR struct_timeval.h DEPENDS .suseconds_t .time_t)
6667
add_header(struct_rlimit HDR struct_rlimit.h DEPENDS .rlim_t)
6768
add_header(struct_rusage HDR struct_rusage.h DEPENDS .struct_timeval)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===-- Definition of type struct f_owner_ex ------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_TYPES_STRUCT_F_OWNER_EX_H
10+
#define LLVM_LIBC_TYPES_STRUCT_F_OWNER_EX_H
11+
12+
#include "llvm-libc-types/pid_t.h"
13+
14+
enum pid_type {
15+
F_OWNER_TID = 0,
16+
F_OWNER_PID,
17+
F_OWNER_PGRP,
18+
};
19+
20+
struct f_owner_ex {
21+
enum pid_type type;
22+
pid_t pid;
23+
};
24+
25+
#endif // LLVM_LIBC_TYPES_STRUCT_F_OWNER_EX_H

libc/include/llvm-libc-types/struct_flock.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#include "llvm-libc-types/off_t.h"
1313
#include "llvm-libc-types/pid_t.h"
1414

15-
struct flock64 {
16-
int16_t l_type;
17-
int16_t l_whence;
15+
struct flock {
16+
short int l_type;
17+
short int l_whence;
1818
off_t l_start;
1919
off_t l_len;
2020
pid_t l_pid;

libc/include/llvm-libc-types/struct_flock64.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include "llvm-libc-types/pid_t.h"
1414

1515
struct flock64 {
16-
int16_t l_type;
17-
int16_t l_whence;
16+
short int l_type;
17+
short int l_whence;
1818
off64_t l_start;
1919
off64_t l_len;
2020
pid_t l_pid;

libc/src/fcntl/linux/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ add_entrypoint_object(
1818
../fcntl.h
1919
DEPENDS
2020
libc.include.fcntl
21-
libc.include.llvm-libc-types.struct_flock
22-
libc.include.llvm-libc-types.struct_flock64
21+
libc.hdr.types.struct_flock
22+
libc.hdr.types.struct_flock64
23+
libc.hdr.types.struct_f_owner_ex
2324
libc.hdr.fcntl_macros
2425
libc.src.__support.OSUtil.osutil
2526
libc.src.errno.errno

libc/src/fcntl/linux/fcntl.cpp

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "src/fcntl/fcntl.h"
1010

1111
#include "hdr/fcntl_macros.h"
12+
#include "hdr/types/struct_f_owner_ex.h"
1213
#include "hdr/types/struct_flock.h"
1314
#include "hdr/types/struct_flock64.h"
1415
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
@@ -18,20 +19,6 @@
1819
#include <stdarg.h>
1920
#include <sys/syscall.h> // For syscall numbers.
2021

21-
// To avoid conflict with system headers when building
22-
// in overlay mode.
23-
namespace helper {
24-
enum pid_type {
25-
F_OWNER_TID = 0,
26-
F_OWNER_PID,
27-
F_OWNER_PGRP,
28-
};
29-
struct fowner_ex {
30-
enum pid_type type;
31-
pid_t pid;
32-
};
33-
} // namespace helper
34-
3522
// The OFD file locks require special handling for LARGEFILES
3623
namespace LIBC_NAMESPACE {
3724
LLVM_LIBC_FUNCTION(int, fcntl, (int fd, int cmd, ...)) {
@@ -86,22 +73,21 @@ LLVM_LIBC_FUNCTION(int, fcntl, (int fd, int cmd, ...)) {
8673
flk->l_pid = flk64.l_pid;
8774
return retVal;
8875
}
89-
// The general case
90-
default: {
91-
if (cmd == F_GETOWN) {
92-
struct helper::fowner_ex fex;
93-
int retVal = syscall_impl<int>(SYS_fcntl, fd, F_GETOWN_EX, &fex);
94-
if (retVal == -EINVAL)
95-
return syscall_impl<int>(SYS_fcntl, fd, cmd,
96-
reinterpret_cast<void *>(arg));
97-
if (static_cast<uint64_t>(retVal) <= -4096UL)
98-
return fex.type == helper::F_OWNER_PGRP ? -fex.pid : fex.pid;
76+
case F_GETOWN: {
77+
struct f_owner_ex fex;
78+
int retVal = syscall_impl<int>(SYS_fcntl, fd, F_GETOWN_EX, &fex);
79+
if (retVal == -EINVAL)
80+
return syscall_impl<int>(SYS_fcntl, fd, cmd,
81+
reinterpret_cast<void *>(arg));
82+
if (static_cast<unsigned long>(retVal) <= -4096UL)
83+
return fex.type == F_OWNER_PGRP ? -fex.pid : fex.pid;
9984

100-
libc_errno = -retVal;
101-
return -1;
102-
}
103-
return syscall_impl<int>(SYS_fcntl, fd, cmd, reinterpret_cast<void *>(arg));
85+
libc_errno = -retVal;
86+
return -1;
10487
}
88+
// The general case
89+
default:
90+
return syscall_impl<int>(SYS_fcntl, fd, cmd, reinterpret_cast<void *>(arg));
10591
}
10692
}
10793
} // namespace LIBC_NAMESPACE

libc/test/src/fcntl/fcntl_test.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
TEST(LlvmLibcFcntlTest, FcntlDupfd) {
1717
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
18-
constexpr const char *TEST_FILE = "testdata/fcntl.test";
18+
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_dup.test";
19+
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
1920
int fd2, fd3;
2021
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC, S_IRWXU);
2122
ASSERT_ERRNO_SUCCESS();
@@ -36,7 +37,8 @@ TEST(LlvmLibcFcntlTest, FcntlDupfd) {
3637

3738
TEST(LlvmLibcFcntlTest, FcntlGetFl) {
3839
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
39-
constexpr const char *TEST_FILE = "testdata/fcntl.test";
40+
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getfl.test";
41+
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
4042
int retVal;
4143
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC, S_IRWXU);
4244
ASSERT_ERRNO_SUCCESS();
@@ -51,7 +53,8 @@ TEST(LlvmLibcFcntlTest, FcntlGetFl) {
5153

5254
TEST(LlvmLibcFcntlTest, FcntlSetFl) {
5355
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
54-
constexpr const char *TEST_FILE = "testdata/fcntl.test";
56+
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_setfl.test";
57+
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
5558

5659
int retVal;
5760
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
@@ -85,11 +88,13 @@ TEST(LlvmLibcFcntlTest, FcntlSetFl) {
8588

8689
TEST(LlvmLibcFcntlTest, FcntlGetLkRead) {
8790
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
88-
constexpr const char *TEST_FILE = "testdata/fcntl.test";
91+
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getlkread.test";
92+
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
8993

9094
struct flock flk, svflk;
9195
int retVal;
92-
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDONLY);
96+
int fd =
97+
LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDONLY, S_IRWXU);
9398
ASSERT_ERRNO_SUCCESS();
9499
ASSERT_GT(fd, 0);
95100

@@ -115,7 +120,8 @@ TEST(LlvmLibcFcntlTest, FcntlGetLkRead) {
115120

116121
TEST(LlvmLibcFcntlTest, FcntlGetLkWrite) {
117122
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
118-
constexpr const char *TEST_FILE = "testdata/fcntl.test";
123+
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getlkwrite.test";
124+
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
119125

120126
struct flock flk, svflk;
121127
int retVal;

0 commit comments

Comments
 (0)