Skip to content

Commit e467450

Browse files
committed
plugin / impl: macOS compatibility
* Code is so magical!
1 parent e82dae7 commit e467450

File tree

6 files changed

+27
-5
lines changed

6 files changed

+27
-5
lines changed

Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ include config.mk
22

33
#### Populate [C|LD]FLAGS ####
44
COMMON_CFLAGS := $(CUSTOM_CFLAGS) $(CFLAGS) -Wall -D_GNU_SOURCE
5-
COMMON_LDFLAGS := $(CUSTOM_LDFLAGS) $(LDFLAGS) -T minieap_init_func.lds
5+
COMMON_LDFLAGS := $(CUSTOM_LDFLAGS) $(LDFLAGS)
66
LIBS += $(CUSTOM_LIBS)
77

8+
# You are not cross-compiling for macOS on Linux, I guess?
9+
ifeq ($(shell uname -s),Linux)
10+
COMMON_LDFLAGS += -T minieap_init_func.lds
11+
endif
12+
813
ifeq ($(ENABLE_ICONV),true)
914
COMMON_CFLAGS += -DENABLE_ICONV
1015
ifeq ($(LIBICONV_STANDALONE),true)

if_impl/if_impl.c

+5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ IF_IMPL* sockraw_new();
1111
IF_IMPL* libpcap_new();
1212

1313
int init_if_impl_list() {
14+
#ifdef __linux__
1415
extern IF_IMPL* (*__IF_IMPL_LIST_START__)();
1516
extern IF_IMPL* (*__IF_IMPL_LIST_END__)(); // They are just location markers, do not care about their content
17+
#else
18+
extern IF_IMPL* (*__IF_IMPL_LIST_START__)() __asm("section$start$__DATA$__ifimplinit");
19+
extern IF_IMPL* (*__IF_IMPL_LIST_END__)() __asm("section$end$__DATA$__ifimplinit");
20+
#endif
1621
IF_IMPL* (**func)();
1722
int i = 0;
1823
for (func = &__IF_IMPL_LIST_START__; func < &__IF_IMPL_LIST_END__; ++i, ++func) {

include/if_impl.h

+4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020

2121
#define FRAME_BUF_SIZE 1512
2222

23+
#ifdef __linux__
2324
#define IF_IMPL_INIT(func) __define_in_init(func, ".ifimplinit")
25+
#else
26+
#define IF_IMPL_INIT(func) __define_in_init(func, "__DATA,__ifimplinit")
27+
#endif
2428

2529
/*
2630
* Representing an interface driver plugin.

include/module_init.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
#define _MINIEAP_MODULE_INIT
33

44
#define __define_in_init(func, sect) \
5-
static void* __init_##func __attribute__((unused, __section__(sect))) = func;
6-
5+
static void* __init_##func __attribute__((used, __section__(sect))) = func;
76
#endif

include/packet_plugin.h

+4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
#include "eth_frame.h"
66
#include "module_init.h"
77

8+
#ifdef __linux__
89
#define PACKET_PLUGIN_INIT(func) __define_in_init(func, ".pktplugininit")
10+
#else
11+
#define PACKET_PLUGIN_INIT(func) __define_in_init(func, "__DATA,__pktplugininit")
12+
#endif
913

1014
typedef struct _packet_plugin {
1115
/*

packet_plugin/packet_plugin.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ PACKET_PLUGIN* packet_plugin_rjv3_new();
1818
PACKET_PLUGIN* packet_plugin_printer_new();
1919

2020
int init_packet_plugin_list() {
21-
extern PACKET_PLUGIN* (*__PACKET_PLUGIN_LIST_START__)(void);
22-
extern PACKET_PLUGIN* (*__PACKET_PLUGIN_LIST_END__)(void);
21+
#ifdef __linux__
22+
extern PACKET_PLUGIN* (*__PACKET_PLUGIN_LIST_START__)();
23+
extern PACKET_PLUGIN* (*__PACKET_PLUGIN_LIST_END__)();
24+
#else
25+
extern PACKET_PLUGIN* (*__PACKET_PLUGIN_LIST_START__)() __asm("section$start$__DATA$__pktplugininit");
26+
extern PACKET_PLUGIN* (*__PACKET_PLUGIN_LIST_END__)() __asm("section$end$__DATA$__pktplugininit");
27+
#endif
2328
PACKET_PLUGIN* (**func)();
2429
int i = 0;
2530
for (func = &__PACKET_PLUGIN_LIST_START__; func < &__PACKET_PLUGIN_LIST_END__; ++i, ++func) {

0 commit comments

Comments
 (0)