mirror of
https://github.com/hashcat/hashcat.git
synced 2024-11-13 19:28:56 +00:00
Merge pull request #3117 from DeforaNetworks/khorben/netbsd
Fix the build for NetBSD
This commit is contained in:
commit
ee2d50d341
@ -25,7 +25,7 @@ Slightly modified to work with hashcat to no falsly detect _SORT_R_LINUX with mi
|
||||
*/
|
||||
|
||||
#if (defined __APPLE__ || defined __MACH__ || defined __DARWIN__ || \
|
||||
defined __FreeBSD__ || defined __DragonFly__)
|
||||
defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__)
|
||||
# define _SORT_R_BSD
|
||||
# define _SORT_R_INLINE inline
|
||||
#elif (defined __linux__) || defined (__CYGWIN__)
|
||||
@ -202,7 +202,12 @@ static _SORT_R_INLINE void sort_r_simple(void *base, size_t nel, size_t w,
|
||||
struct sort_r_data tmp;
|
||||
tmp.arg = arg;
|
||||
tmp.compar = compar;
|
||||
qsort_r(base, nel, width, &tmp, sort_r_arg_swap);
|
||||
|
||||
#if defined __NetBSD__
|
||||
sort_r_simple(base, nel, width, compar, arg);
|
||||
#else
|
||||
qsort_r(base, nel, width, &tmp, sort_r_arg_swap);
|
||||
#endif
|
||||
|
||||
#elif defined _SORT_R_WINDOWS
|
||||
|
||||
|
14
src/Makefile
14
src/Makefile
@ -31,7 +31,7 @@ UNAME := $(patsubst MSYS_NT-%,MSYS2,$(UNAME))
|
||||
UNAME := $(patsubst MINGW32_NT-%,MSYS2,$(UNAME))
|
||||
UNAME := $(patsubst MINGW64_NT-%,MSYS2,$(UNAME))
|
||||
|
||||
ifeq (,$(filter $(UNAME),Linux FreeBSD Darwin CYGWIN MSYS2))
|
||||
ifeq (,$(filter $(UNAME),Linux FreeBSD NetBSD Darwin CYGWIN MSYS2))
|
||||
$(error "! Your Operating System ($(UNAME)) is not supported by this Makefile")
|
||||
endif
|
||||
|
||||
@ -78,7 +78,7 @@ SED_IN_PLACE := -i ""
|
||||
DARWIN_VERSION := $(shell uname -r | cut -d. -f1)
|
||||
endif
|
||||
|
||||
ifeq ($(UNAME),FreeBSD)
|
||||
ifeq (,$(filter $(UNAME),FreeBSD NetBSD))
|
||||
CC := cc
|
||||
CXX := c++
|
||||
SED := gsed
|
||||
@ -314,6 +314,12 @@ LFLAGS_NATIVE += -liconv
|
||||
endif
|
||||
endif # FreeBSD
|
||||
|
||||
ifeq ($(UNAME),NetBSD)
|
||||
CFLAGS_NATIVE := $(CFLAGS)
|
||||
LFLAGS_NATIVE := $(LFLAGS)
|
||||
LFLAGS_NATIVE += -lpthread
|
||||
endif # NetBSD
|
||||
|
||||
ifeq ($(UNAME),Darwin)
|
||||
export MACOSX_DEPLOYMENT_TARGET=10.15
|
||||
CFLAGS_NATIVE := $(CFLAGS)
|
||||
@ -457,10 +463,10 @@ distclean: clean
|
||||
# allow (whitelist) "make install" only on unix-based systems (also disallow cygwin/msys)
|
||||
|
||||
ifneq ($(findstring install,$(MAKECMDGOALS)),)
|
||||
ifeq (,$(filter $(UNAME),Linux FreeBSD Darwin))
|
||||
ifeq (,$(filter $(UNAME),Linux FreeBSD Darwin NetBSD))
|
||||
define ERROR_INSTALL_DISALLOWED
|
||||
! The 'install' target is not allowed on this operating system ($(UNAME)). \
|
||||
Only Linux, FreeBSD and Darwin can use the 'install' target
|
||||
Only Linux, FreeBSD, NetBSD and Darwin can use the 'install' target
|
||||
endef
|
||||
|
||||
$(error $(ERROR_INSTALL_DISALLOWED))
|
||||
|
@ -45,6 +45,12 @@ static int pthread_setaffinity_np (pthread_t thread, size_t cpu_size, cpu_set_t
|
||||
typedef cpuset_t cpu_set_t;
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
typedef cpuset_t cpu_set_t;
|
||||
#endif
|
||||
|
||||
int set_cpu_affinity (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx)
|
||||
{
|
||||
#if defined (__CYGWIN__)
|
||||
@ -54,19 +60,31 @@ int set_cpu_affinity (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx)
|
||||
|
||||
if (user_options->cpu_affinity == NULL) return 0;
|
||||
|
||||
char *devices = hcstrdup (user_options->cpu_affinity);
|
||||
|
||||
if (devices == NULL) return -1;
|
||||
|
||||
#if defined (_WIN)
|
||||
DWORD_PTR aff_mask = 0;
|
||||
const int cpu_id_max = 8 * sizeof (aff_mask);
|
||||
#elif defined(__NetBSD__)
|
||||
cpuset_t * cpuset;
|
||||
const int cpu_id_max = 8 * cpuset_size (cpuset);
|
||||
cpuset = cpuset_create();
|
||||
if (cpuset == NULL)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "cpuset_create() failed with error: %d", errno);
|
||||
|
||||
hcfree (devices);
|
||||
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
cpu_set_t cpuset;
|
||||
const int cpu_id_max = 8 * sizeof (cpuset);
|
||||
CPU_ZERO (&cpuset);
|
||||
#endif
|
||||
|
||||
char *devices = hcstrdup (user_options->cpu_affinity);
|
||||
|
||||
if (devices == NULL) return -1;
|
||||
|
||||
char *saveptr = NULL;
|
||||
|
||||
char *next = strtok_r (devices, ",", &saveptr);
|
||||
@ -79,6 +97,17 @@ int set_cpu_affinity (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx)
|
||||
{
|
||||
#if defined (_WIN)
|
||||
aff_mask = 0;
|
||||
#elif defined (__NetBSD__)
|
||||
cpuset_destroy (cpuset);
|
||||
cpuset = cpuset_create ();
|
||||
if (cpuset == NULL)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "cpuset_create() failed with error: %d", errno);
|
||||
|
||||
hcfree (devices);
|
||||
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
CPU_ZERO (&cpuset);
|
||||
#endif
|
||||
@ -90,6 +119,10 @@ int set_cpu_affinity (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "Invalid cpu_id %d specified.", cpu_id);
|
||||
|
||||
#if defined (__NetBSD__)
|
||||
cpuset_destroy (cpuset);
|
||||
#endif
|
||||
|
||||
hcfree (devices);
|
||||
|
||||
return -1;
|
||||
@ -97,12 +130,18 @@ int set_cpu_affinity (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx)
|
||||
|
||||
#if defined (_WIN)
|
||||
aff_mask |= ((DWORD_PTR) 1) << (cpu_id - 1);
|
||||
#elif defined (__NetBSD__)
|
||||
cpuset_set (cpu_id - 1, cpuset);
|
||||
#else
|
||||
CPU_SET ((cpu_id - 1), &cpuset);
|
||||
#endif
|
||||
|
||||
} while ((next = strtok_r ((char *) NULL, ",", &saveptr)) != NULL);
|
||||
|
||||
#if defined (__NetBSD__)
|
||||
cpuset_destroy (cpuset);
|
||||
#endif
|
||||
|
||||
hcfree (devices);
|
||||
|
||||
#if defined (_WIN)
|
||||
@ -114,6 +153,19 @@ int set_cpu_affinity (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#elif defined (__NetBSD__)
|
||||
|
||||
pthread_t thread = pthread_self ();
|
||||
|
||||
const int rc = pthread_setaffinity_np (thread, cpuset_size(cpuset), cpuset);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "pthread_setaffinity_np() failed with error: %d", rc);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
pthread_t thread = pthread_self ();
|
||||
|
20
src/folder.c
20
src/folder.c
@ -13,6 +13,9 @@
|
||||
|
||||
#if defined (__APPLE__)
|
||||
#include "event.h"
|
||||
#elif defined (__FreeBSD__) || defined (__NetBSD__)
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
static int get_exec_path (char *exec_path, const size_t exec_path_sz)
|
||||
@ -45,8 +48,6 @@ static int get_exec_path (char *exec_path, const size_t exec_path_sz)
|
||||
|
||||
#elif defined (__FreeBSD__)
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
int mib[4];
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
@ -60,6 +61,21 @@ static int get_exec_path (char *exec_path, const size_t exec_path_sz)
|
||||
|
||||
const size_t len = strlen (exec_path);
|
||||
|
||||
#elif defined (__NetBSD__)
|
||||
|
||||
int mib[4];
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC_ARGS;
|
||||
mib[2] = getpid();
|
||||
mib[3] = KERN_PROC_PATHNAME;
|
||||
|
||||
size_t size = exec_path_sz;
|
||||
|
||||
sysctl (mib, 4, exec_path, &size, NULL, 0);
|
||||
|
||||
const size_t len = strlen (exec_path);
|
||||
|
||||
#else
|
||||
#error Your Operating System is not supported or detected
|
||||
#endif
|
||||
|
@ -439,7 +439,7 @@ void SetConsoleWindowSize (const int x)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (__linux__) || defined (__CYGWIN__)
|
||||
#if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__linux__) || defined (__CYGWIN__)
|
||||
static struct termios savemodes;
|
||||
static int havemodes = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user