summaryrefslogtreecommitdiff
path: root/util/nvmutil/include
diff options
context:
space:
mode:
Diffstat (limited to 'util/nvmutil/include')
-rw-r--r--util/nvmutil/include/common.h66
1 files changed, 41 insertions, 25 deletions
diff --git a/util/nvmutil/include/common.h b/util/nvmutil/include/common.h
index f9a4ba1c..46fbcb38 100644
--- a/util/nvmutil/include/common.h
+++ b/util/nvmutil/include/common.h
@@ -1,18 +1,31 @@
-/*
- * SPDX-License-Identifier: MIT
- *
+/* SPDX-License-Identifier: MIT
* Copyright (c) 2022-2026 Leah Rowe <leah@libreboot.org>
*/
#ifndef COMMON_H
#define COMMON_H
-/* keep SYS_RENAME 1 to
- * use libc rename()
- * recommended
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <limits.h>
+
+/* for linux getrandom
*/
-#ifndef SYS_RENAME
-#define SYS_RENAME 1
+#if defined(__linux__)
+#include <errno.h>
+#if defined(__has_include)
+#if __has_include(<sys/random.h>)
+#include <sys/random.h>
+#define HAVE_GETRANDOM 1
+#endif
+#endif
+#if !defined(HAVE_GETRANDOM)
+#include <sys/syscall.h>
+#if defined(SYS_getrandom)
+#define HAVE_GETRANDOM_SYSCALL 1
+#endif
+#endif
+
#endif
#define items(x) (sizeof((x)) / sizeof((x)[0]))
@@ -39,7 +52,7 @@ int fchmod(int fd, mode_t mode);
#define MAX_CMD_LEN 50
#ifndef PATH_LEN
-#define PATH_LEN 1024
+#define PATH_LEN 4096
#endif
#define OFF_ERR 0
@@ -63,10 +76,6 @@ int fchmod(int fd, mode_t mode);
#define HAVE_REAL_PREAD_PWRITE 0
#endif
-#ifndef MAX_EAGAIN_RETRIES
-#define MAX_EAGAIN_RETRIES 100000
-#endif
-
#ifndef LOOP_EAGAIN
#define LOOP_EAGAIN 1
#endif
@@ -328,6 +337,18 @@ void set_mac_nib(unsigned long mac_str_pos,
unsigned long mac_byte_pos, unsigned long mac_nib_pos);
unsigned short hextonum(char ch_s);
unsigned long rlong(void);
+#if !(defined(FALLBACK_RAND_1989) && \
+ ((FALLBACK_RAND_1989) > 0))
+#if defined(__linux__)
+#if defined(HAVE_GETRANDOM) || \
+ defined(HAVE_GETRANDOM_SYSCALL)
+int fallback_rand_getrandom(void *buf, size_t len);
+#endif
+#endif
+#else
+unsigned long fallback_rand_1989(void);
+unsigned long entropy_jitter(void);
+#endif
void write_mac_part(unsigned long partnum);
/* Helper functions for command: dump
@@ -412,7 +433,7 @@ int check_file(int fd, struct stat *st);
long rw_over_nrw(long r, unsigned long nrw);
#if !defined(HAVE_REAL_PREAD_PWRITE) || \
HAVE_REAL_PREAD_PWRITE < 1
-off_t lseek_loop(int fd, off_t off,
+off_t lseek_on_eintr(int fd, off_t off,
int whence, int loop_eagain, int loop_eintr);
#endif
int try_err(int loop_err, int errval);
@@ -429,16 +450,10 @@ const char *getnvmprogname(void);
*/
char *new_tmpfile(int *fd, int local, const char *path);
-int x_i_mkstemp(char *template);
-char *x_c_strrchr(const char *s, int c);
-int x_i_rename(const char *src, const char *dst);
-char *x_c_tmpdir(void);
-int x_i_close(int fd);
-void *x_v_memcpy(void *dst,
- const void *src, unsigned long n);
-int x_i_memcmp(const void *a,
- const void *b, unsigned long n);
-int x_i_fsync(int fd);
+int mkstemp_n(char *template);
+char *get_tmpdir(void);
+int close_on_eintr(int fd);
+int fsync_on_eintr(int fd);
/* asserts */
@@ -454,6 +469,8 @@ typedef char static_assert_unsigned_int_is_4[
(sizeof(unsigned int) >= 4) ? 1 : -1];
typedef char static_assert_unsigned_long_is_4[
(sizeof(unsigned long) >= 4) ? 1 : -1];
+typedef char static_assert_long_ulong[
+ (sizeof(unsigned long) == sizeof(long)) ? 1 : -1];
typedef char static_assert_int_ge_32[(sizeof(int) >= 4) ? 1 : -1];
typedef char static_assert_twos_complement[
((-1 & 3) == 3) ? 1 : -1
@@ -501,6 +518,5 @@ typedef char bool_no_loop_eagain[(NO_LOOP_EAGAIN==0)?1:-1];
typedef char bool_off_err[(OFF_ERR==0)?1:-1];
typedef char bool_off_reset[(OFF_RESET==0||OFF_RESET==1)?1:-1];
-
#endif
#endif