Skip to content

[libc] Add functions to send/recv messages #106467

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 8 commits into from
Sep 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
4 changes: 4 additions & 0 deletions libc/config/linux/api.td
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ def SysSocketAPI : PublicAPI<"sys/socket.h"> {
"socklen_t",
"struct sockaddr",
"struct sockaddr_un",
"struct msghdr",
"struct iovec",
"size_t",
"ssize_t",
];
}

Expand Down
8 changes: 7 additions & 1 deletion libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,14 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.sys.select.select

# sys/socket.h entrypoints
libc.src.sys.socket.bind
libc.src.sys.socket.socket
libc.src.sys.socket.socketpair
libc.src.sys.socket.send
libc.src.sys.socket.sendto
libc.src.sys.socket.sendmsg
libc.src.sys.socket.recv
libc.src.sys.socket.recvfrom
libc.src.sys.socket.recvmsg
)
endif()

Expand Down
27 changes: 27 additions & 0 deletions libc/hdr/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,30 @@ add_proxy_header_library(
libc.include.setjmp
)


add_proxy_header_library(
struct_msghdr
HDRS
struct_msghdr.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.struct_msghdr
libc.include.sys_socket
)

add_proxy_header_library(
struct_sockaddr
HDRS
struct_sockaddr.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.struct_sockaddr
libc.include.sys_socket
)

add_proxy_header_library(
socklen_t
HDRS
socklen_t.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.socklen_t
libc.include.sys_socket
)
21 changes: 21 additions & 0 deletions libc/hdr/types/socklen_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Proxy for socklen_t -----------------------------------------------===//
//
// 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_TYPES_SOCKLEN_T_H
#define LLVM_LIBC_HDR_TYPES_SOCKLEN_T_H

#ifdef LIBC_FULL_BUILD

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

#else

#include <signal.h>

#endif // LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_TYPES_SOCKLEN_T_H
23 changes: 23 additions & 0 deletions libc/hdr/types/ssize_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===-- Proxy for ssize_t -------------------------------------------------===//
//
// 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_TYPES_SSIZE_T_H
#define LLVM_LIBC_HDR_TYPES_SSIZE_T_H

#ifdef LIBC_FULL_BUILD

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

#else

#define __need_ssize_t
#include <stddef.h>
#undef __need_ssize_t

#endif // LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_TYPES_SSIZE_T_H
21 changes: 21 additions & 0 deletions libc/hdr/types/struct_msghdr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Proxy for struct msghdr ------------------------------------------===//
//
// 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_TYPES_STRUCT_MSGHDR_H
#define LLVM_LIBC_HDR_TYPES_STRUCT_MSGHDR_H

#ifdef LIBC_FULL_BUILD

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

#else

#include <sys/socket.h>

#endif // LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_TYPES_STRUCT_MSGHDR_H
21 changes: 21 additions & 0 deletions libc/hdr/types/struct_sockaddr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Proxy for struct sockaddr ----------------------------------------===//
//
// 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_TYPES_STRUCT_SOCKADDR_H
#define LLVM_LIBC_HDR_TYPES_STRUCT_SOCKADDR_H

#ifdef LIBC_FULL_BUILD

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

#else

#include <sys/socket.h>

#endif // LIBC_FULL_BUILD

