Remove <private/bsd_sys_param.h>.
It's hardly used, and the two most interesting users are clearer with
modern alignof() anyway.
Bug: 373789390
Change-Id: I52368ab372ee3afd4ed2dd8e373ff0223d59db0e
diff --git a/libc/Android.bp b/libc/Android.bp
index ae6df52..d9b3658 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -353,7 +353,6 @@
"-Wno-unused-parameter",
"-include netbsd-compat.h",
"-Wframe-larger-than=66000",
- "-include private/bsd_sys_param.h",
],
local_include_dirs: [
diff --git a/libc/bionic/fts.c b/libc/bionic/fts.c
index 1287267..c36835e 100644
--- a/libc/bionic/fts.c
+++ b/libc/bionic/fts.c
@@ -29,7 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/param.h> /* ALIGN */
#include <sys/stat.h>
#include <dirent.h>
@@ -37,6 +36,7 @@
#include <fcntl.h>
#include <fts.h>
#include <limits.h>
+#include <stdalign.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -912,10 +912,14 @@
* be careful that the stat structure is reasonably aligned. Since the
* fts_name field is declared to be of size 1, the fts_name pointer is
* namelen + 2 before the first possible address of the stat structure.
+ *
+ * We can't use the same trick FreeBSD uses here because our fts_name
+ * is a char[1] rather than a char*. This is also the reason we don't
+ * need to say `namelen + 1`. We just assume the worst alignment.
*/
len = sizeof(FTSENT) + namelen;
if (!ISSET(FTS_NOSTAT))
- len += sizeof(struct stat) + ALIGNBYTES;
+ len += alignof(struct stat) + sizeof(struct stat);
if ((p = calloc(1, len)) == NULL)
return (NULL);
@@ -923,7 +927,7 @@
p->fts_namelen = namelen;
p->fts_instr = FTS_NOINSTR;
if (!ISSET(FTS_NOSTAT))
- p->fts_statp = (struct stat *)ALIGN(p->fts_name + namelen + 2);
+ p->fts_statp = (struct stat *)__builtin_align_up(p->fts_name + namelen + 2, alignof(struct stat));
memcpy(p->fts_name, name, namelen);
return (p);
diff --git a/libc/dns/net/gethnamaddr.c b/libc/dns/net/gethnamaddr.c
index add124f..1ffabfa 100644
--- a/libc/dns/net/gethnamaddr.c
+++ b/libc/dns/net/gethnamaddr.c
@@ -495,7 +495,7 @@
*he = NO_RECOVERY;
return NULL;
success:
- bp = (char *)ALIGN(bp);
+ bp = __builtin_align_up(bp, sizeof(uintptr_t));
n = (int)(ap - aliases);
qlen = (n + 1) * sizeof(*hent->h_aliases);
if ((size_t)(ep - bp) < qlen)
@@ -616,7 +616,7 @@
}
// Fix alignment after variable-length data.
- ptr = (char*)ALIGN(ptr);
+ ptr = __builtin_align_up(ptr, sizeof(uintptr_t));
int aliases_len = ((int)(aliases - aliases_ptrs) + 1) * sizeof(*hp->h_aliases);
if (ptr + aliases_len > hbuf_end) {
@@ -653,7 +653,7 @@
}
// Fix alignment after variable-length data.
- ptr = (char*)ALIGN(ptr);
+ ptr = __builtin_align_up(ptr, sizeof(uintptr_t));
int addrs_len = ((int)(addr_p - addr_ptrs) + 1) * sizeof(*hp->h_addr_list);
if (ptr + addrs_len > hbuf_end) {
diff --git a/libc/dns/net/sethostent.c b/libc/dns/net/sethostent.c
index 5c4bdb5..8ea4315 100644
--- a/libc/dns/net/sethostent.c
+++ b/libc/dns/net/sethostent.c
@@ -198,7 +198,7 @@
HENT_SCOPY(aliases[anum], hp->h_aliases[anum],
ptr, len);
}
- ptr = (void *)ALIGN(ptr);
+ ptr = __builtin_align_up(ptr, sizeof(uintptr_t));
if ((size_t)(ptr - buf) >= info->buflen)
goto nospc;
}
diff --git a/libc/private/bsd_sys_param.h b/libc/private/bsd_sys_param.h
deleted file mode 100644
index ab54aa0..0000000
--- a/libc/private/bsd_sys_param.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <inttypes.h>
-
-/* OpenBSD has these in <sys/param.h>, but "ALIGN" isn't something we want to reserve. */
-#define ALIGNBYTES (sizeof(uintptr_t) - 1)
-#define ALIGN(p) ((__BIONIC_CAST(reinterpret_cast, uintptr_t, p) + ALIGNBYTES) & ~ALIGNBYTES)
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index 37b9665..a5f2f81 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -58,8 +58,6 @@
#include "private/bionic_fortify.h"
#include "private/thread_private.h"
-#include "private/bsd_sys_param.h" // For ALIGN/ALIGNBYTES.
-
#define NDYNAMIC 10 /* add ten more whenever necessary */
#define PRINTF_IMPL(expr) \
@@ -135,12 +133,14 @@
};
static glue* moreglue(int n) {
- char* data = new char[sizeof(glue) + ALIGNBYTES + n * sizeof(FILE) + n * sizeof(__sfileext)];
+ char* data = new char[sizeof(glue) +
+ alignof(FILE) + n * sizeof(FILE) +
+ alignof(__sfileext) + n * sizeof(__sfileext)];
if (data == nullptr) return nullptr;
glue* g = reinterpret_cast<glue*>(data);
- FILE* p = reinterpret_cast<FILE*>(ALIGN(data + sizeof(*g)));
- __sfileext* pext = reinterpret_cast<__sfileext*>(ALIGN(data + sizeof(*g)) + n * sizeof(FILE));
+ FILE* p = reinterpret_cast<FILE*>(__builtin_align_up(g + 1, alignof(FILE)));
+ __sfileext* pext = reinterpret_cast<__sfileext*>(__builtin_align_up(p + n, alignof(__sfileext)));
g->next = nullptr;
g->niobs = n;
g->iobs = p;
diff --git a/libc/upstream-openbsd/android/include/openbsd-compat.h b/libc/upstream-openbsd/android/include/openbsd-compat.h
index cbc52b5..ac6840a 100644
--- a/libc/upstream-openbsd/android/include/openbsd-compat.h
+++ b/libc/upstream-openbsd/android/include/openbsd-compat.h
@@ -25,8 +25,6 @@
#include <sys/random.h> // For getentropy.
-#include "private/bsd_sys_param.h"
-
#define __BEGIN_HIDDEN_DECLS _Pragma("GCC visibility push(hidden)")
#define __END_HIDDEN_DECLS _Pragma("GCC visibility pop")