mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2026-04-21 06:19:25 +03:00
v4.10-9505-beta
This commit is contained in:
+39
-1
@@ -258,9 +258,27 @@ CFG_RW *NewCfgRwEx(FOLDER **root, char *cfg_name, bool dont_backup)
|
||||
return ret;
|
||||
}
|
||||
CFG_RW *NewCfgRwExW(FOLDER **root, wchar_t *cfg_name, bool dont_backup)
|
||||
{
|
||||
return NewCfgRwEx2W(root, cfg_name, dont_backup, NULL);
|
||||
}
|
||||
CFG_RW *NewCfgRwEx2A(FOLDER **root, char *cfg_name_a, bool dont_backup, char *template_name_a)
|
||||
{
|
||||
CFG_RW *ret;
|
||||
wchar_t *cfg_name_w = CopyStrToUni(cfg_name_a);
|
||||
wchar_t *template_name_w = CopyStrToUni(template_name_a);
|
||||
|
||||
ret = NewCfgRwEx2W(root, cfg_name_w, dont_backup, template_name_w);
|
||||
|
||||
Free(cfg_name_w);
|
||||
Free(template_name_w);
|
||||
|
||||
return ret;
|
||||
}
|
||||
CFG_RW *NewCfgRwEx2W(FOLDER **root, wchar_t *cfg_name, bool dont_backup, wchar_t *template_name)
|
||||
{
|
||||
CFG_RW *rw;
|
||||
FOLDER *f;
|
||||
bool loaded_from_template = false;
|
||||
// Validate arguments
|
||||
if (cfg_name == NULL || root == NULL)
|
||||
{
|
||||
@@ -270,6 +288,18 @@ CFG_RW *NewCfgRwExW(FOLDER **root, wchar_t *cfg_name, bool dont_backup)
|
||||
f = CfgReadW(cfg_name);
|
||||
if (f == NULL)
|
||||
{
|
||||
// Load from template
|
||||
if (UniIsEmptyStr(template_name) == false)
|
||||
{
|
||||
f = CfgReadW(template_name);
|
||||
if (f != NULL)
|
||||
{
|
||||
loaded_from_template = true;
|
||||
|
||||
goto LABEL_CONTIUNE;
|
||||
}
|
||||
}
|
||||
|
||||
rw = ZeroMalloc(sizeof(CFG_RW));
|
||||
rw->lock = NewLock();
|
||||
rw->FileNameW = CopyUniStr(cfg_name);
|
||||
@@ -281,10 +311,18 @@ CFG_RW *NewCfgRwExW(FOLDER **root, wchar_t *cfg_name, bool dont_backup)
|
||||
return rw;
|
||||
}
|
||||
|
||||
LABEL_CONTIUNE:
|
||||
rw = ZeroMalloc(sizeof(CFG_RW));
|
||||
rw->FileNameW = CopyUniStr(cfg_name);
|
||||
rw->FileName = CopyUniToStr(cfg_name);
|
||||
rw->Io = FileOpenW(cfg_name, false);
|
||||
if (loaded_from_template == false)
|
||||
{
|
||||
rw->Io = FileOpenW(cfg_name, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
rw->Io = FileCreateW(cfg_name);
|
||||
}
|
||||
rw->lock = NewLock();
|
||||
|
||||
*root = f;
|
||||
|
||||
@@ -252,6 +252,8 @@ CFG_RW *NewCfgRw(FOLDER **root, char *cfg_name);
|
||||
CFG_RW *NewCfgRwW(FOLDER **root, wchar_t *cfg_name);
|
||||
CFG_RW *NewCfgRwEx(FOLDER **root, char *cfg_name, bool dont_backup);
|
||||
CFG_RW *NewCfgRwExW(FOLDER **root, wchar_t *cfg_name, bool dont_backup);
|
||||
CFG_RW *NewCfgRwEx2W(FOLDER **root, wchar_t *cfg_name, bool dont_backup, wchar_t *template_name);
|
||||
CFG_RW *NewCfgRwEx2A(FOLDER **root, char *cfg_name_a, bool dont_backup, char *template_name_a);
|
||||
UINT SaveCfgRw(CFG_RW *rw, FOLDER *f);
|
||||
UINT SaveCfgRwEx(CFG_RW *rw, FOLDER *f, UINT revision_number);
|
||||
void FreeCfgRw(CFG_RW *rw);
|
||||
|
||||
+116
-1
@@ -1805,6 +1805,77 @@ X *NewRootX(K *pub, K *priv, NAME *name, UINT days, X_SERIAL *serial)
|
||||
return x2;
|
||||
}
|
||||
|
||||
// Create new X509 basic & extended key usage
|
||||
void AddKeyUsageX509(EXTENDED_KEY_USAGE *ex, int nid)
|
||||
{
|
||||
ASN1_OBJECT *obj;
|
||||
// Validate arguments
|
||||
if (ex == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
obj = OBJ_nid2obj(nid);
|
||||
if (obj != NULL)
|
||||
{
|
||||
sk_ASN1_OBJECT_push(ex, obj);
|
||||
}
|
||||
}
|
||||
X509_EXTENSION *NewExtendedKeyUsageForX509()
|
||||
{
|
||||
EXTENDED_KEY_USAGE *ex = sk_ASN1_OBJECT_new_null();
|
||||
X509_EXTENSION *ret;
|
||||
|
||||
AddKeyUsageX509(ex, NID_server_auth);
|
||||
AddKeyUsageX509(ex, NID_client_auth);
|
||||
AddKeyUsageX509(ex, NID_code_sign);
|
||||
AddKeyUsageX509(ex, NID_email_protect);
|
||||
AddKeyUsageX509(ex, NID_ipsecEndSystem);
|
||||
AddKeyUsageX509(ex, NID_ipsecTunnel);
|
||||
AddKeyUsageX509(ex, NID_ipsecUser);
|
||||
AddKeyUsageX509(ex, NID_time_stamp);
|
||||
AddKeyUsageX509(ex, NID_OCSP_sign);
|
||||
|
||||
ret = X509V3_EXT_i2d(NID_ext_key_usage, 0, ex);
|
||||
|
||||
sk_ASN1_OBJECT_pop_free(ex, ASN1_OBJECT_free);
|
||||
|
||||
return ret;
|
||||
}
|
||||
void BitStringSetBit(ASN1_BIT_STRING *str, int bit)
|
||||
{
|
||||
// Validate arguments
|
||||
if (str == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ASN1_BIT_STRING_set_bit(str, bit, 1);
|
||||
}
|
||||
X509_EXTENSION *NewBasicKeyUsageForX509()
|
||||
{
|
||||
X509_EXTENSION *ret = NULL;
|
||||
ASN1_BIT_STRING *str;
|
||||
|
||||
str = ASN1_BIT_STRING_new();
|
||||
if (str != NULL)
|
||||
{
|
||||
BitStringSetBit(str, 0); // KU_DIGITAL_SIGNATURE
|
||||
BitStringSetBit(str, 1); // KU_NON_REPUDIATION
|
||||
BitStringSetBit(str, 2); // KU_KEY_ENCIPHERMENT
|
||||
BitStringSetBit(str, 3); // KU_DATA_ENCIPHERMENT
|
||||
//BitStringSetBit(str, 4); // KU_KEY_AGREEMENT
|
||||
BitStringSetBit(str, 5); // KU_KEY_CERT_SIGN
|
||||
BitStringSetBit(str, 6); // KU_CRL_SIGN
|
||||
|
||||
ret = X509V3_EXT_i2d(NID_key_usage, 0, str);
|
||||
|
||||
ASN1_BIT_STRING_free(str);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Issue an X509 certificate
|
||||
X509 *NewX509(K *pub, K *priv, X *ca, NAME *name, UINT days, X_SERIAL *serial)
|
||||
{
|
||||
@@ -1812,6 +1883,9 @@ X509 *NewX509(K *pub, K *priv, X *ca, NAME *name, UINT days, X_SERIAL *serial)
|
||||
UINT64 notBefore, notAfter;
|
||||
ASN1_TIME *t1, *t2;
|
||||
X509_NAME *subject_name, *issuer_name;
|
||||
X509_EXTENSION *ex = NULL;
|
||||
X509_EXTENSION *eku = NULL;
|
||||
X509_EXTENSION *busage = NULL;
|
||||
// Validate arguments
|
||||
if (pub == NULL || name == NULL || ca == NULL)
|
||||
{
|
||||
@@ -1892,6 +1966,29 @@ X509 *NewX509(K *pub, K *priv, X *ca, NAME *name, UINT days, X_SERIAL *serial)
|
||||
s->length = serial->size;
|
||||
}
|
||||
|
||||
/*
|
||||
// Extensions
|
||||
ex = X509V3_EXT_conf_nid(NULL, NULL, NID_basic_constraints, "critical,CA:TRUE");
|
||||
X509_add_ext(x509, ex, -1);
|
||||
X509_EXTENSION_free(ex);
|
||||
*/
|
||||
|
||||
// Basic usage
|
||||
busage = NewBasicKeyUsageForX509();
|
||||
if (busage != NULL)
|
||||
{
|
||||
X509_add_ext(x509, busage, -1);
|
||||
X509_EXTENSION_free(busage);
|
||||
}
|
||||
|
||||
// EKU
|
||||
eku = NewExtendedKeyUsageForX509();
|
||||
if (eku != NULL)
|
||||
{
|
||||
X509_add_ext(x509, eku, -1);
|
||||
X509_EXTENSION_free(eku);
|
||||
}
|
||||
|
||||
Lock(openssl_lock);
|
||||
{
|
||||
// Set the public key
|
||||
@@ -1914,6 +2011,8 @@ X509 *NewRootX509(K *pub, K *priv, NAME *name, UINT days, X_SERIAL *serial)
|
||||
ASN1_TIME *t1, *t2;
|
||||
X509_NAME *subject_name, *issuer_name;
|
||||
X509_EXTENSION *ex = NULL;
|
||||
X509_EXTENSION *eku = NULL;
|
||||
X509_EXTENSION *busage = NULL;
|
||||
// Validate arguments
|
||||
if (pub == NULL || name == NULL || priv == NULL)
|
||||
{
|
||||
@@ -2004,6 +2103,22 @@ X509 *NewRootX509(K *pub, K *priv, NAME *name, UINT days, X_SERIAL *serial)
|
||||
X509_add_ext(x509, ex, -1);
|
||||
X509_EXTENSION_free(ex);
|
||||
|
||||
// Basic usage
|
||||
busage = NewBasicKeyUsageForX509();
|
||||
if (busage != NULL)
|
||||
{
|
||||
X509_add_ext(x509, busage, -1);
|
||||
X509_EXTENSION_free(busage);
|
||||
}
|
||||
|
||||
// EKU
|
||||
eku = NewExtendedKeyUsageForX509();
|
||||
if (eku != NULL)
|
||||
{
|
||||
X509_add_ext(x509, eku, -1);
|
||||
X509_EXTENSION_free(eku);
|
||||
}
|
||||
|
||||
Lock(openssl_lock);
|
||||
{
|
||||
// Set the public key
|
||||
@@ -4105,7 +4220,7 @@ CRYPT *NewCrypt(void *key, UINT size)
|
||||
{
|
||||
CRYPT *c = ZeroMalloc(sizeof(CRYPT));
|
||||
|
||||
c->Rc4Key = ZeroMalloc(sizeof(struct rc4_key_st));
|
||||
c->Rc4Key = Malloc(sizeof(struct rc4_key_st));
|
||||
|
||||
RC4_set_key(c->Rc4Key, size, (UCHAR *)key);
|
||||
|
||||
|
||||
@@ -3025,6 +3025,83 @@ wchar_t *UniReplaceFormatStringFor64(wchar_t *fmt)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Get lines from a string
|
||||
UNI_TOKEN_LIST *UniGetLines(wchar_t *str)
|
||||
{
|
||||
UINT i, len;
|
||||
BUF *b = NULL;
|
||||
LIST *o;
|
||||
UNI_TOKEN_LIST *ret;
|
||||
// Validate arguments
|
||||
if (str == NULL)
|
||||
{
|
||||
return UniNullToken();
|
||||
}
|
||||
|
||||
o = NewListFast(NULL);
|
||||
|
||||
len = UniStrLen(str);
|
||||
|
||||
b = NewBuf();
|
||||
|
||||
for (i = 0;i < len;i++)
|
||||
{
|
||||
wchar_t c = str[i];
|
||||
bool f = false;
|
||||
|
||||
if (c == L'\r')
|
||||
{
|
||||
if (str[i + 1] == L'\n')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
f = true;
|
||||
}
|
||||
else if (c == L'\n')
|
||||
{
|
||||
f = true;
|
||||
}
|
||||
|
||||
if (f)
|
||||
{
|
||||
wchar_t zero = 0;
|
||||
wchar_t *s;
|
||||
WriteBuf(b, &zero, sizeof(wchar_t));
|
||||
|
||||
s = (wchar_t *)b->Buf;
|
||||
|
||||
Add(o, UniCopyStr(s));
|
||||
|
||||
ClearBuf(b);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteBuf(b, &c, sizeof(wchar_t));
|
||||
}
|
||||
}
|
||||
|
||||
if (true)
|
||||
{
|
||||
wchar_t zero = 0;
|
||||
wchar_t *s;
|
||||
WriteBuf(b, &zero, sizeof(wchar_t));
|
||||
|
||||
s = (wchar_t *)b->Buf;
|
||||
|
||||
Add(o, UniCopyStr(s));
|
||||
|
||||
ClearBuf(b);
|
||||
}
|
||||
|
||||
FreeBuf(b);
|
||||
|
||||
ret = UniListToTokenList(o);
|
||||
|
||||
UniFreeStrList(o);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Display the string on the screen
|
||||
void UniPrintStr(wchar_t *string)
|
||||
{
|
||||
|
||||
@@ -232,6 +232,7 @@ bool UniInStr(wchar_t *str, wchar_t *keyword);
|
||||
bool UniInStrEx(wchar_t *str, wchar_t *keyword, bool case_sensitive);
|
||||
void ClearUniStr(wchar_t *str, UINT str_size);
|
||||
bool UniInChar(wchar_t *string, wchar_t c);
|
||||
UNI_TOKEN_LIST *UniGetLines(wchar_t *str);
|
||||
|
||||
#ifdef OS_UNIX
|
||||
void GetCurrentCharSet(char *name, UINT size);
|
||||
|
||||
@@ -319,6 +319,21 @@ void MainteThreadList(LIST *o)
|
||||
UnlockList(o);
|
||||
}
|
||||
|
||||
// Wait until all threads in the thread list will be stopped
|
||||
void WaitAllThreadsWillBeStopped(LIST *o)
|
||||
{
|
||||
// Validate arguments
|
||||
if (o == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (LIST_NUM(o) != 0)
|
||||
{
|
||||
SleepThread(100);
|
||||
}
|
||||
}
|
||||
|
||||
// Stop all the threads in the thread list
|
||||
void StopThreadList(LIST *o)
|
||||
{
|
||||
@@ -1934,8 +1949,14 @@ INT64 GetTimeDiffEx(SYSTEMTIME *basetime, bool local_time)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef OS_UNIX
|
||||
Copy(&t1, localtime(&tmp), sizeof(struct tm));
|
||||
Copy(&t2, gmtime(&tmp), sizeof(struct tm));
|
||||
#else // OS_UNIX
|
||||
localtime_r(&tmp, &t1);
|
||||
gmtime_r(&tmp, &t2);
|
||||
#endif // OS_UNIX
|
||||
|
||||
TmToSystem(&s1, &t1);
|
||||
TmToSystem(&s2, &t2);
|
||||
|
||||
@@ -1970,8 +1991,14 @@ INT64 GetTimeDiff()
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef OS_UNIX
|
||||
Copy(&t1, localtime(&tmp), sizeof(struct tm));
|
||||
Copy(&t2, gmtime(&tmp), sizeof(struct tm));
|
||||
#else // OS_UNIX
|
||||
localtime_r(&tmp, &t1);
|
||||
gmtime_r(&tmp, &t2);
|
||||
#endif // OS_UNIX
|
||||
|
||||
TmToSystem(&s1, &t1);
|
||||
TmToSystem(&s2, &t2);
|
||||
|
||||
|
||||
@@ -275,6 +275,7 @@ void DelThreadFromThreadList(LIST *o, THREAD *t);
|
||||
void MainteThreadList(LIST *o);
|
||||
void FreeThreadList(LIST *o);
|
||||
void StopThreadList(LIST *o);
|
||||
void WaitAllThreadsWillBeStopped(LIST *o);
|
||||
|
||||
#endif // KERNEL_H
|
||||
|
||||
|
||||
@@ -344,8 +344,10 @@ typedef UINT_PTR SOCKET;
|
||||
#define OSTYPE_WINDOWS_SERVER_8 2710 // Windows Server 2012
|
||||
#define OSTYPE_WINDOWS_81 2701 // Windows 8.1
|
||||
#define OSTYPE_WINDOWS_SERVER_81 2711 // Windows Server 2012 R2
|
||||
#define OSTYPE_WINDOWS_9 2800 // Windows 9
|
||||
#define OSTYPE_WINDOWS_SERVER_9 2810 // Windows Server 9
|
||||
#define OSTYPE_WINDOWS_10 2702 // Windows 10
|
||||
#define OSTYPE_WINDOWS_SERVER_10 2712 // Windows Server 10
|
||||
#define OSTYPE_WINDOWS_11 2800 // Windows 11 or later
|
||||
#define OSTYPE_WINDOWS_SERVER_11 2810 // Windows Server 11 or later
|
||||
#define OSTYPE_UNIX_UNKNOWN 3000 // Unknown UNIX
|
||||
#define OSTYPE_LINUX 3100 // Linux
|
||||
#define OSTYPE_SOLARIS 3200 // Solaris
|
||||
|
||||
@@ -218,6 +218,13 @@ int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, char *CmdLine, int CmdShow)
|
||||
#define USE_INTEL_AESNI_LIBRARY
|
||||
#endif
|
||||
|
||||
// Determine the performance / memory strategy
|
||||
#if (defined(CPU_X86) || defined(CPU_X64) || defined(CPU_X86_X64) || defined(CPU_SPARC) || defined(CPU_SPARC64) || defined(OS_WIN32) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(i386) || defined(__i386) || defined(__i386__) || defined(__ia64__) || defined(__IA64__) || defined(_IA64))
|
||||
#define USE_STRATEGY_PERFORMACE
|
||||
#else
|
||||
#define USE_STRATEGY_LOW_MEMORY
|
||||
#endif
|
||||
|
||||
// Macro that displays the current time
|
||||
#ifdef WIN32
|
||||
#define WHEN if (IsDebug()){WHERE; MsPrintTick();}
|
||||
|
||||
+110
-47
@@ -129,11 +129,60 @@
|
||||
|
||||
#define FIFO_INIT_MEM_SIZE 4096
|
||||
#define FIFO_REALLOC_MEM_SIZE (65536 * 10) // Exquisite value
|
||||
#define FIFO_REALLOC_MEM_SIZE_SMALL 65536
|
||||
|
||||
#define INIT_NUM_RESERVED 32
|
||||
|
||||
static UINT fifo_default_realloc_mem_size = FIFO_REALLOC_MEM_SIZE;
|
||||
static UINT fifo_current_realloc_mem_size = FIFO_REALLOC_MEM_SIZE;
|
||||
|
||||
// Check whether the specified key item is in the hash list
|
||||
bool IsInHashListKey(HASH_LIST *h, UINT key)
|
||||
{
|
||||
// Validate arguments
|
||||
if (h == NULL || key == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HashListKeyToPointer(h, key) == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search the item in the hash list with the key
|
||||
void *HashListKeyToPointer(HASH_LIST *h, UINT key)
|
||||
{
|
||||
UINT num, i;
|
||||
void **pp;
|
||||
void *ret = NULL;
|
||||
// Validate arguments
|
||||
if (h == NULL || key == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pp = HashListToArray(h, &num);
|
||||
if (pp == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0;i < num;i++)
|
||||
{
|
||||
void *p = pp[i];
|
||||
|
||||
if (POINTER_TO_KEY(p) == key)
|
||||
{
|
||||
ret = p;
|
||||
}
|
||||
}
|
||||
|
||||
Free(pp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Lock the hash list
|
||||
void LockHashList(HASH_LIST *h)
|
||||
@@ -223,17 +272,11 @@ void *SearchHash(HASH_LIST *h, void *t)
|
||||
if (h->Entries[r] != NULL)
|
||||
{
|
||||
LIST *o = h->Entries[r];
|
||||
UINT i;
|
||||
void *r = Search(o, t);
|
||||
|
||||
for (i = 0;i < LIST_NUM(o);i++)
|
||||
if (r != NULL)
|
||||
{
|
||||
void *p = LIST_DATA(o, i);
|
||||
|
||||
if (h->CompareProc(&p, &t) == 0)
|
||||
{
|
||||
ret = p;
|
||||
break;
|
||||
}
|
||||
ret = r;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,10 +336,10 @@ void AddHash(HASH_LIST *h, void *p)
|
||||
|
||||
if (h->Entries[r] == NULL)
|
||||
{
|
||||
h->Entries[r] = NewListFast(NULL);
|
||||
h->Entries[r] = NewListFast(h->CompareProc);
|
||||
}
|
||||
|
||||
Add(h->Entries[r], p);
|
||||
Insert(h->Entries[r], p);
|
||||
|
||||
if (h->AllList != NULL)
|
||||
{
|
||||
@@ -1031,6 +1074,18 @@ void *PeekQueue(QUEUE *q)
|
||||
return p;
|
||||
}
|
||||
|
||||
// Get the number of queued items
|
||||
UINT GetQueueNum(QUEUE *q)
|
||||
{
|
||||
// Validate arguments
|
||||
if (q == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return q->num_item;
|
||||
}
|
||||
|
||||
// Get one
|
||||
void *GetNext(QUEUE *q)
|
||||
{
|
||||
@@ -1105,6 +1160,21 @@ void InsertQueue(QUEUE *q, void *p)
|
||||
|
||||
q->num_item++;
|
||||
|
||||
/*{
|
||||
static UINT max_num_item;
|
||||
static UINT64 next_tick = 0;
|
||||
UINT64 now = Tick64();
|
||||
|
||||
max_num_item = MAX(q->num_item, max_num_item);
|
||||
|
||||
if (next_tick == 0 || next_tick <= now)
|
||||
{
|
||||
next_tick = now + (UINT64)1000;
|
||||
|
||||
printf("max_queue = %u\n", max_num_item);
|
||||
}
|
||||
}*/
|
||||
|
||||
// KS
|
||||
KS_INC(KS_INSERT_QUEUE_COUNT);
|
||||
}
|
||||
@@ -2327,9 +2397,26 @@ UINT ReadFifo(FIFO *f, void *p, UINT size)
|
||||
f->pos = 0;
|
||||
}
|
||||
|
||||
ShrinkFifoMemory(f);
|
||||
|
||||
// KS
|
||||
KS_INC(KS_READ_FIFO_COUNT);
|
||||
|
||||
return read_size;
|
||||
}
|
||||
|
||||
// Rearrange the memory
|
||||
void ShrinkFifoMemory(FIFO *f)
|
||||
{
|
||||
// Validate arguments
|
||||
if (f == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Rearrange the memory
|
||||
if (f->pos >= FIFO_INIT_MEM_SIZE &&
|
||||
f->memsize >= f->realloc_mem_size &&
|
||||
if (f->pos >= FIFO_INIT_MEM_SIZE &&
|
||||
f->memsize >= fifo_current_realloc_mem_size &&
|
||||
(f->memsize / 2) > f->size)
|
||||
{
|
||||
void *new_p;
|
||||
@@ -2345,11 +2432,6 @@ UINT ReadFifo(FIFO *f, void *p, UINT size)
|
||||
f->p = new_p;
|
||||
f->pos = 0;
|
||||
}
|
||||
|
||||
// KS
|
||||
KS_INC(KS_READ_FIFO_COUNT);
|
||||
|
||||
return read_size;
|
||||
}
|
||||
|
||||
// Write to the FIFO
|
||||
@@ -2497,19 +2579,19 @@ void CleanupFifo(FIFO *f)
|
||||
// Initialize the FIFO system
|
||||
void InitFifo()
|
||||
{
|
||||
fifo_default_realloc_mem_size = FIFO_REALLOC_MEM_SIZE;
|
||||
fifo_current_realloc_mem_size = FIFO_REALLOC_MEM_SIZE;
|
||||
}
|
||||
|
||||
// Create a FIFO
|
||||
FIFO *NewFifo()
|
||||
{
|
||||
return NewFifoEx(0, false);
|
||||
return NewFifoEx(false);
|
||||
}
|
||||
FIFO *NewFifoFast()
|
||||
{
|
||||
return NewFifoEx(0, true);
|
||||
return NewFifoEx(true);
|
||||
}
|
||||
FIFO *NewFifoEx(UINT realloc_mem_size, bool fast)
|
||||
FIFO *NewFifoEx(bool fast)
|
||||
{
|
||||
FIFO *f;
|
||||
|
||||
@@ -2531,13 +2613,6 @@ FIFO *NewFifoEx(UINT realloc_mem_size, bool fast)
|
||||
f->memsize = FIFO_INIT_MEM_SIZE;
|
||||
f->p = Malloc(FIFO_INIT_MEM_SIZE);
|
||||
|
||||
if (realloc_mem_size == 0)
|
||||
{
|
||||
realloc_mem_size = fifo_default_realloc_mem_size;
|
||||
}
|
||||
|
||||
f->realloc_mem_size = realloc_mem_size;
|
||||
|
||||
#ifndef DONT_USE_KERNEL_STATUS
|
||||
// TrackNewObj(POINTER_TO_UINT64(f), "FIFO", 0);
|
||||
#endif // DONT_USE_KERNEL_STATUS
|
||||
@@ -2549,20 +2624,20 @@ FIFO *NewFifoEx(UINT realloc_mem_size, bool fast)
|
||||
}
|
||||
|
||||
// Get the default memory reclaiming size of the FIFO
|
||||
UINT GetFifoDefaultReallocMemSize()
|
||||
UINT GetFifoCurrentReallocMemSize()
|
||||
{
|
||||
return fifo_default_realloc_mem_size;
|
||||
return fifo_current_realloc_mem_size;
|
||||
}
|
||||
|
||||
// Set the default memory reclaiming size of the FIFO
|
||||
void SetFifoDefaultReallocMemSize(UINT size)
|
||||
void SetFifoCurrentReallocMemSize(UINT size)
|
||||
{
|
||||
if (size == 0)
|
||||
{
|
||||
size = FIFO_REALLOC_MEM_SIZE;
|
||||
}
|
||||
|
||||
fifo_default_realloc_mem_size = size;
|
||||
fifo_current_realloc_mem_size = size;
|
||||
}
|
||||
|
||||
// Read a buffer from a file
|
||||
@@ -3743,12 +3818,6 @@ char B64_CharToCode(char c)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// High-speed Malloc (currently not implemented)
|
||||
void *MallocFast(UINT size)
|
||||
{
|
||||
return Malloc(size);
|
||||
}
|
||||
|
||||
// Malloc
|
||||
void *Malloc(UINT size)
|
||||
{
|
||||
@@ -3899,12 +3968,6 @@ void *ZeroMallocEx(UINT size, bool zero_clear_when_free)
|
||||
Zero(p, size);
|
||||
return p;
|
||||
}
|
||||
void *ZeroMallocFast(UINT size)
|
||||
{
|
||||
void *p = MallocFast(size);
|
||||
Zero(p, size);
|
||||
return p;
|
||||
}
|
||||
|
||||
// Memory allocation
|
||||
void *InternalMalloc(UINT size)
|
||||
|
||||
+12
-7
@@ -114,6 +114,10 @@
|
||||
#ifndef MEMORY_H
|
||||
#define MEMORY_H
|
||||
|
||||
// MallocFast (not implemented)
|
||||
#define MallocFast Malloc
|
||||
#define ZeroMallocFast ZeroMalloc
|
||||
|
||||
// Memory size that can be passed to the kernel at a time
|
||||
#define MAX_SEND_BUF_MEM_SIZE (10 * 1024 * 1024)
|
||||
|
||||
@@ -154,7 +158,6 @@ struct FIFO
|
||||
LOCK *lock;
|
||||
void *p;
|
||||
UINT pos, size, memsize;
|
||||
UINT realloc_mem_size;
|
||||
UINT64 total_read_size;
|
||||
UINT64 total_write_size;
|
||||
};
|
||||
@@ -214,7 +217,7 @@ struct SHARED_BUFFER
|
||||
// Macro
|
||||
#define LIST_DATA(o, i) (((o) != NULL) ? ((o)->p[(i)]) : NULL)
|
||||
#define LIST_NUM(o) (((o) != NULL) ? (o)->num_item : 0)
|
||||
|
||||
#define HASH_LIST_NUM(o) (((o) != NULL) ? (o)->NumItems : 0)
|
||||
|
||||
// Function pointer type to get a hash function
|
||||
typedef UINT (GET_HASH)(void *p);
|
||||
@@ -244,6 +247,8 @@ UINT CalcHashForHashList(HASH_LIST *h, void *p);
|
||||
void **HashListToArray(HASH_LIST *h, UINT *num);
|
||||
void LockHashList(HASH_LIST *h);
|
||||
void UnlockHashList(HASH_LIST *h);
|
||||
bool IsInHashListKey(HASH_LIST *h, UINT key);
|
||||
void *HashListKeyToPointer(HASH_LIST *h, UINT key);
|
||||
|
||||
LIST *NewCandidateList();
|
||||
void FreeCandidateList(LIST *o);
|
||||
@@ -254,9 +259,7 @@ LIST *BufToCandidate(BUF *b);
|
||||
|
||||
void *Malloc(UINT size);
|
||||
void *MallocEx(UINT size, bool zero_clear_when_free);
|
||||
void *MallocFast(UINT size);
|
||||
void *ZeroMalloc(UINT size);
|
||||
void *ZeroMallocFast(UINT size);
|
||||
void *ZeroMallocEx(UINT size, bool zero_clear_when_free);
|
||||
void *ReAlloc(void *addr, UINT size);
|
||||
void Free(void *addr);
|
||||
@@ -333,6 +336,7 @@ bool CompareBuf(BUF *b1, BUF *b2);
|
||||
|
||||
UINT PeekFifo(FIFO *f, void *p, UINT size);
|
||||
UINT ReadFifo(FIFO *f, void *p, UINT size);
|
||||
void ShrinkFifoMemory(FIFO *f);
|
||||
UCHAR *GetFifoPointer(FIFO *f);
|
||||
UCHAR *FifoPtr(FIFO *f);
|
||||
void WriteFifo(FIFO *f, void *p, UINT size);
|
||||
@@ -344,10 +348,10 @@ void ReleaseFifo(FIFO *f);
|
||||
void CleanupFifo(FIFO *f);
|
||||
FIFO *NewFifo();
|
||||
FIFO *NewFifoFast();
|
||||
FIFO *NewFifoEx(UINT realloc_mem_size, bool fast);
|
||||
FIFO *NewFifoEx(bool fast);
|
||||
void InitFifo();
|
||||
UINT GetFifoDefaultReallocMemSize();
|
||||
void SetFifoDefaultReallocMemSize(UINT size);
|
||||
UINT GetFifoCurrentReallocMemSize();
|
||||
void SetFifoCurrentReallocMemSize(UINT size);
|
||||
|
||||
void *Search(LIST *o, void *target);
|
||||
void Sort(LIST *o);
|
||||
@@ -416,6 +420,7 @@ void ReleaseQueue(QUEUE *q);
|
||||
void CleanupQueue(QUEUE *q);
|
||||
QUEUE *NewQueue();
|
||||
QUEUE *NewQueueFast();
|
||||
UINT GetQueueNum(QUEUE *q);
|
||||
|
||||
SK *NewSk();
|
||||
SK *NewSkEx(bool no_compact);
|
||||
|
||||
@@ -8729,6 +8729,35 @@ bool MsIsWindows7()
|
||||
return false;
|
||||
}
|
||||
|
||||
// Determine whether it's Windows 10 or later
|
||||
bool MsIsWindows10()
|
||||
{
|
||||
OS_INFO *info = GetOsInfo();
|
||||
|
||||
if (info == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OS_IS_WINDOWS_NT(info->OsType))
|
||||
{
|
||||
if (GET_KETA(info->OsType, 100) == 7)
|
||||
{
|
||||
if (GET_KETA(info->OsType, 1) >= 2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (GET_KETA(info->OsType, 100) >= 8)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Determine whether it's Windows 8.1 or later
|
||||
bool MsIsWindows81()
|
||||
{
|
||||
|
||||
@@ -995,6 +995,7 @@ bool MsIsIA64();
|
||||
void *MsDisableWow64FileSystemRedirection();
|
||||
void MsRestoreWow64FileSystemRedirection(void *p);
|
||||
void MsSetWow64FileSystemRedirectionEnable(bool enable);
|
||||
bool MsIsWindows10();
|
||||
bool MsIsWindows81();
|
||||
bool MsIsWindows8();
|
||||
bool MsIsWindows7();
|
||||
|
||||
+47
-20
@@ -4281,7 +4281,7 @@ void RUDPGetRegisterHostNameByIP(char *dst, UINT size, IP *ip)
|
||||
StrLower(tmp);
|
||||
Format(dst, size,
|
||||
(IsUseAlternativeHostname() ? UDP_NAT_T_SERVER_TAG_ALT : UDP_NAT_T_SERVER_TAG),
|
||||
tmp[0], tmp[1], tmp[2], tmp[3]);
|
||||
tmp[2], tmp[3]);
|
||||
|
||||
|
||||
if (false)
|
||||
@@ -9302,6 +9302,12 @@ void UnixInitAsyncSocket(SOCK *sock)
|
||||
{
|
||||
UnixSetSocketNonBlockingMode(sock->socket, true);
|
||||
}
|
||||
|
||||
if (sock->ssl != NULL && sock->ssl->s3 != NULL)
|
||||
{
|
||||
sock->Ssl_Init_Async_SendAlert[0] = sock->ssl->s3->send_alert[0];
|
||||
sock->Ssl_Init_Async_SendAlert[1] = sock->ssl->s3->send_alert[1];
|
||||
}
|
||||
}
|
||||
|
||||
// Initializing the socket library
|
||||
@@ -13139,6 +13145,15 @@ UINT SecureRecv(SOCK *sock, void *data, UINT size)
|
||||
e = SSL_get_error(ssl, ret);
|
||||
if (e == SSL_ERROR_WANT_READ || e == SSL_ERROR_WANT_WRITE || e == SSL_ERROR_SSL)
|
||||
{
|
||||
if (e == SSL_ERROR_SSL &&
|
||||
sock->ssl->s3->send_alert[0] == SSL3_AL_FATAL &&
|
||||
sock->ssl->s3->send_alert[0] != sock->Ssl_Init_Async_SendAlert[0] &&
|
||||
sock->ssl->s3->send_alert[1] != sock->Ssl_Init_Async_SendAlert[1])
|
||||
{
|
||||
Debug("%s %u SSL Fatal Error on ASYNC socket !!!\n", __FILE__, __LINE__);
|
||||
Disconnect(sock);
|
||||
return 0;
|
||||
}
|
||||
// Packet has not arrived yet, that is not to be read
|
||||
return SOCK_LATER;
|
||||
}
|
||||
@@ -13202,6 +13217,7 @@ UINT SecureRecv(SOCK *sock, void *data, UINT size)
|
||||
// Successful reception
|
||||
sock->RecvSize += (UINT64)ret;
|
||||
sock->RecvNum++;
|
||||
|
||||
return (UINT)ret;
|
||||
}
|
||||
if (ret == 0)
|
||||
@@ -13215,6 +13231,16 @@ UINT SecureRecv(SOCK *sock, void *data, UINT size)
|
||||
{
|
||||
if (e == SSL_ERROR_WANT_READ || e == SSL_ERROR_WANT_WRITE || e == SSL_ERROR_SSL)
|
||||
{
|
||||
if (e == SSL_ERROR_SSL &&
|
||||
sock->ssl->s3->send_alert[0] == SSL3_AL_FATAL &&
|
||||
sock->ssl->s3->send_alert[0] != sock->Ssl_Init_Async_SendAlert[0] &&
|
||||
sock->ssl->s3->send_alert[1] != sock->Ssl_Init_Async_SendAlert[1])
|
||||
{
|
||||
Debug("%s %u SSL Fatal Error on ASYNC socket !!!\n", __FILE__, __LINE__);
|
||||
Disconnect(sock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Packet has not yet arrived
|
||||
return SOCK_LATER;
|
||||
}
|
||||
@@ -14220,24 +14246,6 @@ void Disconnect(SOCK *sock)
|
||||
sock->ssl_ctx = NULL;
|
||||
}
|
||||
sock->Connected = false;
|
||||
// Release the certificate
|
||||
if (sock->RemoteX != NULL)
|
||||
{
|
||||
FreeX(sock->RemoteX);
|
||||
sock->RemoteX = NULL;
|
||||
}
|
||||
if (sock->LocalX != NULL)
|
||||
{
|
||||
FreeX(sock->LocalX);
|
||||
sock->LocalX = NULL;
|
||||
}
|
||||
|
||||
// Cipher algorithm name
|
||||
if (sock->CipherName != NULL)
|
||||
{
|
||||
Free(sock->CipherName);
|
||||
sock->CipherName = NULL;
|
||||
}
|
||||
sock->SecureMode = false;
|
||||
}
|
||||
}
|
||||
@@ -14957,7 +14965,7 @@ SOCK *ConnectEx(char *hostname, UINT port, UINT timeout)
|
||||
}
|
||||
SOCK *ConnectEx2(char *hostname, UINT port, UINT timeout, bool *cancel_flag)
|
||||
{
|
||||
return ConnectEx3(hostname, port, timeout, cancel_flag, NULL, NULL, false, false, false);
|
||||
return ConnectEx3(hostname, port, timeout, cancel_flag, NULL, NULL, false, false, true);
|
||||
}
|
||||
SOCK *ConnectEx3(char *hostname, UINT port, UINT timeout, bool *cancel_flag, char *nat_t_svc_name, UINT *nat_t_error_code, bool try_start_ssl, bool ssl_no_tls, bool no_get_hostname)
|
||||
{
|
||||
@@ -15824,6 +15832,25 @@ void CleanupSock(SOCK *s)
|
||||
}
|
||||
#endif // OS_WIN32
|
||||
|
||||
// Release the certificate
|
||||
if (s->RemoteX != NULL)
|
||||
{
|
||||
FreeX(s->RemoteX);
|
||||
s->RemoteX = NULL;
|
||||
}
|
||||
if (s->LocalX != NULL)
|
||||
{
|
||||
FreeX(s->LocalX);
|
||||
s->LocalX = NULL;
|
||||
}
|
||||
|
||||
// Cipher algorithm name
|
||||
if (s->CipherName != NULL)
|
||||
{
|
||||
Free(s->CipherName);
|
||||
s->CipherName = NULL;
|
||||
}
|
||||
|
||||
Free(s->WaitToUseCipher);
|
||||
DeleteLock(s->lock);
|
||||
DeleteLock(s->ssl_lock);
|
||||
|
||||
@@ -304,6 +304,7 @@ struct SOCK
|
||||
bool IsReverseAcceptedSocket; // Whether it is a reverse socket
|
||||
IP Reverse_MyServerGlobalIp; // Self global IP address when using the reverse socket
|
||||
UINT Reverse_MyServerPort; // Self port number when using the reverse socket
|
||||
UCHAR Ssl_Init_Async_SendAlert[2]; // Initial state of SSL send_alert
|
||||
|
||||
#ifdef ENABLE_SSL_LOGGING
|
||||
// SSL Logging (for debug)
|
||||
@@ -740,8 +741,8 @@ struct RUDP_SESSION
|
||||
};
|
||||
|
||||
// NAT Traversal Server Information
|
||||
#define UDP_NAT_T_SERVER_TAG "x%c.x%c.x%c.x%c.servers.nat-traversal.softether-network.net."
|
||||
#define UDP_NAT_T_SERVER_TAG_ALT "x%c.x%c.x%c.x%c.servers.nat-traversal.uxcom.jp."
|
||||
#define UDP_NAT_T_SERVER_TAG "x%c.x%c.servers.nat-traversal.softether-network.net."
|
||||
#define UDP_NAT_T_SERVER_TAG_ALT "x%c.x%c.servers.nat-traversal.uxcom.jp."
|
||||
#define UDP_NAT_T_PORT 5004
|
||||
|
||||
// Related to processing to get the IP address of the NAT-T server
|
||||
|
||||
+8
-4
@@ -197,10 +197,14 @@ char *OsTypeToStr(UINT type)
|
||||
return "Windows 8.1\0\n";
|
||||
case OSTYPE_WINDOWS_SERVER_81:
|
||||
return "Windows Server 2012 R2\0\n";
|
||||
case OSTYPE_WINDOWS_9:
|
||||
return "Windows 8.2 or later\0\n";
|
||||
case OSTYPE_WINDOWS_SERVER_9:
|
||||
return "Windows Server 8.2 or later\0\n";
|
||||
case OSTYPE_WINDOWS_10:
|
||||
return "Windows 10\0\n";
|
||||
case OSTYPE_WINDOWS_SERVER_10:
|
||||
return "Windows Server 10\0\n";
|
||||
case OSTYPE_WINDOWS_11:
|
||||
return "Windows 11 or later\0\n";
|
||||
case OSTYPE_WINDOWS_SERVER_11:
|
||||
return "Windows Server 11 or later\0\n";
|
||||
case OSTYPE_UNIX_UNKNOWN:
|
||||
return "UNIX System\0\n";
|
||||
case OSTYPE_LINUX:
|
||||
|
||||
+1
-1
@@ -2183,7 +2183,7 @@ bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3)
|
||||
b2 = false;
|
||||
}
|
||||
}
|
||||
if (b1 || b2 || (Cmp(p->MacHeader->SrcAddress, p->MacHeader->DestAddress, 6) == 0))
|
||||
if (b1 || b2 || (memcmp(p->MacHeader->SrcAddress, p->MacHeader->DestAddress, 6) == 0))
|
||||
{
|
||||
p->InvalidSourcePacket = true;
|
||||
}
|
||||
|
||||
+63
-12
@@ -966,6 +966,24 @@ void *UnixNewSingleInstance(char *instance_name)
|
||||
}
|
||||
}
|
||||
|
||||
// Set the high oom score
|
||||
void UnixSetHighOomScore()
|
||||
{
|
||||
IO *o;
|
||||
char tmp[256];
|
||||
|
||||
sprintf(tmp, "/proc/%u/oom_score_adj", getpid());
|
||||
|
||||
o = UnixFileCreate(tmp);
|
||||
if (o != NULL)
|
||||
{
|
||||
char tmp[128];
|
||||
sprintf(tmp, "%u\n", 800);
|
||||
UnixFileWrite(o, tmp, strlen(tmp));
|
||||
UnixFileClose(o, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Raise the priority of the process
|
||||
void UnixSetHighPriority()
|
||||
{
|
||||
@@ -2139,10 +2157,24 @@ void UnixSigChldHandler(int sig)
|
||||
signal(SIGCHLD, UnixSigChldHandler);
|
||||
}
|
||||
|
||||
// Disable core dump
|
||||
void UnixDisableCoreDump()
|
||||
{
|
||||
#ifdef RLIMIT_CORE
|
||||
UnixSetResourceLimit(RLIMIT_CORE, 0);
|
||||
#endif // RLIMIT_CORE
|
||||
}
|
||||
|
||||
// Initialize the library for UNIX
|
||||
void UnixInit()
|
||||
{
|
||||
UNIXIO *o;
|
||||
UINT64 max_memory = UNIX_MAX_MEMORY;
|
||||
|
||||
if (UnixIs64BitRlimSupported())
|
||||
{
|
||||
max_memory = UNIX_MAX_MEMORY_64;
|
||||
}
|
||||
|
||||
UnixInitSolarisSleep();
|
||||
|
||||
@@ -2154,11 +2186,11 @@ void UnixInit()
|
||||
current_process_id = getpid();
|
||||
|
||||
#ifdef RLIMIT_CORE
|
||||
UnixSetResourceLimit(RLIMIT_CORE, UNIX_MAX_MEMORY);
|
||||
UnixSetResourceLimit(RLIMIT_CORE, max_memory);
|
||||
#endif // RLIMIT_CORE
|
||||
|
||||
#ifdef RLIMIT_DATA
|
||||
UnixSetResourceLimit(RLIMIT_DATA, UNIX_MAX_MEMORY);
|
||||
UnixSetResourceLimit(RLIMIT_DATA, max_memory);
|
||||
#endif // RLIMIT_DATA
|
||||
|
||||
#ifdef RLIMIT_NOFILE
|
||||
@@ -2170,11 +2202,11 @@ void UnixInit()
|
||||
#endif // RLIMIT_NOFILE
|
||||
|
||||
#ifdef RLIMIT_STACK
|
||||
// UnixSetResourceLimit(RLIMIT_STACK, UNIX_MAX_MEMORY);
|
||||
// UnixSetResourceLimit(RLIMIT_STACK, max_memory);
|
||||
#endif // RLIMIT_STACK
|
||||
|
||||
#ifdef RLIMIT_RSS
|
||||
UnixSetResourceLimit(RLIMIT_RSS, UNIX_MAX_MEMORY);
|
||||
UnixSetResourceLimit(RLIMIT_RSS, max_memory);
|
||||
#endif // RLIMIT_RSS
|
||||
|
||||
#ifdef RLIMIT_LOCKS
|
||||
@@ -2182,7 +2214,7 @@ void UnixInit()
|
||||
#endif // RLIMIT_LOCKS
|
||||
|
||||
#ifdef RLIMIT_MEMLOCK
|
||||
UnixSetResourceLimit(RLIMIT_MEMLOCK, UNIX_MAX_MEMORY);
|
||||
UnixSetResourceLimit(RLIMIT_MEMLOCK, max_memory);
|
||||
#endif // RLIMIT_MEMLOCK
|
||||
|
||||
#ifdef RLIMIT_NPROC
|
||||
@@ -2226,27 +2258,46 @@ void UnixFree()
|
||||
}
|
||||
|
||||
// Adjust the upper limit of resources that may be occupied
|
||||
void UnixSetResourceLimit(UINT id, UINT value)
|
||||
void UnixSetResourceLimit(UINT id, UINT64 value)
|
||||
{
|
||||
struct rlimit t;
|
||||
UINT hard_limit;
|
||||
UINT64 hard_limit;
|
||||
|
||||
if (UnixIs64BitRlimSupported() == false)
|
||||
{
|
||||
if (value > (UINT64)4294967295ULL)
|
||||
{
|
||||
value = (UINT64)4294967295ULL;
|
||||
}
|
||||
}
|
||||
|
||||
Zero(&t, sizeof(t));
|
||||
getrlimit(id, &t);
|
||||
|
||||
hard_limit = t.rlim_max;
|
||||
hard_limit = (UINT64)t.rlim_max;
|
||||
|
||||
Zero(&t, sizeof(t));
|
||||
t.rlim_cur = MIN(value, hard_limit);
|
||||
t.rlim_max = hard_limit;
|
||||
t.rlim_cur = (rlim_t)MIN(value, hard_limit);
|
||||
t.rlim_max = (rlim_t)hard_limit;
|
||||
setrlimit(id, &t);
|
||||
|
||||
Zero(&t, sizeof(t));
|
||||
t.rlim_cur = value;
|
||||
t.rlim_max = value;
|
||||
t.rlim_cur = (rlim_t)value;
|
||||
t.rlim_max = (rlim_t)value;
|
||||
setrlimit(id, &t);
|
||||
}
|
||||
|
||||
// Is the rlim_t type 64-bit?
|
||||
bool UnixIs64BitRlimSupported()
|
||||
{
|
||||
if (sizeof(rlim_t) >= 8)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Generate the PID file name
|
||||
void UnixGenPidFileName(char *name, UINT size)
|
||||
{
|
||||
|
||||
+5
-1
@@ -122,6 +122,7 @@
|
||||
#define UNIX_LINUX_MAX_THREADS 200000000 // Maximum number of threads
|
||||
#define UNIX_MAX_LOCKS 65536 // Maximum number of locks
|
||||
#define UNIX_MAX_MEMORY (2147483648UL) // Maximum memory capacity
|
||||
#define UNIX_MAX_MEMORY_64 ((UINT64)((UINT64)65536ULL * (UINT64)2147483647ULL)) // Maximum memory capacity (64-bit)
|
||||
#define UNIX_MAX_FD (655360) // Maximum number of FDs
|
||||
#define UNIX_MAX_FD_MACOS (10000) // Maximum number of FDs (Mac OS X)
|
||||
#define MAXIMUM_WAIT_OBJECTS 64 // Maximum number of select
|
||||
@@ -201,6 +202,7 @@ void UnixAlert(char *msg, char *caption);
|
||||
void UnixAlertW(wchar_t *msg, wchar_t *caption);
|
||||
char *UnixGetProductId();
|
||||
void UnixSetHighPriority();
|
||||
void UnixSetHighOomScore();
|
||||
void UnixRestorePriority();
|
||||
void *UnixNewSingleInstance(char *instance_name);
|
||||
void UnixFreeSingleInstance(void *data);
|
||||
@@ -211,12 +213,14 @@ void UnixExecSilent(char *cmd);
|
||||
void UnixDisableInterfaceOffload(char *name);
|
||||
void UnixSetEnableKernelEspProcessing(bool b);
|
||||
|
||||
void UnixDisableCoreDump();
|
||||
void UnixSetThreadPriorityRealtime();
|
||||
void UnixSetThreadPriorityLow();
|
||||
void UnixSetThreadPriorityHigh();
|
||||
void UnixSetThreadPriorityIdle();
|
||||
void UnixRestoreThreadPriority();
|
||||
void UnixSetResourceLimit(UINT id, UINT value);
|
||||
void UnixSetResourceLimit(UINT id, UINT64 value);
|
||||
bool UnixIs64BitRlimSupported();
|
||||
UINT64 UnixGetTick64();
|
||||
void UnixSigChldHandler(int sig);
|
||||
void UnixCloseIO();
|
||||
|
||||
+17
-4
@@ -1407,17 +1407,30 @@ UINT Win32GetOsType()
|
||||
return OSTYPE_WINDOWS_SERVER_81;
|
||||
}
|
||||
}
|
||||
else if (os.dwMajorVersion == 6 && os.dwMinorVersion == 4)
|
||||
{
|
||||
if (os.wProductType == VER_NT_WORKSTATION)
|
||||
{
|
||||
// Windows 10
|
||||
return OSTYPE_WINDOWS_10;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Windows Server 10
|
||||
return OSTYPE_WINDOWS_SERVER_10;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (os.wProductType == VER_NT_WORKSTATION)
|
||||
{
|
||||
// Windows 9?
|
||||
return OSTYPE_WINDOWS_9;
|
||||
// Windows 11 or later
|
||||
return OSTYPE_WINDOWS_11;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Windows Server 9?
|
||||
return OSTYPE_WINDOWS_SERVER_9;
|
||||
// Windows Server 11 or later
|
||||
return OSTYPE_WINDOWS_SERVER_11;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user