Skip to content
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

[libc] Provide sys/queue.h #78081

Merged
merged 6 commits into from
Jan 19, 2024
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
1 change: 1 addition & 0 deletions libc/config/baremetal/arm/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ set(TARGET_PUBLIC_HEADERS
libc.include.stdlib
libc.include.string
libc.include.strings
libc.include.sys_queue
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be nice to add this header to the other targets as well since it should still work, and that will make sure that it's being tested by our upstream builders.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

)
1 change: 1 addition & 0 deletions libc/config/baremetal/riscv/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ set(TARGET_PUBLIC_HEADERS
libc.include.stdlib
libc.include.string
libc.include.strings
libc.include.sys_queue
)
1 change: 1 addition & 0 deletions libc/config/linux/riscv/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.sys_mman
libc.include.sys_prctl
libc.include.sys_random
libc.include.sys_queue
libc.include.sys_resource
libc.include.sys_select
libc.include.sys_socket
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 @@ -30,6 +30,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.sys_ioctl
libc.include.sys_mman
libc.include.sys_prctl
libc.include.sys_queue
libc.include.sys_random
libc.include.sys_resource
libc.include.sys_select
Expand Down
8 changes: 8 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ add_gen_header(
.llvm_libc_common_h
)

add_header(
sys_queue
HDR
sys/queue.h
DEPENDS
.llvm-libc-macros.sys_queue_macros
)

add_gen_header(
sys_random
DEF_FILE sys/random.h.def
Expand Down
28 changes: 27 additions & 1 deletion libc/include/llvm-libc-macros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function(add_macro_header name)
"MACRO_HEADER"
"" # Optional arguments
"HDR" # Single value arguments
"" # Multi-value arguments
"DEPENDS" # Multi-value arguments
${ARGN}
)
if(TARGET libc.include.llvm-libc-macros.${LIBC_TARGET_OS}.${name})
Expand All @@ -14,12 +14,15 @@ function(add_macro_header name)
${MACRO_HEADER_HDR}
DEPENDS
.${LIBC_TARGET_OS}.${name}
${MACRO_HEADER_DEPENDS}
)
else()
add_header(
${name}
HDR
${MACRO_HEADER_HDR}
DEPENDS
${MACRO_HEADER_DEPENDS}
)
endif()
endfunction(add_macro_header)
Expand Down Expand Up @@ -70,6 +73,20 @@ add_macro_header(
math-macros.h
)

add_macro_header(
offsetof_macro
HDR
offsetof-macro.h
)

add_macro_header(
containerof_macro
HDR
containerof-macro.h
DEPENDS
.offsetof_macro
)

add_macro_header(
sched_macros
HDR
Expand Down Expand Up @@ -118,6 +135,15 @@ add_macro_header(
sys-mman-macros.h
)

add_macro_header(
sys_queue_macros
HDR
sys-queue-macros.h
DEPENDS
.null_macro
.containerof_macro
)

add_macro_header(
sys_random_macros
HDR
Expand Down
20 changes: 20 additions & 0 deletions libc/include/llvm-libc-macros/containerof-macro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Definition of the containerof macro -------------------------------===//
//
// 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_MACROS_CONTAINEROF_MACRO_H
#define __LLVM_LIBC_MACROS_CONTAINEROF_MACRO_H

#include <llvm-libc-macros/offsetof-macro.h>

#define __containerof(ptr, type, member) \
({ \
const __typeof(((type *)0)->member) *__ptr = (ptr); \
(type *)(void *)((const char *)__ptr - offsetof(type, member)); \
})

#endif // __LLVM_LIBC_MACROS_CONTAINEROF_MACRO_H
15 changes: 15 additions & 0 deletions libc/include/llvm-libc-macros/offsetof-macro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//===-- Definition of the offsetof macro ----------------------------------===//
//
// 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_MACROS_OFFSETOF_MACRO_H
#define __LLVM_LIBC_MACROS_OFFSETOF_MACRO_H

#define __need_offsetof
#include <stddef.h>

#endif // __LLVM_LIBC_MACROS_OFFSETOF_MACRO_H
Loading