mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
fix macos...
This commit is contained in:
parent
65607fc727
commit
b6d826410d
2 changed files with 66 additions and 8 deletions
|
@ -26,6 +26,9 @@
|
||||||
#include "comms.h"
|
#include "comms.h"
|
||||||
#include "util_posix.h" // msleep
|
#include "util_posix.h" // msleep
|
||||||
|
|
||||||
|
#if defined(__MACH__) && defined(__APPLE__)
|
||||||
|
# include "pthread_spin_lock_shim.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MAX_PM3_INPUT_ARGS_LENGTH 4096
|
#define MAX_PM3_INPUT_ARGS_LENGTH 4096
|
||||||
|
|
||||||
|
@ -220,14 +223,16 @@ void CmdsHelp(const command_t Commands[]) {
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_spinlock_t sycmd_spinlock;
|
|
||||||
|
|
||||||
static int execute_system_command(const char *command) {
|
static int execute_system_command(const char *command) {
|
||||||
|
|
||||||
|
pthread_spinlock_t sycmd_spinlock;
|
||||||
|
pthread_spin_init(&sycmd_spinlock, 0);
|
||||||
|
pthread_spin_lock(&sycmd_spinlock);
|
||||||
|
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
pthread_spin_lock(&sycmd_spinlock);
|
#if defined(_WIN32)
|
||||||
#if defined(_WIN32)
|
|
||||||
char wrapped_command[255];
|
char wrapped_command[255];
|
||||||
strncat(wrapped_command, "cmd /C \"", 9);
|
strncat(wrapped_command, "cmd /C \"", 9);
|
||||||
strncat(wrapped_command, command, strlen(command));
|
strncat(wrapped_command, command, strlen(command));
|
||||||
|
@ -238,6 +243,7 @@ static int execute_system_command(const char *command) {
|
||||||
ret = system(command);
|
ret = system(command);
|
||||||
#endif
|
#endif
|
||||||
pthread_spin_unlock(&sycmd_spinlock);
|
pthread_spin_unlock(&sycmd_spinlock);
|
||||||
|
pthread_spin_destroy(&sycmd_spinlock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,10 +297,7 @@ int CmdsParse(const command_t Commands[], const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Cmd[0] == '!') {
|
if (Cmd[0] == '!') {
|
||||||
pthread_spin_init(&sycmd_spinlock, 0);
|
return execute_system_command(Cmd + 1);
|
||||||
int res = execute_system_command(Cmd + 1);
|
|
||||||
pthread_spin_destroy(&sycmd_spinlock);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char cmd_name[128] = {0};
|
char cmd_name[128] = {0};
|
||||||
|
|
55
client/src/pthread_spin_lock_shim.h
Normal file
55
client/src/pthread_spin_lock_shim.h
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
Required imports:
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PTHREAD_SPIN_LOCK_SHIM
|
||||||
|
#define PTHREAD_SPIN_LOCK_SHIM
|
||||||
|
|
||||||
|
typedef int pthread_spinlock_t;
|
||||||
|
|
||||||
|
#ifndef PTHREAD_PROCESS_SHARED
|
||||||
|
# define PTHREAD_PROCESS_SHARED 1
|
||||||
|
#endif
|
||||||
|
#ifndef PTHREAD_PROCESS_PRIVATE
|
||||||
|
# define PTHREAD_PROCESS_PRIVATE 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static inline int pthread_spin_init(pthread_spinlock_t *lock, int pshared) {
|
||||||
|
__asm__ __volatile__ ("" ::: "memory");
|
||||||
|
*lock = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int pthread_spin_destroy(pthread_spinlock_t *lock) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int pthread_spin_lock(pthread_spinlock_t *lock) {
|
||||||
|
while (1) {
|
||||||
|
int i;
|
||||||
|
for (i=0; i < 10000; i++) {
|
||||||
|
if (__sync_bool_compare_and_swap(lock, 0, 1)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sched_yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int pthread_spin_trylock(pthread_spinlock_t *lock) {
|
||||||
|
if (__sync_bool_compare_and_swap(lock, 0, 1)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return EBUSY;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int pthread_spin_unlock(pthread_spinlock_t *lock) {
|
||||||
|
__asm__ __volatile__ ("" ::: "memory");
|
||||||
|
*lock = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue