Skip to content

Commit

Permalink
Apply Enclose.IO hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
pmq20 committed Aug 23, 2020
1 parent 3228d2f commit a4ab86d
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 1 deletion.
7 changes: 7 additions & 0 deletions node/deps/uv/include/uv.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ extern "C" {
#error "Define either BUILDING_UV_SHARED or USING_UV_SHARED, not both."
#endif

// --------- [Enclose.IO Hack start] ---------
#ifndef __cplusplus
#ifndef _WIN32
#include "enclose_io.h"
#endif
#endif
// --------- [Enclose.IO Hack end] ---------
#ifdef _WIN32
/* Windows - set up dll import/export decorators. */
# if defined(BUILDING_UV_SHARED)
Expand Down
9 changes: 9 additions & 0 deletions node/deps/uv/src/unix/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,15 @@ static int uv__fs_statx(int fd,
int mode;
int rc;

// --------- [Enclose.IO Hack start] ---------
//roytan-hack-start
//for ubuntu 18.04 or debian
if (no_statx != 1) {
no_statx = 1;
}
//roytan-hack-end
// --------- [Enclose.IO Hack end] ---------

if (uv__load_relaxed(&no_statx))
return UV_ENOSYS;

Expand Down
6 changes: 6 additions & 0 deletions node/deps/uv/src/win/dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
#include "uv.h"
#include "internal.h"

// --------- [Enclose.IO Hack start] ---------
#ifndef __cplusplus
#define ENCLOSE_IO_WINAPI_H_VD6Y96RT
#include "enclose_io.h"
#endif
// --------- [Enclose.IO Hack end] ---------
static int uv__dlerror(uv_lib_t* lib, const char* filename, DWORD errorno);


Expand Down
5 changes: 5 additions & 0 deletions node/deps/uv/src/win/fs-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ int uv_fs_event_start(uv_fs_event_t* handle,
handle->short_filew = NULL;
}

// --------- [Enclose.IO Hack start] ---------
if (pathw == handle->dirw) {
handle->dirw = NULL;
}
// --------- [Enclose.IO Hack end] ---------
uv__free(pathw);

if (handle->dir_handle != INVALID_HANDLE_VALUE) {
Expand Down
6 changes: 6 additions & 0 deletions node/deps/uv/src/win/handle-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
#include "uv.h"
#include "internal.h"

// --------- [Enclose.IO Hack start] ---------
#ifndef __cplusplus
#define ENCLOSE_IO_WINAPI_H_VD6Y96RT
#include "enclose_io.h"
#endif
// --------- [Enclose.IO Hack end] ---------

#define DECREASE_ACTIVE_COUNT(loop, handle) \
do { \
Expand Down
6 changes: 6 additions & 0 deletions node/deps/uv/src/win/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
#include <userenv.h>
#include <math.h>

// --------- [Enclose.IO Hack start] ---------
#ifndef __cplusplus
#define ENCLOSE_IO_WINAPI_H_VD6Y96RT
#include "enclose_io.h"
#endif
// --------- [Enclose.IO Hack end] ---------
/*
* Max title length; the only thing MSDN tells us about the maximum length
* of the console title is that it is smaller than 64K. However in practice
Expand Down
2 changes: 2 additions & 0 deletions node/deps/uv/uv.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
'include_dirs': [
'include',
'src/',
'../libsquash/include',
'../libsquash/sample',
],
'defines': [
'<@(shared_mac_defines)',
Expand Down
6 changes: 6 additions & 0 deletions node/lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,12 @@ Module._extensions['.node'] = function(module, filename) {
manifest.assertIntegrity(moduleURL, content);
}
// Be aware this doesn't use `content`
// --------- [Enclose.IO Hack start] ---------
if (filename && filename.indexOf && 0 === filename.indexOf('/__enclose_io_memfs__')) {
var file_extracted = process.__enclose_io_memfs__extract(filename);
return process.dlopen(module, file_extracted);
}
// --------- [Enclose.IO Hack end] ---------
return process.dlopen(module, path.toNamespacedPath(filename));
};

Expand Down
14 changes: 13 additions & 1 deletion node/node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@

'include_dirs': [
'src',
'deps/v8/include'
'deps/v8/include',
'deps/libsquash/include',
'deps/libsquash/sample',
'deps/libautoupdate/include'
],

'sources': [
Expand All @@ -362,6 +365,8 @@
'dependencies': [
'deps/histogram/histogram.gyp:histogram',
'deps/uvwasi/uvwasi.gyp:uvwasi',
'deps/libsquash/enclose_io_libsquash.gyp:enclose_io_libsquash',
'deps/libautoupdate/libautoupdate.gyp:libautoupdate',
],

'msvs_settings': {
Expand Down Expand Up @@ -540,11 +545,16 @@

'include_dirs': [
'src',
'deps/libsquash/include',
'deps/libsquash/sample',
'deps/libautoupdate/include',
'<(SHARED_INTERMEDIATE_DIR)' # for node_natives.h
],
'dependencies': [
'deps/histogram/histogram.gyp:histogram',
'deps/uvwasi/uvwasi.gyp:uvwasi',
'deps/libsquash/enclose_io_libsquash.gyp:enclose_io_libsquash',
'deps/libautoupdate/libautoupdate.gyp:libautoupdate',
],

'sources': [
Expand Down Expand Up @@ -1132,6 +1142,8 @@
'<(node_lib_target_name)',
'deps/histogram/histogram.gyp:histogram',
'deps/uvwasi/uvwasi.gyp:uvwasi',
'deps/libsquash/enclose_io_libsquash.gyp:enclose_io_libsquash',
'deps/libautoupdate/libautoupdate.gyp:libautoupdate',
'node_dtrace_header',
'node_dtrace_ustack',
'node_dtrace_provider',
Expand Down
1 change: 1 addition & 0 deletions node/node.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'<(_msvs_precompiled_header)',
'<(_msvs_precompiled_source)',
],
'libraries': [ '-lpsapi.lib', '-lOle32.lib' ]
}, { # POSIX
'defines': [ '__POSIX__' ],
}],
Expand Down
112 changes: 112 additions & 0 deletions node/src/node_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
#include "node.h"
#include <cstdio>

// --------- [Enclose.IO Hack start] ---------
extern "C" {
#include "enclose_io.h"
#include "autoupdate.h"
}
// --------- [Enclose.IO Hack end] ---------
#ifdef _WIN32
#include <windows.h>
#include <VersionHelpers.h>
Expand All @@ -32,6 +38,54 @@
#define SKIP_CHECK_VALUE "1"

int wmain(int argc, wchar_t* wargv[]) {
// --------- [Enclose.IO Hack start] ---------
int autoupdate_result;
sqfs_err enclose_io_ret;
int new_argc;
wchar_t **new_argv;

#if ENCLOSE_IO_AUTO_UPDATE
autoupdate_result = autoupdate(
argc,
wargv,
ENCLOSE_IO_AUTO_UPDATE_URL_Host,
ENCLOSE_IO_AUTO_UPDATE_URL_Port,
ENCLOSE_IO_AUTO_UPDATE_URL_Path,
ENCLOSE_IO_AUTO_UPDATE_BASE,
0
);
#endif

enclose_io_ret = squash_start();
assert(SQFS_OK == enclose_io_ret);
enclose_io_fs = (sqfs *)calloc(sizeof(sqfs), 1);
assert(NULL != enclose_io_fs);
enclose_io_ret = sqfs_open_image(enclose_io_fs, enclose_io_memfs, 0);
assert(SQFS_OK == enclose_io_ret);
#ifdef ENCLOSE_IO_ROOT_ALIAS
enclose_io_fs->root_alias = ENCLOSE_IO_ROOT_ALIAS;
#endif
#ifdef ENCLOSE_IO_ROOT_ALIAS2
enclose_io_fs->root_alias2 = ENCLOSE_IO_ROOT_ALIAS2;
#endif

#ifdef ENCLOSE_IO_ENTRANCE
new_argc = argc;
new_argv = wargv;
if (NULL == getenv("ENCLOSE_IO_USE_ORIGINAL_NODE")) {
new_argv = (wchar_t **)malloc( (argc + 1) * sizeof(wchar_t *));
assert(new_argv);
new_argv[0] = wargv[0];
new_argv[1] = ENCLOSE_IO_ENTRANCE;
for (size_t i = 1; i < argc; ++i) {
new_argv[2 + i - 1] = wargv[i];
}
new_argc = argc + 1;
}
argc = new_argc;
wargv = new_argv;
#endif
// --------- [Enclose.IO Hack end] ---------
// Windows Server 2012 (not R2) is supported until 10/10/2023, so we allow it
// to run in the experimental support tier.
char buf[SKIP_CHECK_SIZE + 1];
Expand Down Expand Up @@ -134,6 +188,64 @@ int main(int argc, char* argv[]) {
}
}
#endif
// --------- [Enclose.IO Hack start] ---------
int autoupdate_result;
sqfs_err enclose_io_ret;
char *argv_memory;
int new_argc;
char **new_argv;

#if ENCLOSE_IO_AUTO_UPDATE
autoupdate_result = autoupdate(
argc,
argv,
ENCLOSE_IO_AUTO_UPDATE_URL_Host,
ENCLOSE_IO_AUTO_UPDATE_URL_Port,
ENCLOSE_IO_AUTO_UPDATE_URL_Path,
ENCLOSE_IO_AUTO_UPDATE_BASE,
0
);
#endif

enclose_io_ret = squash_start();
assert(SQFS_OK == enclose_io_ret);
enclose_io_fs = (sqfs *)malloc(sizeof(sqfs));
assert(NULL != enclose_io_fs);
memset(enclose_io_fs, 0, sizeof(sqfs));
enclose_io_ret = sqfs_open_image(enclose_io_fs, enclose_io_memfs, 0);
assert(SQFS_OK == enclose_io_ret);

#ifdef ENCLOSE_IO_ENTRANCE
argv_memory = NULL;
new_argc = argc;
new_argv = argv;
if (NULL == getenv("ENCLOSE_IO_USE_ORIGINAL_NODE")) {
new_argv = (char **)malloc( (argc + 1) * sizeof(char *));
assert(new_argv);
new_argv[0] = argv[0];
new_argv[1] = ENCLOSE_IO_ENTRANCE;
for (size_t i = 1; i < argc; ++i) {
new_argv[2 + i - 1] = argv[i];
}
new_argc = argc + 1;
/* argv memory should be adjacent. */
size_t total_argv_size = 0;
for (size_t i = 0; i < new_argc; ++i) {
total_argv_size += strlen(new_argv[i]) + 1;
}
argv_memory = (char *)malloc( (total_argv_size) * sizeof(char));
assert(argv_memory);
for (size_t i = 0; i < new_argc; ++i) {
memcpy(argv_memory, new_argv[i], strlen(new_argv[i]) + 1);
new_argv[i] = argv_memory;
argv_memory += strlen(new_argv[i]) + 1;
}
assert(argv_memory - new_argv[0] == total_argv_size);
}
argc = new_argc;
argv = new_argv;
#endif
// --------- [Enclose.IO Hack end] ---------
// Disable stdio buffering, it interacts poorly with printf()
// calls elsewhere in the program (e.g., any logging from V8.)
setvbuf(stdout, nullptr, _IONBF, 0);
Expand Down
Binary file modified node/src/res/node.ico
Binary file not shown.

0 comments on commit a4ab86d

Please sign in to comment.