Skip to content

[libc] implement pathconf/fpathconf #87165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f428a36
intiial attempt
changkhothuychung Mar 30, 2024
480690f
remove fpathconf
changkhothuychung Mar 30, 2024
c585630
add fpathconf
changkhothuychung Mar 30, 2024
b9436a3
fstatvfs
changkhothuychung Mar 30, 2024
a9d69b4
Merge branch 'main' into pathconf-impl
changkhothuychung May 4, 2024
dc6b994
Merge branch 'main' into pathconf-impl
changkhothuychung May 4, 2024
001e9a2
some fix
changkhothuychung May 5, 2024
ff19692
some fix and add test
changkhothuychung May 11, 2024
1b83f13
some fix
changkhothuychung May 13, 2024
4a6c986
refactor
changkhothuychung May 14, 2024
445bef6
some fix
changkhothuychung May 15, 2024
fa71f67
some fix
changkhothuychung May 15, 2024
751e22c
some changes
changkhothuychung May 17, 2024
2d66e87
some fix
changkhothuychung May 22, 2024
94349c2
move utils to linux
changkhothuychung Jun 11, 2024
f57f003
move header to linux
changkhothuychung Jun 14, 2024
65ff5e6
aplly new patch
changkhothuychung Jun 15, 2024
5f96eb8
Merge branch 'main' into pathconf-impl
SchrodingerZhu Jun 16, 2024
6af318b
fix build issue
SchrodingerZhu Jun 16, 2024
e7c690b
Merge pull request #1 from SchrodingerZhu/zyf-patch
changkhothuychung Jun 16, 2024
0ab4d2c
Merge branch 'main' into pathconf-impl
changkhothuychung Jun 16, 2024
04ab180
fix header files
changkhothuychung Jun 18, 2024
ef770b2
fix dependency
changkhothuychung Jun 19, 2024
7a28909
some fixes
changkhothuychung Jun 23, 2024
722bb11
some fix
changkhothuychung Jul 5, 2024
1e092d2
Merge branch 'main' into pathconf-impl
SchrodingerZhu Jul 6, 2024
2f5614b
apply patch
changkhothuychung Jul 7, 2024
3fb2a75
Merge branch 'pathconf-impl' of https://github.com/changkhothuychung/…
changkhothuychung Jul 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.dup3
libc.src.unistd.execve
libc.src.unistd.fchdir
libc.src.unistd.fpathconf
libc.src.unistd.fsync
libc.src.unistd.ftruncate
libc.src.unistd.getcwd
Expand All @@ -295,6 +296,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.link
libc.src.unistd.linkat
libc.src.unistd.lseek
libc.src.unistd.pathconf
libc.src.unistd.pread
libc.src.unistd.pwrite
libc.src.unistd.read
Expand Down
2 changes: 2 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.dup3
libc.src.unistd.execve
libc.src.unistd.fchdir
libc.src.unistd.fpathconf
libc.src.unistd.fsync
libc.src.unistd.ftruncate
libc.src.unistd.getcwd
Expand All @@ -300,6 +301,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.link
libc.src.unistd.linkat
libc.src.unistd.lseek
libc.src.unistd.pathconf
libc.src.unistd.pread
libc.src.unistd.pwrite
libc.src.unistd.read
Expand Down
2 changes: 2 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.dup3
libc.src.unistd.execve
libc.src.unistd.fchdir
libc.src.unistd.fpathconf
libc.src.unistd.fsync
libc.src.unistd.ftruncate
libc.src.unistd.getcwd
Expand All @@ -313,6 +314,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.unistd.link
libc.src.unistd.linkat
libc.src.unistd.lseek
libc.src.unistd.pathconf
libc.src.unistd.pipe
libc.src.unistd.pread
libc.src.unistd.pwrite
Expand Down
27 changes: 27 additions & 0 deletions libc/hdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ add_proxy_header_library(
libc.include.llvm-libc-macros.sys_epoll_macros
)

