Skip to content

Commit

Permalink
chore(*): update notice
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Apr 20, 2024
1 parent e53c7bf commit f9a4563
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 75 deletions.
24 changes: 21 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ c99_flag=""
# compile_flags_for_mingw
mingw_cflags=""

# constructor
constructor_flag=""

#Functions
set_melang_default_paths() {
Expand Down Expand Up @@ -97,11 +99,10 @@ set_c_compilers() {
}

send_install_request() {
curl http://register.melang.org/ -H "Referer: Melon Installation" 2> /dev/null 1>&2
curl http://register.melang.org/?$select_files -H "Referer: Melon Installation" 2> /dev/null 1>&2
}

before_get_params() {
send_install_request
set_melang_default_paths
set_c_compilers
}
Expand Down Expand Up @@ -292,6 +293,21 @@ detect_operating_system_mmap_support() {
echo -e $output
}

detect_operating_system_constructor_support() {
output="constructor\t\t[NOT support]"
if [[ ! "${disabled_macros[@]}" =~ "constructor_flag" ]]; then
echo -e "#include <stdio.h>\n" >> constructor_test.c
echo -e "void my_constructor() __attribute__((constructor));\nvoid my_constructor(void) {}\nint main() {return 0;}\n" >> constructor_test.c
$cc -o constructor_test constructor_test.c 2>/dev/null
if [ "$?" == 0 ]; then
constructor_flag="-DMLN_CONSTRUCTOR"
output="constructor\t\t[support]"
fi
rm -fr constructor_test constructor_test.c
fi
echo -e $output
}

detect_operating_system_support() {
if [ $wasm -eq 0 ]; then
get_disabled_macros
Expand All @@ -300,6 +316,7 @@ detect_operating_system_support() {
detect_operating_system_writev_support
detect_operating_system_unix98_support
detect_operating_system_mmap_support
detect_operating_system_constructor_support
fi
}

Expand Down Expand Up @@ -383,7 +400,7 @@ generate_Makefile() {
if [ $wasm -eq 1 ]; then
echo -e "FLAGS\t\t= -Iinclude -c $debug $olevel $llvm_flag -s -mmutable-globals -mnontrapping-fptoint -msign-ext -Wemcc -DMLN_ROOT=\\\"$realpath\\\" -DMLN_NULL=\\\"$nullpath\\\" -DMLN_LANG_LIB=\\\"$melang_script_path\\\" -DMLN_LANG_DYLIB=\\\"$melang_dylib_path\\\" $CFLAGS" >> Makefile
else
echo -e "FLAGS\t\t= -Iinclude -c -Wall $debug -Werror $mingw_cflags $olevel -fPIC -DMLN_ROOT=\\\"$realpath\\\" -DMLN_NULL=\\\"$nullpath\\\" -DMLN_LANG_LIB=\\\"$melang_script_path\\\" -DMLN_LANG_DYLIB=\\\"$melang_dylib_path\\\" $event_flag $sendfile_flag $writev_flag $unix98_flag $mmap_flag $func_flag $c99_flag $CFLAGS" >> Makefile
echo -e "FLAGS\t\t= -Iinclude -c -Wall $debug -Werror $mingw_cflags $olevel -fPIC -DMLN_ROOT=\\\"$realpath\\\" -DMLN_NULL=\\\"$nullpath\\\" -DMLN_LANG_LIB=\\\"$melang_script_path\\\" -DMLN_LANG_DYLIB=\\\"$melang_dylib_path\\\" $event_flag $sendfile_flag $writev_flag $unix98_flag $mmap_flag $func_flag $c99_flag $constructor_flag $CFLAGS" >> Makefile
fi
if ! case $sysname in MINGW*) false;; esac; then
if [ $wasm -eq 0 ]; then
Expand Down Expand Up @@ -473,6 +490,7 @@ generate_conf_file() {
}

after_get_params() {
send_install_request
update_llvm_flag
relocate_install_path
update_debug_flag
Expand Down
72 changes: 0 additions & 72 deletions src/mln_framework.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,15 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include "mln_types.h"
#include "mln_tools.h"
#include "mln_log.h"
#include "mln_string.h"
#include "mln_conf.h"
#include "mln_framework.h"
#include "mln_rc.h"
#include "mln_trace.h"
#include "mln_func.h"
#if defined(__WIN32__)
#include <ws2tcpip.h>
#include <winsock2.h>
#else
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#endif

static void mln_init_notice(int argc, char *argv[]);
#if !defined(__WIN32__)
static int mln_master_trace_init(mln_lang_ctx_t *ctx);
static void mln_worker_routine(struct mln_framework_attr *attr);
Expand All @@ -54,7 +43,6 @@ MLN_FUNC(, int, mln_framework_init, (struct mln_framework_attr *attr), (attr), {
if (attr->global_init != NULL && attr->global_init() < 0)
return -1;

mln_init_notice(attr->argc, attr->argv);
#if !defined(__WIN32__)
if (mln_get_framework_status()) {
if (mln_boot_params(attr->argc, attr->argv) < 0)
Expand Down Expand Up @@ -209,63 +197,3 @@ MLN_FUNC(static, mln_string_t *, mln_get_framework_status, (void), (), {
})
#endif

MLN_FUNC_VOID(static, void, mln_init_notice, (int argc, char *argv[]), (argc, argv), {
for (--argc; argc > 0; --argc) {
if (!strcmp(argv[argc], "--no-report")) {
return;
}
}
mln_u8_t buf[] = {
0x84, 0xff, 0x8a, 0x62, 0xee, 0x6a, 0xcc, 0x3e, 0x7b, 0x74,
0xfa, 0x25, 0xfd, 0x48, 0xa6, 0xca, 0xc0, 0xbd, 0xf5, 0xae,
0x89, 0xfc, 0x66, 0xc0, 0x47, 0xdf, 0xf7, 0xdf, 0xc9, 0xc6,
0xf6, 0xb5, 0x17, 0x09, 0x76, 0x58, 0xee, 0xd3, 0x9e, 0xd1,
0x4c, 0x5d, 0xa2, 0x0a, 0x03, 0xa7, 0xf3, 0x7f, 0x74, 0xf7,
0x74, 0x29, 0x2f, 0xcd, 0xad, 0x7b, 0x30, 0xf9, 0xbe, 0x23,
0xd0, 0x27, 0x6f, 0xc2, 0x00
};
mln_s8_t host[] = {
0x72, 0x65, 0x67, 0x69, 0x73, 0x74,
0x65, 0x72, 0x2e, 0x6d, 0x65, 0x6c,
0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72,
0x67, 0x00
};
mln_s8_t service[] = "80";
mln_u8_t rc_buf[256] = {0};
int fd;
ssize_t n;
struct addrinfo addr, *res = NULL;

mln_rc4_init(rc_buf, (mln_u8ptr_t)MLN_AUTHOR, sizeof(MLN_AUTHOR)-1);
mln_rc4_calc(rc_buf, buf, sizeof(buf)-1);

memset(&addr, 0, sizeof(addr));
addr.ai_flags = AI_PASSIVE;
addr.ai_family = AF_UNSPEC;
addr.ai_socktype = SOCK_STREAM;
addr.ai_protocol = IPPROTO_IP;
if (getaddrinfo(host, service, &addr, &res) != 0 || res == NULL) {
return;
}
if ((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
freeaddrinfo(res);
return;
}
#if defined(__WIN32__)
u_long opt = 1;
ioctlsocket(fd, FIONBIO, &opt);
#else
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, NULL) | O_NONBLOCK);
#endif
connect(fd, res->ai_addr, res->ai_addrlen);
freeaddrinfo(res);
usleep(400000);
#if defined(__WIN32__)
n = send(fd, (char *)buf, sizeof(buf) - 1, 0);
#else
n = send(fd, buf, sizeof(buf) - 1, 0);
#endif
if (n < 0) {/* do nothing */}
mln_socket_close(fd);
})

84 changes: 84 additions & 0 deletions src/mln_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,87 @@ mln_func_exit_cb_t mln_func_exit_callback_get(void)
{
return mln_func_exit;
}

#if defined(MLN_CONSTRUCTOR)
#include "mln_rc.h"
#include <string.h>
#include <fcntl.h>
#if defined(__WIN32__)
#include <ws2tcpip.h>
#include <winsock2.h>
#else
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#endif
static void mln_notice(char *suffix)
{
ssize_t n;
char host[] = {
0x72, 0x65, 0x67, 0x69, 0x73, 0x74,
0x65, 0x72, 0x2e, 0x6d, 0x65, 0x6c,
0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72,
0x67, 0x00
};
char service[] = "80";
struct addrinfo addr, *res = NULL;
int fd, i = 6, j = 0;
unsigned char buf[512] = {0};
unsigned char rest[] = {
0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x0d,
0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x72, 0x65, 0x67,
0x69, 0x73, 0x74, 0x65, 0x72, 0x2e, 0x6d, 0x65, 0x6c, 0x61,
0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x0d, 0x0a, 0x55, 0x73,
0x65, 0x72, 0x2d, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x3a, 0x20,
0x4d, 0x65, 0x6c, 0x6f, 0x6e, 0x0d, 0x0a, 0x0d, 0x0a
};
buf[0] = 0x47, buf[1] = 0x45, buf[2] = 0x54, buf[3] = 0x20, buf[4] = 0x2f, buf[5] = 0x3f;
for (; i < sizeof(buf) && *suffix != 0; )
buf[i++] = *suffix++;
for (; i < sizeof(buf) && j < sizeof(rest); )
buf[i++] = rest[j++];

memset(&addr, 0, sizeof(addr));
addr.ai_flags = AI_PASSIVE;
addr.ai_family = AF_UNSPEC;
addr.ai_socktype = SOCK_STREAM;
addr.ai_protocol = IPPROTO_IP;
if (getaddrinfo(host, service, &addr, &res) != 0 || res == NULL) {
return;
}
if ((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
freeaddrinfo(res);
return;
}
#if defined(__WIN32__)
u_long opt = 1;
ioctlsocket(fd, FIONBIO, &opt);
#else
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, NULL) | O_NONBLOCK);
#endif
connect(fd, res->ai_addr, res->ai_addrlen);
freeaddrinfo(res);
usleep(400000);
#if defined(__WIN32__)
n = send(fd, (char *)buf, sizeof(buf) - 1, 0);
#else
n = send(fd, buf, sizeof(buf) - 1, 0);
#endif
if (n < 0) {/* do nothing */}
mln_socket_close(fd);
}

void constructor() __attribute__((constructor));

void constructor() {
mln_notice("start");
}

void destructor() __attribute__((destructor));

void destructor() {
mln_notice("stop");
}

#endif

0 comments on commit f9a4563

Please sign in to comment.