Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sys.statvfs.fstatvfs
libc.src.sys.statvfs.statvfs

# sys/sysinfo.h entrypoints
libc.src.sys.sysinfo.sysinfo

# sys/utsname.h entrypoints
libc.src.sys.utsname.uname

Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.sys_stat
libc.include.sys_statfs
libc.include.sys_statvfs
libc.include.sys_sysinfo
libc.include.sys_syscall
libc.include.sys_sysmacros
libc.include.sys_time
Expand Down
4 changes: 4 additions & 0 deletions libc/config/linux/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ set(TARGET_LIBC_ENTRYPOINTS
# sys/prctl.h entrypoints
libc.src.sys.prctl.prctl

# sys/sysinfo.h entrypoints
# Disabled due to QEMU test failures.
# libc.src.sys.sysinfo.sysinfo

# sys/personality.h entrypoints
libc.src.sys.personality.personality

Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/arm/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.wctype
libc.include.sys_param
libc.include.sys_personality
libc.include.sys_sysinfo
libc.include.sys_unistd
# Disabled due to epoll_wait syscalls not being available on this platform.
# libc.include.sys_epoll
Expand Down
4 changes: 4 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ set(TARGET_LIBC_ENTRYPOINTS
# sys/time.h entrypoints
libc.src.sys.time.utimes

# sys/sysinfo.h entrypoints
# Disabled due to QEMU test failures.
# libc.src.sys.sysinfo.sysinfo

# sys/utsname.h entrypoints
libc.src.sys.utsname.uname

Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.sys_stat
libc.include.sys_statfs
libc.include.sys_statvfs
libc.include.sys_sysinfo
libc.include.sys_syscall
libc.include.sys_time
libc.include.sys_types
Expand Down
3 changes: 3 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ set(TARGET_LIBC_ENTRYPOINTS
# sys/time.h entrypoints
libc.src.sys.time.utimes

# sys/sysinfo.h entrypoints
libc.src.sys.sysinfo.sysinfo

# sys/utsname.h entrypoints
libc.src.sys.utsname.uname

Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.sys_stat
libc.include.sys_statfs
libc.include.sys_statvfs
libc.include.sys_sysinfo
libc.include.sys_syscall
libc.include.sys_sysmacros
libc.include.sys_time
Expand Down
9 changes: 9 additions & 0 deletions libc/hdr/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,15 @@ add_proxy_header_library(
libc.include.netinet_udp
)

add_proxy_header_library(
struct_sysinfo
HDRS
struct_sysinfo.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.struct_sysinfo
libc.include.sys_sysinfo
)

add_proxy_header_library(
struct_utsname
HDRS
Expand Down
27 changes: 27 additions & 0 deletions libc/hdr/types/struct_sysinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Proxy for struct sysinfo.
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_SYSINFO_H
#define LLVM_LIBC_HDR_TYPES_STRUCT_SYSINFO_H

#ifdef LIBC_FULL_BUILD

#include "include/llvm-libc-types/struct_sysinfo.h"

#else // Overlay mode

#include <sys/sysinfo.h>

#endif // LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_TYPES_STRUCT_SYSINFO_H
9 changes: 9 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,15 @@ add_header_macro(
.llvm-libc-types.ushort
)

add_header_macro(
sys_sysinfo
../libc/include/sys/sysinfo.yaml
sys/sysinfo.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.struct_sysinfo
)

add_header_macro(
sys_utsname
../libc/include/sys/utsname.yaml
Expand Down
5 changes: 5 additions & 0 deletions libc/include/llvm-libc-types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ add_header(
)
add_header(struct_tm HDR struct_tm.h)
add_header(struct_passwd HDR struct_passwd.h DEPENDS .uid_t .gid_t)
if(TARGET libc.include.llvm-libc-types.${LIBC_TARGET_OS}.struct_sysinfo)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but jus' saying that we might want to add add_type_header here that would populate the OS-specific dependencies automatically, like add_macro_header does.

(in a separate, PR of course)

add_header(struct_sysinfo HDR struct_sysinfo.h DEPENDS .${LIBC_TARGET_OS}.struct_sysinfo)
else()
add_header(struct_sysinfo HDR struct_sysinfo.h)
endif()
add_header(struct_utsname HDR struct_utsname.h)
add_header(thrd_start_t HDR thrd_start_t.h)
add_header(thrd_t HDR thrd_t.h DEPENDS .__thread_type)
Expand Down
6 changes: 6 additions & 0 deletions libc/include/llvm-libc-types/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ add_header(
HDR
loff_t.h
)

add_header(
struct_sysinfo
HDR
struct_sysinfo.h
)
19 changes: 19 additions & 0 deletions libc/include/llvm-libc-types/linux/struct_sysinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Definition of struct sysinfo for Linux.
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_TYPES_LINUX_STRUCT_SYSINFO_H
#define LLVM_LIBC_TYPES_LINUX_STRUCT_SYSINFO_H

#include <linux/sysinfo.h>

#endif // LLVM_LIBC_TYPES_LINUX_STRUCT_SYSINFO_H
21 changes: 21 additions & 0 deletions libc/include/llvm-libc-types/struct_sysinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Definition of struct sysinfo.
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_TYPES_STRUCT_SYSINFO_H
#define LLVM_LIBC_TYPES_STRUCT_SYSINFO_H

#if defined(__linux__)
#include "linux/struct_sysinfo.h"
#endif

#endif // LLVM_LIBC_TYPES_STRUCT_SYSINFO_H
10 changes: 10 additions & 0 deletions libc/include/sys/sysinfo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
header: sys/sysinfo.h
standards:
- linux
types:
- type_name: struct_sysinfo
functions:
- name: sysinfo
return_type: int
arguments:
- type: struct sysinfo *
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ add_header_library(
HDRS
sysinfo.h
DEPENDS
libc.hdr.types.struct_sysinfo
libc.src.__support.OSUtil.osutil
libc.src.__support.common
libc.src.__support.error_or
Expand Down
6 changes: 3 additions & 3 deletions libc/src/__support/OSUtil/linux/syscall_wrappers/sysinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SYSINFO_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_SYSINFO_H

#include "hdr/types/struct_sysinfo.h"
#include "src/__support/OSUtil/linux/syscall.h" // For syscall_checked
#include "src/__support/common.h"
#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
#include <linux/sysinfo.h> // For struct sysinfo
#include <sys/syscall.h> // For syscall numbers
#include <sys/syscall.h> // For syscall numbers

namespace LIBC_NAMESPACE_DECL {
namespace linux_syscalls {

LIBC_INLINE ErrorOr<int> sysinfo(struct ::sysinfo *info) {
LIBC_INLINE ErrorOr<int> sysinfo(struct sysinfo *info) {
return syscall_checked<int>(SYS_sysinfo, info);
}

Expand Down
1 change: 1 addition & 0 deletions libc/src/sys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ add_subdirectory(ptrace)
add_subdirectory(uio)
add_subdirectory(ioctl)
add_subdirectory(sysmacros)
add_subdirectory(sysinfo)
10 changes: 10 additions & 0 deletions libc/src/sys/sysinfo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
endif()

add_entrypoint_object(
sysinfo
ALIAS
DEPENDS
.${LIBC_TARGET_OS}.sysinfo
)
11 changes: 11 additions & 0 deletions libc/src/sys/sysinfo/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_entrypoint_object(
sysinfo
SRCS
sysinfo.cpp
HDRS
../sysinfo.h
DEPENDS
libc.hdr.types.struct_sysinfo
libc.src.__support.OSUtil.linux.syscall_wrappers.sysinfo
libc.src.errno.errno
)
33 changes: 33 additions & 0 deletions libc/src/sys/sysinfo/linux/sysinfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Linux implementation of sysinfo.
///
//===----------------------------------------------------------------------===//

#include "src/sys/sysinfo/sysinfo.h"

#include "hdr/types/struct_sysinfo.h"
#include "src/__support/OSUtil/linux/syscall_wrappers/sysinfo.h"
#include "src/__support/common.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(int, sysinfo, (struct sysinfo * info)) {
auto result = linux_syscalls::sysinfo(info);
if (!result) {
libc_errno = result.error();
return -1;
}
return 0;
}

} // namespace LIBC_NAMESPACE_DECL
26 changes: 26 additions & 0 deletions libc/src/sys/sysinfo/sysinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Implementation header for sysinfo.
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_SYS_SYSINFO_SYSINFO_H
#define LLVM_LIBC_SRC_SYS_SYSINFO_SYSINFO_H

#include "hdr/types/struct_sysinfo.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

int sysinfo(struct sysinfo *info);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_SYS_SYSINFO_SYSINFO_H
1 change: 1 addition & 0 deletions libc/src/unistd/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ add_entrypoint_object(
libc.hdr.sys_auxv_macros
libc.hdr.sys_resource_macros
libc.hdr.types.struct_rlimit
libc.hdr.types.struct_sysinfo
libc.src.__support.libc_errno
libc.src.__support.macros.config
libc.src.__support.OSUtil.linux.sysinfo
Expand Down
2 changes: 1 addition & 1 deletion libc/src/unistd/linux/sysconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "hdr/sys_auxv_macros.h"
#include "hdr/sys_resource_macros.h"
#include "hdr/types/struct_rlimit.h"
#include "hdr/types/struct_sysinfo.h"
#include "hdr/unistd_macros.h"
#include "src/__support/OSUtil/linux/auxv.h"
#include "src/__support/OSUtil/linux/syscall_wrappers/prlimit.h"
Expand All @@ -26,7 +27,6 @@
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
#include <linux/limits.h>
#include <linux/sysinfo.h>

// In overlay mode, system headers (like glibc's <bits/local_lim.h>) may
// explicitly undefine ARG_MAX to indicate it is dynamic. We define a fallback
Expand Down
1 change: 1 addition & 0 deletions libc/test/src/sys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ add_subdirectory(time)
add_subdirectory(ioctl)
add_subdirectory(sem)
add_subdirectory(sysmacros)
add_subdirectory(sysinfo)
17 changes: 17 additions & 0 deletions libc/test/src/sys/sysinfo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
add_custom_target(libc_sys_sysinfo_unittests)

add_libc_test(
sysinfo_test
SUITE
libc_sys_sysinfo_unittests
SRCS
sysinfo_test.cpp
DEPENDS
libc.hdr.errno_macros
libc.hdr.types.struct_sysinfo
libc.include.sys_sysinfo
libc.src.errno.errno
libc.src.__support.common
libc.src.sys.sysinfo.sysinfo
libc.test.UnitTest.ErrnoSetterMatcher
)
Loading
Loading