util: introduce syscall to avoid vararg argument parsing

This commit is contained in:
Robert Swiecki 2019-01-21 22:25:37 +01:00
parent d1151ea4bd
commit 681fce1cc4
2 changed files with 9 additions and 1 deletions

View File

@ -212,7 +212,7 @@ static const uint64_t c = 1442695040888963407ULL;
static void rndInitThread(void) {
#if defined(__NR_getrandom)
if (syscall(__NR_getrandom, &rndX, sizeof(rndX), 0) == sizeof(rndX)) {
if (util::syscall(__NR_getrandom, (uintptr_t)&rndX, sizeof(rndX), 0) == sizeof(rndX)) {
return;
}
#endif /* defined(__NR_getrandom) */
@ -317,4 +317,9 @@ std::vector<std::string> strSplit(const std::string str, char delim) {
return vec;
}
long syscall(long sysno, uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4,
uintptr_t a5) {
return syscall(sysno, a0, a1, a2, a3, a4, a5);
}
} // namespace util

3
util.h
View File

@ -22,6 +22,7 @@
#ifndef NS_UTIL_H
#define NS_UTIL_H
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
@ -53,6 +54,8 @@ uint64_t rnd64(void);
const std::string sigName(int signo);
const std::string timeToStr(time_t t);
std::vector<std::string> strSplit(const std::string str, char delim);
long syscall(long sysno, uintptr_t a0 = 0, uintptr_t a1 = 0, uintptr_t a2 = 0, uintptr_t a3 = 0,
uintptr_t a4 = 0, uintptr_t a5 = 0);
} // namespace util