hashcat: partially fix the build for NetBSD
authorPierre Pronchery <khorben@defora.org>
Wed, 5 Jan 2022 22:36:31 +0000 (23:36 +0100)
committerPierre Pronchery <khorben@defora.org>
Wed, 5 Jan 2022 22:36:54 +0000 (23:36 +0100)
hashcat/distinfo
hashcat/patches/patch-src_affinity.c

index 422863960ad80fd8e314da0cf49a4e84e7a2da21..02ab4c93c5eed69ed006f6468ae0e335842a5d37 100644 (file)
@@ -5,5 +5,5 @@ SHA512 (hashcat-6.2.5.tar.gz) = 2b881146c625172c91cb74b33851473155dcde2421fba1b4
 Size (hashcat-6.2.5.tar.gz) = 6341872 bytes
 SHA1 (patch-include_sort__r.h) = 710a6866d1f1b0ba4c499e07897cdaaed5d2f2cb
 SHA1 (patch-src_Makefile) = 2781200f402b5cebaded0cce72023d6e1cda7ef9
-SHA1 (patch-src_affinity.c) = 83621bdd3f9a891cc80ef4a864c14864e917d6d8
+SHA1 (patch-src_affinity.c) = 6054fea2478244292bd855bb8eb8d064aa0d81d1
 SHA1 (patch-src_folder.c) = 9db8506a5fa6aaceb05acb772ab4a58d8f3cac57
index 2a9a18f327ca49356d7143d76fe8983989403abe..736e40baf480c3f2650efbed91fd04731beecff8 100644 (file)
@@ -1,18 +1,90 @@
 $NetBSD$
 
-Tentatively fix the build for NetBSD
+Fix the build for NetBSD
 
 --- src/affinity.c.orig        2022-01-05 22:06:04.906472892 +0000
 +++ src/affinity.c
-@@ -45,6 +45,11 @@ static int pthread_setaffinity_np (pthre
+@@ -45,6 +45,12 @@ static int pthread_setaffinity_np (pthre
  typedef cpuset_t cpu_set_t;
  #endif
  
 +#if defined(__NetBSD__)
-+#include <sys/intrio.h>
++#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__)
+@@ -57,6 +63,10 @@ int set_cpu_affinity (MAYBE_UNUSED hashc
+   #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();
+   #else
+   cpu_set_t cpuset;
+   const int cpu_id_max = 8 * sizeof (cpuset);
+@@ -79,6 +89,9 @@ int set_cpu_affinity (MAYBE_UNUSED hashc
+     {
+       #if defined (_WIN)
+       aff_mask = 0;
++      #elif defined (__NetBSD__)
++      cpuset_destroy (cpuset);
++      cpuset = cpuset_create ();
+       #else
+       CPU_ZERO (&cpuset);
+       #endif
+@@ -90,6 +103,10 @@ int set_cpu_affinity (MAYBE_UNUSED hashc
+     {
+       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 +114,18 @@ int set_cpu_affinity (MAYBE_UNUSED hashc
+     #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 +137,19 @@ int set_cpu_affinity (MAYBE_UNUSED hashc
+     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 ();