Skip to content

Commit

Permalink
Merge pull request #412 from Tarsnap/libcperciva-import
Browse files Browse the repository at this point in the history
Libcperciva import
  • Loading branch information
cperciva authored Jan 13, 2025
2 parents d316e2d + 4da012d commit cbe523b
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 19 deletions.
2 changes: 1 addition & 1 deletion liball/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ setuidgid.o: ../libcperciva/util/setuidgid.c ../libcperciva/util/parsenum.h ../l
${CC} ${CFLAGS_POSIX} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DCPUSUPPORT_CONFIG_FILE=\"cpusupport-config.h\" -DAPISUPPORT_CONFIG_FILE=\"apisupport-config.h\" -I.. ${IDIRS} ${CPPFLAGS} ${CFLAGS} -c ../libcperciva/util/setuidgid.c -o setuidgid.o
sock.o: ../libcperciva/util/sock.c ../libcperciva/util/imalloc.h ../libcperciva/util/parsenum.h ../libcperciva/util/warnp.h ../libcperciva/util/sock.h ../libcperciva/util/sock_internal.h ../libcperciva/util/sock_util.h
${CC} ${CFLAGS_POSIX} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DCPUSUPPORT_CONFIG_FILE=\"cpusupport-config.h\" -DAPISUPPORT_CONFIG_FILE=\"apisupport-config.h\" -I.. ${IDIRS} ${CPPFLAGS} ${CFLAGS} -c ../libcperciva/util/sock.c -o sock.o
sock_util.o: ../libcperciva/util/sock_util.c ../libcperciva/util/asprintf.h ../libcperciva/util/sock.h ../libcperciva/util/sock_internal.h ../libcperciva/util/sock_util.h
sock_util.o: ../libcperciva/util/sock_util.c ../libcperciva/util/asprintf.h ../libcperciva/util/sock.h ../libcperciva/util/warnp.h ../libcperciva/util/sock_internal.h ../libcperciva/util/sock_util.h
${CC} ${CFLAGS_POSIX} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DCPUSUPPORT_CONFIG_FILE=\"cpusupport-config.h\" -DAPISUPPORT_CONFIG_FILE=\"apisupport-config.h\" -I.. ${IDIRS} ${CPPFLAGS} ${CFLAGS} -c ../libcperciva/util/sock_util.c -o sock_util.o
warnp.o: ../libcperciva/util/warnp.c ../libcperciva/util/warnp.h
${CC} ${CFLAGS_POSIX} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DCPUSUPPORT_CONFIG_FILE=\"cpusupport-config.h\" -DAPISUPPORT_CONFIG_FILE=\"apisupport-config.h\" -I.. ${IDIRS} ${CPPFLAGS} ${CFLAGS} -c ../libcperciva/util/warnp.c -o warnp.o
Expand Down
2 changes: 2 additions & 0 deletions libcperciva/cpusupport/Build/cpusupport-ARM-AES.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ main(void)
uint32x4_t lanes = {0};
uint8_t arr[16] = {0};

/* Check AES. */
data = vld1q_u8(arr);
output = vaeseq_u8(data, key);
(void)output; /* UNUSED */

/* Check _u32: some compilers only support the _u8 variant. */
lanes = vdupq_laneq_u32(lanes, 0);

/* Success! */
Expand Down
2 changes: 2 additions & 0 deletions libcperciva/cpusupport/cpusupport_x86_aesni.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ CPUSUPPORT_FEATURE_DECL(x86, aesni)

unsupported:
#endif

/* Not supported. */
return (0);
}
2 changes: 2 additions & 0 deletions libcperciva/cpusupport/cpusupport_x86_rdrand.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ CPUSUPPORT_FEATURE_DECL(x86, rdrand)

unsupported:
#endif

/* Not supported. */
return (0);
}
2 changes: 2 additions & 0 deletions libcperciva/cpusupport/cpusupport_x86_shani.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ CPUSUPPORT_FEATURE_DECL(x86, shani)

