Skip to content

Commit

Permalink
32 bit support
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Jun 18, 2024
1 parent 46cacb7 commit 403abab
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 49 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set(CMAKE_CXX_STANDARD 11 CACHE INTERNAL "CXX standard version" FORCE)
set(CMAKE_C_STANDARD_REQUIRED TRUE CACHE BOOL "request not to use lower versions" FORCE)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE CACHE BOOL "request not to use lower versions" FORCE)

# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32") for 32 bit build, note that ssl libs need tweaks
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")

if(CMAKE_BUILD_TYPE STREQUAL "Release")
cmake_policy(SET CMP0069 NEW)
Expand Down Expand Up @@ -50,8 +52,8 @@ option(INCLUDE_OPENSSL_SERVER "link OpenSSlServer staticly to the core" TRUE)
option(INCLUDE_OPENSSL_CLIENT "link OpenSSLClient staticly to the core" TRUE)
option(INCLUDE_TROJAN_AUTH_SERVER "link TrojanAuthServer staticly to the core" TRUE)
option(INCLUDE_TROJAN_SOCKS_SERVER "link TrojanSocksServer staticly to the core" TRUE)
option(INCLUDE_WOLFSSL_SERVER "link WolfSSLServer staticly to the core" TRUE) # temporarely disabled for compile speed
option(INCLUDE_WOLFSSL_CLIENT "link WolfSSLClient staticly to the core" TRUE) # temporarely disabled for compile speed
option(INCLUDE_WOLFSSL_SERVER "link WolfSSLServer staticly to the core" FALSE) # temporarely disabled for compile speed
option(INCLUDE_WOLFSSL_CLIENT "link WolfSSLClient staticly to the core" FALSE) # temporarely disabled for compile speed
option(INCLUDE_BORINGSSL_SERVER "link BoringSSLServer staticly to the core" FALSE) #conflicts with openssl/noprefix ?
option(INCLUDE_HTTP2_SERVER "link Http2Server staticly to the core" TRUE)
option(INCLUDE_HTTP2_CLIENT "link Http2Client staticly to the core" TRUE)
Expand Down
8 changes: 3 additions & 5 deletions tunnels/client/reverse/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "types.h"
#include <stdbool.h>


