Fix linux build.

This commit is contained in:
XMRig 2017-06-14 16:11:01 +03:00
parent 8ebb659cd6
commit 5af169fd7b
11 changed files with 220 additions and 3 deletions

View file

@ -1,5 +1,5 @@
find_path(UV_INCLUDE_DIR NAMES uv.h)
find_library(UV_LIBRARY NAMES libuv)
find_library(UV_LIBRARY NAMES uv libuv)
set(UV_LIBRARIES ${UV_LIBRARY})
set(UV_INCLUDE_DIRS ${UV_INCLUDE_DIR})

View file

@ -22,6 +22,7 @@
*/
#include <stdlib.h>
#include <uv.h>
@ -92,6 +93,8 @@ int App::exec()
free(m_network);
free(m_options);
Mem::release();
return r;
}

66
src/App_unix.cpp Normal file
View file

@ -0,0 +1,66 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include "App.h"
#include "Console.h"
#include "Cpu.h"
#include "Options.h"
void App::background()
{
if (m_options->affinity() != -1L) {
Cpu::setAffinity(-1, m_options->affinity());
}
if (!m_options->background()) {
return;
}
int i = fork();
if (i < 0) {
exit(1);
}
if (i > 0) {
exit(0);
}
i = setsid();
if (i < 0) {
LOG_ERR("setsid() failed (errno = %d)", errno);
}
i = chdir("/");
if (i < 0) {
LOG_ERR("chdir() failed (errno = %d)", errno);
}
}

View file

@ -23,9 +23,13 @@
#include <malloc.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef WIN32
# include <winsock2.h>
# include "3rdparty/winansi.h"

View file

@ -22,3 +22,38 @@
*/
#include <pthread.h>
#include <sched.h>
#include <unistd.h>
#include "Cpu.h"
void Cpu::init()
{
# ifdef XMRIG_NO_LIBCPUID
m_totalThreads = sysconf(_SC_NPROCESSORS_CONF);
# endif
initCommon();
}
void Cpu::setAffinity(int id, unsigned long mask)
{
cpu_set_t set;
CPU_ZERO(&set);
for (int i = 0; i < m_totalThreads; i++) {
if (mask & (1UL << i)) {
CPU_SET(i, &set);
}
}
if (id == -1) {
sched_setaffinity(0, sizeof(&set), &set);
} else {
pthread_setaffinity_np(pthread_self(), sizeof(&set), &set);
}
}

View file

@ -22,5 +22,61 @@
*/
#include <stdlib.h>
#include <mm_malloc.h>
#include <sys/mman.h>
#include "crypto/CryptoNight.h"
#include "Mem.h"
#include "Options.h"
#include "Console.h"
bool Mem::allocate(int algo, int threads, bool doubleHash)
{
m_algo = algo;
m_threads = threads;
m_doubleHash = doubleHash;
const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
const size_t size = MEMORY * (threads * ratio + 1);
m_flags |= HugepagesAvailable;
m_memory = static_cast<uint8_t*>(mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0));
if (m_memory == MAP_FAILED) {
m_memory = static_cast<uint8_t*>(_mm_malloc(size, 16));
return true;
}
m_flags |= HugepagesEnabled;
if (madvise(m_memory, size, MADV_RANDOM | MADV_WILLNEED) != 0) {
LOG_ERR("madvise failed");
}
if (mlock(m_memory, size) == 0) {
m_flags |= Lock;
}
return true;
}
void Mem::release()
{
const int size = MEMORY * (m_threads + 1);
if (m_flags & HugepagesEnabled) {
if (m_flags & Lock) {
munlock(m_memory, size);
}
munmap(m_memory, size);
}
else {
_mm_free(m_memory);
}
}

View file

@ -22,8 +22,9 @@
*/
#include <uv.h>
#include <jansson.h>
#include <string.h>
#include <uv.h>
#ifdef _MSC_VER

View file

@ -25,6 +25,7 @@
#define __CRYPTONIGHT_H__
#include <stddef.h>
#include <stdint.h>

View file

@ -25,6 +25,7 @@
#define __JOBRESULT_H__
#include <memory.h>
#include <stdint.h>

50
src/net/Network_unix.cpp Normal file
View file

@ -0,0 +1,50 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include "net/Network.h"
#include "version.h"
char *Network::userAgent()
{
const size_t max = 128;
char *buf = static_cast<char*>(malloc(max));
int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION);
# if defined(__x86_64__)
length += snprintf(buf + length, max - length, "x86_64) libuv/%s", uv_version_string());
# else
length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string());
# endif
# ifdef __GNUC__
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# endif
return buf;
}

View file

@ -64,7 +64,7 @@ char *Network::userAgent()
# ifdef __GNUC__
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#elif _MSC_VER
# elif _MSC_VER
length += snprintf(buf + length, max - length, " msvc/%d", MSVC_VERSION);
# endif