unsupported:
#endif

/* Not supported. */
return (0);
}
2 changes: 2 additions & 0 deletions libcperciva/cpusupport/cpusupport_x86_sse2.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ CPUSUPPORT_FEATURE_DECL(x86, sse2)

unsupported:
#endif

/* Not supported. */
return (0);
}
2 changes: 2 additions & 0 deletions libcperciva/cpusupport/cpusupport_x86_ssse3.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ CPUSUPPORT_FEATURE_DECL(x86, ssse3)

unsupported:
#endif

/* Not supported. */
return (0);
}
1 change: 1 addition & 0 deletions libcperciva/datastruct/elasticarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ void *
elasticarray_get(struct elasticarray * EA, size_t pos, size_t reclen)
{

/* Calculate the pointer address. */
return ((uint8_t *)(EA->buf) + pos * reclen);
}

Expand Down
1 change: 1 addition & 0 deletions libcperciva/datastruct/timerqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ compar(void * cookie, const void * x, const void * y)

(void)cookie; /* UNUSED */

/* Compare the times. */
return (tvcmp(&_x->tv, &_y->tv));
}

Expand Down
1 change: 1 addition & 0 deletions libcperciva/netbuf/netbuf_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct netbuf_read *
netbuf_read_init(int s)
{

/* Call the real function (without SSL). */
return (netbuf_read_init2(s, NULL));
}

Expand Down
2 changes: 2 additions & 0 deletions libcperciva/util/align_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ align_ptr(uint8_t * arr, size_t alignment)
*/
offset = (uintptr_t)(&arr[0]) % alignment;
offset = (alignment - offset) % alignment;

/* Return the aligned pointer. */
return ((void *)&arr[offset]);
}

Expand Down
2 changes: 1 addition & 1 deletion libcperciva/util/daemonize.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ daemonize(const char * spid)
* releasing them for the benefit of leak checkers.
*/
if (ipc_sync_done(IS))
goto err1;
goto err0;

/* We have been poked by the child. Exit. */
_exit(0);
Expand Down
7 changes: 4 additions & 3 deletions libcperciva/util/imalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ imalloc(size_t nrec, size_t reclen)
/* Sanity check. */
assert(reclen != 0);

/* Handle cases where we don't allocate memory. */
if (nrec == 0)
return (NULL);

if (nrec > SIZE_MAX / reclen) {
errno = ENOMEM;
return (NULL);
} else {
return (malloc(nrec * reclen));
}

/* Allocate memory. */
return (malloc(nrec * reclen));
}

/**
Expand Down
6 changes: 6 additions & 0 deletions libcperciva/util/optional_mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ optional_mutex_lock(pthread_mutex_t * mutex)
{

#ifdef OPTIONAL_MUTEX_PTHREAD_YES
/* Mutexes are enabled; call the pthread function. */
return (pthread_mutex_lock(mutex));
#else
(void)mutex; /* UNUSED */

/* Do nothing. */
return (0);
#endif
}
Expand All @@ -49,9 +52,12 @@ optional_mutex_unlock(pthread_mutex_t * mutex)
{

#ifdef OPTIONAL_MUTEX_PTHREAD_YES
/* Mutexes are enabled; call the pthread function. */
return (pthread_mutex_unlock(mutex));
#else
(void)mutex; /* UNUSED */

/* Do nothing. */
return (0);
#endif
}
Expand Down
2 changes: 2 additions & 0 deletions libcperciva/util/setgroups_none.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ setgroups_none(void)
{

#ifdef NO_SETGROUPS
/* Not supported. */
return (0);
#else
/* Attempt to leave all supplementary groups. */
return (setgroups(0, NULL));
#endif
}
25 changes: 21 additions & 4 deletions release-tools/metabuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ get_apisupport_cflags() {
done | sed 's/^ //'
}