enum
{
kPreconnectDelayShort = 10,
Expand Down Expand Up @@ -49,7 +48,7 @@ static void cleanup(reverse_client_con_state_t *cstate)
if (cstate->idle_handle)
{
reverse_client_state_t *state = STATE(cstate->self);
removeIdleItemByHash(cstate->u->tid, state->starved_connections, (hash_t) (cstate));
removeIdleItemByHash(cstate->u->tid, state->starved_connections, (hash_t) (size_t) (cstate));
}
doneLineDownSide(cstate->u);
doneLineDownSide(cstate->d);
Expand All @@ -60,11 +59,11 @@ static void cleanup(reverse_client_con_state_t *cstate)
}
static void doConnect(struct connect_arg *cg)
{
tunnel_t *self = cg->t;
tunnel_t *self = cg->t;
// reverse_client_state_t *state = STATE(self);
reverse_client_con_state_t *cstate = createCstate(self, cg->tid);
free(cg);
context_t *hello_data_ctx = newContext(cstate->u);
context_t *hello_data_ctx = newContext(cstate->u);
self->up->upStream(self->up, newInitContext(cstate->u));

if (! isAlive(cstate->u))
Expand Down Expand Up @@ -151,7 +150,6 @@ static void onStarvedConnectionExpire(idle_item_t *idle_con)

assert(! cstate->pair_connected);


state->threadlocal_pool[cstate->u->tid].unused_cons_count -= 1;
LOGW("ReverseClient: a idle connection detected and closed");

Expand Down
4 changes: 2 additions & 2 deletions tunnels/client/reverse/reverse_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static void downStream(tunnel_t *self, context_t *c)
{
ucstate->idle_handle = NULL;
reverse_client_state_t *state = STATE(ucstate->self);
removeIdleItemByHash(ucstate->u->tid, state->starved_connections, (hash_t) (ucstate));
removeIdleItemByHash(ucstate->u->tid, state->starved_connections, (hash_t)(size_t) (ucstate));
}

ucstate->pair_connected = true;
Expand Down Expand Up @@ -136,7 +136,7 @@ static void downStream(tunnel_t *self, context_t *c)

initiateConnect(self, tid, false);

ucstate->idle_handle = newIdleItem(state->starved_connections, (hash_t) (ucstate), ucstate,
ucstate->idle_handle = newIdleItem(state->starved_connections, (hash_t) (size_t)(ucstate), ucstate,
onStarvedConnectionExpire, c->line->tid,
kConnectionStarvationTimeOut);

Expand Down
2 changes: 1 addition & 1 deletion ww/basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#if defined(OS_UNIX)
#include <sys/types.h>
#elif ! defined(ssize_t)
typedef int64_t ssize_t;
typedef long ssize_t;
#endif

typedef uint64_t hash_t;
Expand Down
70 changes: 46 additions & 24 deletions ww/eventloop/base/hbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ char* hv_strreverse(char* str) {
if (str == NULL) return NULL;
char* b = str;
char* e = str;
while(*e) {++e;}
while (*e) {
++e;
}
--e;
char tmp;
while (e > b) {
Expand Down Expand Up @@ -128,7 +130,10 @@ char* hv_strncpy(char* dest, const char* src, size_t n) {
char* hv_strncat(char* dest, const char* src, size_t n) {
assert(dest != NULL && src != NULL);
char* ret = dest;
while (*dest) {++dest;--n;}
while (*dest) {
++dest;
--n;
}
while (*src != '\0' && --n > 0) {
*dest++ = *src++;
}
Expand All @@ -149,8 +154,14 @@ bool hv_strendswith(const char* str, const char* end) {
assert(str != NULL && end != NULL);
int len1 = 0;
int len2 = 0;
while (*str) {++str; ++len1;}
while (*end) {++end; ++len2;}
while (*str) {
++str;
++len1;
}
while (*end) {
++end;
++len2;
}
if (len1 < len2) return false;
while (len2-- > 0) {
--str;
Expand All @@ -174,10 +185,12 @@ bool hv_wildcard_match(const char* str, const char* pattern) {
if (*pattern == '*') {
match = hv_strendswith(str, pattern + 1);
break;
} else if (*str != *pattern) {
}
else if (*str != *pattern) {
match = false;
break;
} else {
}
else {
++str;
++pattern;
}
Expand Down Expand Up @@ -211,12 +224,12 @@ char* hv_strrchr_dir(const char* filepath) {

const char* hv_basename(const char* filepath) {
const char* pos = hv_strrchr_dir(filepath);
return pos ? pos+1 : filepath;
return pos ? pos + 1 : filepath;
}

const char* hv_suffixname(const char* filename) {
const char* pos = hv_strrchr_dot(filename);
return pos ? pos+1 : "";
return pos ? pos + 1 : "";
}

int hv_mkdir_p(const char* dir) {
Expand Down Expand Up @@ -402,19 +415,25 @@ bool hv_getboolean(const char* str) {
}

size_t hv_parse_size(const char* str) {
size_t size = 0, n = 0;
size_t size = 0;
uint64_t n = 0;
const char* p = str;
char c;
while ((c = *p) != '\0') {
if (c >= '0' && c <= '9') {
n = n * 10 + c - '0';
} else {
}
else {
switch (c) {
case 'K': case 'k': n <<= 10; break;
case 'M': case 'm': n <<= 20; break;
case 'G': case 'g': n <<= 30; break;
case 'T': case 't': n <<= 40; break;
default: break;
case 'K':
case 'k': n <<= 10; break;
case 'M':
case 'm': n <<= 20; break;
case 'G':
case 'g': n <<= 30; break;
case 'T':
case 't': n <<= 40; break;
default: break;
}
size += n;
n = 0;
Expand All @@ -431,14 +450,15 @@ time_t hv_parse_time(const char* str) {
while ((c = *p) != '\0') {
if (c >= '0' && c <= '9') {
n = n * 10 + c - '0';
} else {
}
else {
switch (c) {
case 's': break;
case 'm': n *= 60; break;
case 'h': n *= 60 * 60; break;
case 'd': n *= 24 * 60 * 60; break;
case 'w': n *= 7 * 24 * 60 * 60; break;
default: break;
case 's': break;
case 'm': n *= 60; break;
case 'h': n *= 60 * 60; break;
case 'd': n *= 24 * 60 * 60; break;
case 'w': n *= 7 * 24 * 60 * 60; break;
default: break;
}
time += n;
n = 0;
Expand Down Expand Up @@ -475,7 +495,8 @@ int hv_parse_url(hurl_t* stURL, const char* strURL) {
if (pswd) {
stURL->fields[HV_URL_PASSWORD].off = pswd + 1 - begin;
stURL->fields[HV_URL_PASSWORD].len = pos - pswd - 1;
} else {
}
else {
pswd = pos;
}
stURL->fields[HV_URL_USERNAME].off = user - begin;
Expand All @@ -492,7 +513,8 @@ int hv_parse_url(hurl_t* stURL, const char* strURL) {
for (unsigned short i = 1; i <= stURL->fields[HV_URL_PORT].len; ++i) {
stURL->port = stURL->port * 10 + (port[i] - '0');
}
} else {
}
else {
port = ep;
// set default port
stURL->port = 80;
Expand Down
17 changes: 2 additions & 15 deletions ww/eventloop/base/hlsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ static bool SemaWait(hsem_t* sp) {
}
}



static bool SemaTimedWait(hsem_t* sp, uint64_t timeout_usecs) {
mach_timespec_t ts;
ts.tv_sec = (uint32_t)(timeout_usecs / USECS_IN_1_SEC);
Expand Down Expand Up @@ -215,11 +213,7 @@ static bool SemaSignal(hsem_t* sp, uint32_t count) {
#define LSEMA_MAX_SPINS 10000

static bool _LSemaWaitPartialSpin(hlsem_t* s, uint64_t timeout_usecs) {
#ifdef OS_UNIX
ssize_t oldCount;
#else
long oldCount;
#endif
int spin = LSEMA_MAX_SPINS;
while (--spin >= 0) {
oldCount = atomic_load_explicit(&s->count, memory_order_relaxed);
Expand Down Expand Up @@ -264,11 +258,8 @@ bool LSemaWait(hlsem_t* s) {
}

bool LSemaTryWait(hlsem_t* s) {
#ifdef OS_UNIX
ssize_t oldCount = atomic_load_explicit(&s->count, memory_order_relaxed);
#else
long oldCount = atomic_load_explicit(&s->count, memory_order_relaxed);
#endif

while (oldCount > 0) {
if (atomic_compare_exchange_weak_explicit(&s->count, &oldCount, oldCount - 1, memory_order_acquire, memory_order_relaxed)) {
return true;
Expand All @@ -283,13 +274,9 @@ bool LSemaTimedWait(hlsem_t* s, uint64_t timeout_usecs) {

void LSemaSignal(hlsem_t* s, uint32_t count) {
assert(count > 0);
#ifdef OS_UNIX
ssize_t oldCount = atomic_fetch_add_explicit(&s->count, (ssize_t)count, memory_order_release);
ssize_t toRelease = -oldCount < count ? -oldCount : (ssize_t)count;
#else

long oldCount = atomic_fetch_add_explicit(&s->count, (long)count, memory_order_release);
long toRelease = -oldCount < (long)count ? -oldCount : (long)count;
#endif
if (toRelease > 0) SemaSignal(&s->sema, (uint32_t)toRelease);
}

Expand Down

0 comments on commit 403abab

Please sign in to comment.