Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Add an 80386-only mode #75

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ else(WIN32)
-m32
)

if(ONLY_80386)
add_compile_options(-march=i386)
endif(ONLY_80386)

# Link everything 32-bit (until we have a 64-bit option)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
Expand Down
10 changes: 10 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ CMAKE_OPTS="${CMAKE_OPTS} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
CC=${CC:-clang}
CXX=${CXX:-clang++}

if [[ -n "${ONLY_80386}" ]]; then
# NOTE(ww): clang's -march=i386 generates instructions for i486 and i586.
# See: https://reviews.llvm.org/D18802 (which was never merged)
if [[ "${CC}" == "clang" ]]; then
echo "80386-only instructions requested, but clang has a buggy -march=i386. Good luck!"
fi

CMAKE_OPTS="$CMAKE_OPTS -DONLY_80386=1"
fi

CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_C_COMPILER=$CC"
CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_ASM_COMPILER=$CC"
CMAKE_OPTS="$CMAKE_OPTS -DCMAKE_CXX_COMPILER=$CXX"
Expand Down
2 changes: 1 addition & 1 deletion challenges/Azurad/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS )
set( SERVICE_ID "00119" )
set( AUTHOR_ID "KPRCA" )
add_compile_options( -Oz -g )
add_compile_options( -Os -g )
set( VULN_COUNT "1" )
buildCB()
48 changes: 24 additions & 24 deletions challenges/Blubber/cb_1/src/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef struct
bool registered;
bool waiting;
uint32_t last_read;
blubber* blubber;
blubber* blubber_;
} client_state;

client_state* new_client(int n)
Expand All @@ -73,7 +73,7 @@ client_state* new_client(int n)

c->last_read = 0;
c->registered = false;
c->blubber = new blubber();
c->blubber_ = new blubber();
return c;
}

Expand Down Expand Up @@ -128,11 +128,11 @@ void handle_read(server_state* s, client_state* c)
for (cgc_size_t i = 0; i < s->num_clients; ++i)
{
client_state* other = s->clients[i];
if (c->blubber->subs.contains(other->blubber))
if (c->blubber_->subs.contains(other->blubber_))
{
for (cgc_size_t j = 0; j < other->blubber->blubs.length(); j++)
for (cgc_size_t j = 0; j < other->blubber_->blubs.length(); j++)
{
blub* b = (blub*)other->blubber->blubs.get(j);
blub* b = (blub*)other->blubber_->blubs.get(j);
if (b->ts > c->last_read)
{
unread.add(b);
Expand Down Expand Up @@ -169,11 +169,11 @@ void handle_blub(client_state* c)
tmp[BLUB_MAX] = '\0';

dbg("Recorded blub (%s) %d", tmp, cgc_strlen(tmp))
c->blubber->record_blub(tmp);
c->blubber_->record_blub(tmp);
}
else
{
blub* b = c->blubber->gen_blub();
blub* b = c->blubber_->gen_blub();
if (b)
{
dbg("Recorded blub (%s) %d", b->content, cgc_strlen(b->content));
Expand Down Expand Up @@ -202,23 +202,23 @@ void handle_reblub(server_state* s, client_state* c)

idx = cgc_strtol(num, NULL, 10);

dbg("(%s) attempting to reblub (%s)'s %d blub", c->blubber->username, username, idx);
dbg("(%s) attempting to reblub (%s)'s %d blub", c->blubber_->username, username, idx);
for (cgc_size_t i = 0; i < s->num_clients; ++i)
{
client_state* other = s->clients[i];
// Make sure author exists and client is subbed to them.
if (cgc_strcmp(other->blubber->username, username) == 0 && c->blubber->subs.contains(other->blubber))
if (cgc_strcmp(other->blubber_->username, username) == 0 && c->blubber_->subs.contains(other->blubber_))
{
dbg("Found (%s) in (%s)'s subs", other->blubber->username, c->blubber->username);
if (other->blubber->blubs.length() > idx)
dbg("Found (%s) in (%s)'s subs", other->blubber_->username, c->blubber_->username);
if (other->blubber_->blubs.length() > idx)
{
dbg("Fetching (%s) %d blub", other->blubber->username, idx);
blub* b = (blub*)other->blubber->blubs.get(idx);
dbg("Fetching (%s) %d blub", other->blubber_->username, idx);
blub* b = (blub*)other->blubber_->blubs.get(idx);
if (b)
{
dbg("(%s) reblubbed (%s)'s %d blub", c->blubber->username, other->blubber->username, idx);
blub* n = new blub(c->blubber->username, b->content);
c->blubber->blubs.add(n);
dbg("(%s) reblubbed (%s)'s %d blub", c->blubber_->username, other->blubber_->username, idx);
blub* n = new blub(c->blubber_->username, b->content);
c->blubber_->blubs.add(n);
}
}
}
Expand All @@ -235,26 +235,26 @@ void handle_sub(server_state* s, client_state* c)
}
username[USERNAME_MAX] = '\0';

dbg("Attempting to sub (%s) to (%s)", c->blubber->username, username);
dbg("Attempting to sub (%s) to (%s)", c->blubber_->username, username);
for (cgc_size_t i = 0; i < s->num_clients; ++i)
{
client_state* other = s->clients[i];
if (cgc_strcmp(other->blubber->username, username) == 0)
if (cgc_strcmp(other->blubber_->username, username) == 0)
{
if (c->blubber->subs.contains(other->blubber))
if (c->blubber_->subs.contains(other->blubber_))
{
dbg("(%s) is already subbed to (%s)", c->blubber->username, username);
dbg("(%s) is already subbed to (%s)", c->blubber_->username, username);
return;
}
else
{
dbg("Subbed (%s) to (%s)", c->blubber->username, username);
c->blubber->subs.add(other->blubber);
dbg("Subbed (%s) to (%s)", c->blubber_->username, username);
c->blubber_->subs.add(other->blubber_);
return;
}
}
}
dbg("Failed to sub (%s) to (%s)", c->blubber->username, username);
dbg("Failed to sub (%s) to (%s)", c->blubber_->username, username);
}

int run_server(server_state* state)
Expand All @@ -275,7 +275,7 @@ int run_server(server_state* state)
dbg("Registered %d as (%s)", c->n, username);
cgc_fprintf(c->tx, (char *)"Welcome to blubber, %s" EOT_S, username);
c->registered = true;
c->blubber->set_username(username);
c->blubber_->set_username(username);
state->num_alive++;
}

Expand Down
2 changes: 1 addition & 1 deletion challenges/FailAV/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set( VULN_COUNT "1" )
add_compile_options( -fno-exceptions -fno-rtti -DCPLUSPLUS )
set( override LDFLAGS "-nostdlib -static -Ttext=0x90000000" )
add_compile_options( -Oz -g )
add_compile_options( -Os -g )
set( SERVICE_ID "00091" )
set( AUTHOR_ID "KPRCA" )
buildCB()