join_str() {
out=""
for text in "$@"; do
if [ -n "${out}" ]; then
# If we already have something in ${out}, add a space.
if [ -n "${text}" ]; then
out="${out} ${text}"
fi
else
# If ${out} is empty, set it to the first item.
out="${text}"
fi
done
printf "%s" "${out}"
}

add_object_files() {
# Set up useful variables
OBJ=$(${MAKEBSD} -v SRCS | \
Expand All @@ -131,8 +147,8 @@ add_object_files() {
CF_MANUAL=$(${MAKEBSD} -v CFLAGS."$(basename "${S}")")
CF_CPUSUPPORT=$(get_cpusupport_cflags "${S}")
CF_APISUPPORT=$(get_apisupport_cflags "${S}")
CF=$(echo "${CF_CPUSUPPORT} ${CF_APISUPPORT} ${CF_MANUAL}" | \
sed 's/^ //' | sed 's/ $//')
CF=$(join_str "${CF_CPUSUPPORT}" "${CF_APISUPPORT}" \
"${CF_MANUAL}")
IDIRS=$(${MAKEBSD} -v IDIRS)
# Get the build dependencies, then remove newlines, condense
# multiple spaces, remove line continuations, and replace the
Expand All @@ -145,8 +161,9 @@ add_object_files() {
sed -e 's| $||g'
printf "\n"
# Print the build instructions
echo " ${OUT_CC_BEGIN} ${OUT_CC_MID} ${CF} -c ${S} -o ${F}" |
tr -s ' '
line=$(join_str "${OUT_CC_BEGIN}" "${OUT_CC_MID}" \
"${CF}" "-c" "${S}" "-o" "${F}")
printf "\t%s\n" "${line}"
done >> "${OUT}"
}

Expand Down
2 changes: 1 addition & 1 deletion spipe/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ clean:
${PROG}:${SRCS:.c=.o} ${LIBALL}
${CC} -o ${PROG} ${SRCS:.c=.o} ${LIBALL} ${LDFLAGS} ${LDADD_EXTRA} ${LDADD_REQ} ${LDADD_POSIX}

main.o: main.c ../libcperciva/events/events.h ../libcperciva/util/getopt.h ../lib/util/graceful_shutdown.h ../libcperciva/util/parsenum.h ../libcperciva/util/sock.h ../libcperciva/util/warnp.h ../lib/proto/proto_conn.h ../lib/proto/proto_crypt.h ../libcperciva/crypto/crypto_dh.h pushbits.h
main.o: main.c ../libcperciva/events/events.h ../libcperciva/util/getopt.h ../lib/util/graceful_shutdown.h ../libcperciva/util/parsenum.h ../libcperciva/util/sock.h ../libcperciva/util/sock_util.h ../libcperciva/util/warnp.h ../lib/proto/proto_conn.h ../lib/proto/proto_crypt.h ../libcperciva/crypto/crypto_dh.h pushbits.h
${CC} ${CFLAGS_POSIX} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DCPUSUPPORT_CONFIG_FILE=\"cpusupport-config.h\" -DAPISUPPORT_CONFIG_FILE=\"apisupport-config.h\" -I.. ${IDIRS} ${CPPFLAGS} ${CFLAGS} -c main.c -o main.o
pushbits.o: pushbits.c ../libcperciva/util/noeintr.h ../lib/util/pthread_create_blocking_np.h ../libcperciva/util/warnp.h pushbits.h
${CC} ${CFLAGS_POSIX} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DCPUSUPPORT_CONFIG_FILE=\"cpusupport-config.h\" -DAPISUPPORT_CONFIG_FILE=\"apisupport-config.h\" -I.. ${IDIRS} ${CPPFLAGS} ${CFLAGS} -c pushbits.c -o pushbits.o
2 changes: 1 addition & 1 deletion spiped/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ clean:
${PROG}:${SRCS:.c=.o} ${LIBALL}
${CC} -o ${PROG} ${SRCS:.c=.o} ${LIBALL} ${LDFLAGS} ${LDADD_EXTRA} ${LDADD_REQ} ${LDADD_POSIX}

main.o: main.c ../libcperciva/util/asprintf.h ../libcperciva/util/daemonize.h ../libcperciva/events/events.h ../libcperciva/util/getopt.h ../lib/util/graceful_shutdown.h ../libcperciva/util/parsenum.h ../libcperciva/util/setuidgid.h ../libcperciva/util/sock.h ../libcperciva/util/warnp.h dispatch.h ../lib/proto/proto_crypt.h ../libcperciva/crypto/crypto_dh.h
main.o: main.c ../libcperciva/util/asprintf.h ../libcperciva/util/daemonize.h ../libcperciva/events/events.h ../libcperciva/util/getopt.h ../lib/util/graceful_shutdown.h ../libcperciva/util/parsenum.h ../libcperciva/util/setuidgid.h ../libcperciva/util/sock.h ../libcperciva/util/sock_util.h ../libcperciva/util/warnp.h dispatch.h ../lib/proto/proto_crypt.h ../libcperciva/crypto/crypto_dh.h
${CC} ${CFLAGS_POSIX} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DCPUSUPPORT_CONFIG_FILE=\"cpusupport-config.h\" -DAPISUPPORT_CONFIG_FILE=\"apisupport-config.h\" -I.. ${IDIRS} ${CPPFLAGS} ${CFLAGS} -c main.c -o main.o
dispatch.o: dispatch.c ../lib/dnsthread/dnsthread.h ../libcperciva/events/events.h ../libcperciva/network/network.h ../libcperciva/external/queue/queue.h ../libcperciva/util/sock.h ../libcperciva/util/sock_util.h ../libcperciva/util/warnp.h ../lib/proto/proto_conn.h dispatch.h
${CC} ${CFLAGS_POSIX} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DCPUSUPPORT_CONFIG_FILE=\"cpusupport-config.h\" -DAPISUPPORT_CONFIG_FILE=\"apisupport-config.h\" -I.. ${IDIRS} ${CPPFLAGS} ${CFLAGS} -c dispatch.c -o dispatch.o
21 changes: 13 additions & 8 deletions tests/shared_valgrind_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,13 @@ valgrind_setup() {
fi

# Set up valgrind command.
_valgrind_setup_cmd="valgrind \
--log-file=${_valgrind_setup_logfilename} \
--track-fds=yes \
--trace-children=yes \
--leak-check=full --show-leak-kinds=all \
--errors-for-leak-kinds=all \
_valgrind_setup_cmd="valgrind \
--log-file=${_valgrind_setup_logfilename} \
--track-fds=yes \
--trace-children=yes \
--leak-check=full \
--show-leak-kinds=all \
--errors-for-leak-kinds=all \
--suppressions=${valgrind_suppressions}"
echo "${_valgrind_setup_cmd}"
}
Expand Down Expand Up @@ -333,9 +334,13 @@ _val_checkl() {
return
fi

# Check the error summary.
# Check the error summary. Get the number of expected errors from the
# ${valgrind_fds_log} file. (Ideally this would be 0, but due to
# porting issues, some versions of valgrind on some platforms always
# report a non-zero number of errors.)
_val_checkl_num_errors=$(grep "ERROR SUMMARY: " "${_val_checkl_logfile}" | awk '{print $4}')
if [ "${_val_checkl_num_errors}" -gt 0 ]; then
_val_checkl_num_errors_basic=$(grep "ERROR SUMMARY: " "${valgrind_fds_log}" | awk '{ print $4}')
if [ "${_val_checkl_num_errors}" != "${_val_checkl_num_errors_basic}" ]; then
# There was some other error(s) -- invalid read or write,
# conditional jump based on uninitialized value(s), invalid
# free, etc.
Expand Down

0 comments on commit cbe523b

Please sign in to comment.