#endif // LLVM_LIBC_HDR_TYPES_STRUCT_SOCKADDR_H
2 changes: 2 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,8 @@ add_header_macro(
.llvm-libc-macros.sys_socket_macros
.llvm-libc-types.sa_family_t
.llvm-libc-types.socklen_t
.llvm-libc-types.struct_iovec
.llvm-libc-types.struct_msghdr
.llvm-libc-types.struct_sockaddr
.llvm-libc-types.struct_sockaddr_un
)
Expand Down
6 changes: 4 additions & 2 deletions libc/include/llvm-libc-types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ add_header(
add_header(wint_t HDR wint_t.h)
add_header(sa_family_t HDR sa_family_t.h)
add_header(socklen_t HDR socklen_t.h)
add_header(struct_sockaddr_un HDR struct_sockaddr_un.h)
add_header(struct_sockaddr HDR struct_sockaddr.h)
add_header(struct_sockaddr_un HDR struct_sockaddr_un.h DEPENDS .sa_family_t)
add_header(struct_sockaddr HDR struct_sockaddr.h DEPENDS .sa_family_t)
add_header(struct_iovec HDR struct_iovec.h DEPENDS .size_t)
add_header(struct_msghdr HDR struct_msghdr.h DEPENDS .size_t .socklen_t .struct_iovec)
add_header(rpc_opcodes_t HDR rpc_opcodes_t.h)
add_header(ACTION HDR ACTION.h)
add_header(ENTRY HDR ENTRY.h)
Expand Down
19 changes: 19 additions & 0 deletions libc/include/llvm-libc-types/struct_iovec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Definition of struct iovec ----------------------------------------===//
//
// 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_TYPES_STRUCT_IOVEC_H
#define LLVM_LIBC_TYPES_STRUCT_IOVEC_H

#include "size_t.h"

struct iovec {
void *iov_base;
size_t iov_len;
};

#endif // LLVM_LIBC_TYPES_STRUCT_IOVEC_H
26 changes: 26 additions & 0 deletions libc/include/llvm-libc-types/struct_msghdr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===-- Definition of struct msghdr ---------------------------------------===//
//
// 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_TYPES_STRUCT_MSGHDR_H
#define LLVM_LIBC_TYPES_STRUCT_MSGHDR_H

#include "size_t.h"
#include "socklen_t.h"
#include "struct_iovec.h"

struct msghdr {
void *msg_name; /* Optional address */
socklen_t msg_namelen; /* Size of address */
struct iovec *msg_iov; /* Scatter/gather array */
size_t msg_iovlen; /* # elements in msg_iov */
void *msg_control; /* Ancillary data, see below */
size_t msg_controllen; /* Ancillary data buffer len */
int msg_flags; /* Flags (unused) */
};

#endif // LLVM_LIBC_TYPES_STRUCT_MSGHDR_H
92 changes: 92 additions & 0 deletions libc/newhdrgen/yaml/sys/socket.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@ types:
- type_name: struct_sockaddr
- type_name: socklen_t
- type_name: sa_family_t
- type_name: struct_msghdr
- type_name: struct_iovec
- type_name: size_t
- type_name: ssize_t
enums: []
objects: []
functions:
- name: accept
standards:
- POSIX
return_type: int
arguments:
- type: int
- type: sockaddr *__restrict
- type: socklen_t *__restrict
- name: bind
standards:
- POSIX
Expand All @@ -16,6 +28,77 @@ functions:
- type: int
- type: const struct sockaddr *
- type: socklen_t
- name: connect
standards:
- POSIX
return_type: int
arguments:
- type: int
- type: const struct sockaddr *
- type: socklen_t
- name: listen
standards:
- POSIX
return_type: int
arguments:
- type: int
- type: int
- name: recv
standards:
- POSIX
return_type: ssize_t
arguments:
- type: int
- type: const void *
- type: size_t
- type: int
- name: recvfrom
standards:
- POSIX
return_type: ssize_t
arguments:
- type: int
- type: const void*
- type: size_t
- type: int
- type: const struct sockaddr *
- type: socklen_t
- name: recvmsg
standards:
- POSIX
return_type: ssize_t
arguments:
- type: int
- type: const struct msghdr *
- type: int
- name: send
standards:
- POSIX
return_type: ssize_t
arguments:
- type: int
- type: const void*
- type: size_t
- type: int
- name: sendmsg
standards:
- POSIX
return_type: ssize_t
arguments:
- type: int
- type: const struct msghdr *
- type: int
- name: sendto
standards:
- POSIX
return_type: ssize_t
arguments:
- type: int
- type: const void *
- type: size_t
- type: int
- type: const struct sockaddr *
- type: socklen_t
- name: socket
standards:
- POSIX
Expand All @@ -24,3 +107,12 @@ functions:
- type: int
- type: int
- type: int
- name: socketpair
standards:
- posix
return_type: int
arguments:
- type: int
- type: int
- type: int
- type: int*
Loading
Loading