add_proxy_header_library(
sys_stat_macros
HDRS
sys_stat_macros.h
FULL_BUILD_DEPENDS
libc.include.sys_stat
libc.include.llvm-libc-macros.sys_stat_macros
)

add_proxy_header_library(
unistd_macros
HDRS
unistd_macros.h
FULL_BUILD_DEPENDS
libc.include.unistd
libc.include.llvm-libc-macros.unistd_macros
)

add_proxy_header_library(
time_macros
HDRS
Expand All @@ -97,4 +115,13 @@ add_proxy_header_library(
libc.include.float
)

add_proxy_header_library(
limits_macros
HDRS
limits_macros.h
FULL_BUILD_DEPENDS
libc.include.limits
libc.include.llvm-libc-macros.limits_macros
)

add_subdirectory(types)
22 changes: 22 additions & 0 deletions libc/hdr/limits_macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of macros from limits.h --------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_LIMITS_MACROS_H
#define LLVM_LIBC_HDR_LIMITS_MACROS_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-macros/limits-macros.h"

#else // Overlay mode

#include <limits.h>

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_LIMITS_MACROS_H
22 changes: 22 additions & 0 deletions libc/hdr/sys_stat_macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of macros from sys/stat.h ------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_SYS_STAT_MACROS_H
#define LLVM_LIBC_HDR_SYS_STAT_MACROS_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-macros/sys-stat-macros.h"

#else // Overlay mode

#include <sys/stat.h>

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_SYS_STAT_MACROS_H
22 changes: 22 additions & 0 deletions libc/hdr/unistd_macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===-- Definition of macros from unistd.h --------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_UNISTD_MACROS_H
#define LLVM_LIBC_HDR_UNISTD_MACROS_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-macros/unistd-macros.h"

#else // Overlay mode

#include <unistd.h>

#endif // LLVM_LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_UNISTD_MACROS_H
12 changes: 12 additions & 0 deletions libc/include/llvm-libc-macros/limits-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,16 @@
#define ULLONG_MIN 0ULL
#endif // ULLONG_MIN

#ifndef _POSIX_MAX_CANON
#define _POSIX_MAX_CANON 255
#endif

#ifndef _POSIX_MAX_INPUT
#define _POSIX_MAX_INPUT 255
#endif

#ifndef _POSIX_NAME_MAX
#define _POSIX_PATH_MAX 256
#endif

#endif // LLVM_LIBC_MACROS_LIMITS_MACROS_H
27 changes: 27 additions & 0 deletions libc/include/llvm-libc-macros/linux/unistd-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@
#define _SC_PAGESIZE 1
#define _SC_PAGE_SIZE _SC_PAGESIZE

#define _PC_FILESIZEBITS 0
#define _PC_LINK_MAX 1
#define _PC_MAX_CANON 2
#define _PC_MAX_INPUT 3
#define _PC_NAME_MAX 4
#define _PC_PATH_MAX 5
#define _PC_PIPE_BUF 6
#define _PC_2_SYMLINKS 7
#define _PC_ALLOC_SIZE_MIN 8
#define _PC_REC_INCR_XFER_SIZE 9
#define _PC_REC_MAX_XFER_SIZE 10
#define _PC_REC_MIN_XFER_SIZE 11
#define _PC_REC_XFER_ALIGN 12
#define _PC_SYMLINK_MAX 13
#define _PC_CHOWN_RESTRICTED 14
#define _PC_NO_TRUNC 15
#define _PC_VDISABLE 16
#define _PC_ASYNC_IO 17
#define _PC_PRIO_IO 18
#define _PC_SYNC_IO 19

// TODO: Move these limit macros to a separate file
#define _POSIX_CHOWN_RESTRICTED 1
#define _POSIX_PIPE_BUF 512
#define _POSIX_NO_TRUNC 1
#define _POSIX_VDISABLE '\0'

// Macro to set up the call to the __llvm_libc_syscall function
// This is to prevent the call from having fewer than 6 arguments, since six
// arguments are always passed to the syscall. Unnecessary arguments are
Expand Down
1 change: 1 addition & 0 deletions libc/src/sys/statvfs/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_header_library(
libc.src.__support.common
libc.src.__support.CPP.optional
libc.include.sys_syscall
libc.include.llvm-libc-types.struct_statvfs
)

add_entrypoint_object(
Expand Down
15 changes: 15 additions & 0 deletions libc/src/unistd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ add_entrypoint_object(
.${LIBC_TARGET_OS}.fork
)

add_entrypoint_object(
fpathconf
ALIAS
DEPENDS
.${LIBC_TARGET_OS}.fpathconf
)

add_entrypoint_object(
execv
ALIAS
Expand Down Expand Up @@ -160,6 +167,14 @@ add_entrypoint_object(
.${LIBC_TARGET_OS}.lseek
)

add_entrypoint_object(
pathconf
ALIAS
DEPENDS
.${LIBC_TARGET_OS}.pathconf
)


add_entrypoint_object(
pipe
ALIAS
Expand Down
18 changes: 18 additions & 0 deletions libc/src/unistd/fpathconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation header for fpathconf ---------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_UNISTD_FPATHCONF_H
#define LLVM_LIBC_SRC_UNISTD_FPATHCONF_H

namespace LIBC_NAMESPACE {

long fpathconf(int fd, int name);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_UNISTD_FSYNC_H
42 changes: 42 additions & 0 deletions libc/src/unistd/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ add_entrypoint_object(
libc.src.errno.errno
)

add_entrypoint_object(
fpathconf
SRCS
fpathconf.cpp
HDRS
../fpathconf.h
DEPENDS
libc.include.unistd
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
libc.src.errno.errno
libc.src.unistd.linux.pathconf_utils
)

add_entrypoint_object(
execv
SRCS
Expand Down Expand Up @@ -273,6 +287,34 @@ add_entrypoint_object(
libc.src.errno.errno
)

add_entrypoint_object(
pathconf
SRCS
pathconf.cpp
HDRS
../pathconf.h
DEPENDS
libc.include.unistd
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
libc.src.errno.errno
libc.src.unistd.linux.pathconf_utils
)

add_object_library(
pathconf_utils
SRCS
pathconf_utils.cpp
HDRS
pathconf_utils.h
DEPENDS
libc.hdr.limits_macros
libc.hdr.unistd_macros
libc.src.__support.OSUtil.osutil
libc.src.errno.errno
libc.src.sys.statvfs.linux.statfs_utils
)

add_entrypoint_object(
pipe
SRCS
Expand Down
24 changes: 24 additions & 0 deletions libc/src/unistd/linux/fpathconf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===-- Linux implementation of fpathconf ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/unistd/fpathconf.h"
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
#include "src/sys/statvfs/linux/statfs_utils.h"
#include "src/unistd/linux/pathconf_utils.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(long, fpathconf, (int fd, int name)) {
if (cpp::optional<statfs_utils::LinuxStatFs> result =
statfs_utils::linux_fstatfs(fd))
return pathconfig(result.value(), name);
return -1;
}

} // namespace LIBC_NAMESPACE
23 changes: 23 additions & 0 deletions libc/src/unistd/linux/pathconf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Linux implementation of pathconf ----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/unistd/pathconf.h"
#include "src/errno/libc_errno.h"
#include "src/sys/statvfs/linux/statfs_utils.h"
#include "src/unistd/linux/pathconf_utils.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(long, pathconf, (const char *path, int name)) {
if (cpp::optional<statfs_utils::LinuxStatFs> result =
statfs_utils::linux_statfs(path))
return pathconfig(result.value(), name);
return -1;
}

} // namespace LIBC_NAMESPACE
Loading