Discussion:
[PATCH 2/2] ck: add pr_{load,store}_bool functions
Jason A. Donenfeld
2021-04-23 05:39:02 UTC
Permalink
While these are functionally the same as ck_pr_{load,store}_8, it's
actually quite useful to be able to use this on ordinary bool types,
without having to add casting to every callsite.

Signed-off-by: Jason A. Donenfeld <***@zx2c4.com>
---
sys/contrib/ck/include/ck_pr.h | 2 ++
1 file changed, 2 insertions(+)

diff --git a/sys/contrib/ck/include/ck_pr.h b/sys/contrib/ck/include/ck_pr.h
index 2de6e13ec3c..61616213999 100644
--- a/sys/contrib/ck/include/ck_pr.h
+++ b/sys/contrib/ck/include/ck_pr.h
@@ -179,6 +179,7 @@ ck_pr_rfo(const void *m)
#define ck_pr_store_32(DST, VAL) CK_PR_STORE_SAFE((DST), (VAL), 32)
#define ck_pr_store_16(DST, VAL) CK_PR_STORE_SAFE((DST), (VAL), 16)
#define ck_pr_store_8(DST, VAL) CK_PR_STORE_SAFE((DST), (VAL), 8)
+#define ck_pr_store_bool(DST, VAL) ck_pr_store_8((uint8_t *)(DST), (uint8_t)(VAL))

#define ck_pr_store_ptr_unsafe(DST, VAL) ck_pr_md_store_ptr((DST), (VAL))

@@ -199,6 +200,7 @@ ck_pr_rfo(const void *m)
#define ck_pr_load_32(SRC) CK_PR_LOAD_SAFE((SRC), 32)
#define ck_pr_load_16(SRC) CK_PR_LOAD_SAFE((SRC), 16)
#define ck_pr_load_8(SRC) CK_PR_LOAD_SAFE((SRC), 8)
+#define ck_pr_load_bool(SRC) ((bool)ck_pr_load_8((uint8_t *)(SRC)))

#ifdef CK_F_PR_LOAD_64
#define ck_pr_load_64(SRC) CK_PR_LOAD_SAFE((SRC), 64)
--
2.31.1
Jason A. Donenfeld
2021-04-23 05:39:01 UTC
Permalink
It is useful to be able to call pr_usrreqs->pru_sockaddr on a struct
socket, so this commit adds a wrapper around it, analogous to the other
types of socket getters.

Original-author: Kyle Evans <***@FreeBSD.org>
Signed-off-by: Jason A. Donenfeld <***@zx2c4.com>
---
sys/kern/uipc_socket.c | 11 +++++++++++
sys/sys/socketvar.h | 1 +
2 files changed, 12 insertions(+)

diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index 92a204aafef..374e2a3abaa 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -3506,6 +3506,17 @@ soopt_mcopyout(struct sockopt *sopt, struct mbuf *m)
return (0);
}

+int
+sogetsockaddr(struct socket *so, struct sockaddr **nam)
+{
+ int error;
+
+ CURVNET_SET(so->so_vnet);
+ error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, nam);
+ CURVNET_RESTORE();
+ return (error);
+}
+
/*
* sohasoutofband(): protocol notifies socket layer of the arrival of new
* out-of-band data, which will then notify socket consumers.
diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h
index 295a1cf3d37..ad616a4d893 100644
--- a/sys/sys/socketvar.h
+++ b/sys/sys/socketvar.h
@@ -428,6 +428,7 @@ int sodisconnect(struct socket *so);
void sodtor_set(struct socket *, so_dtor_t *);
struct sockaddr *sodupsockaddr(const struct sockaddr *sa, int mflags);
void sofree(struct socket *so);
+int sogetsockaddr(struct socket *so, struct sockaddr **nam);
void sohasoutofband(struct socket *so);
int solisten(struct socket *so, int backlog, struct thread *td);
void solisten_proto(struct socket *so, int backlog);
--
2.31.1
Jason A. Donenfeld
2021-05-05 12:56:35 UTC
Permalink
I wound up posting the 1/2 patch to phabricator here:
https://reviews.freebsd.org/D30087

Could somebody review and commit this?

Thanks,
Jason

Loading...