Skip to content

Commit

Permalink
Add thunk logic to the hphpi binary
Browse files Browse the repository at this point in the history
Summary:
This diff adds thunk logic so that we can make the hphpi binary redirect
to another binary via execv(). The idea here is that we can set a symlink
"/.hphpi-thunk" on individual machines to make hphpi redirect to a different
binary.

Note that the thunk will only be triggered for the hphpi binary, and only
if "/.hphpi-thunk" exists in the filesystem. Other binaries produced by
hphpc will not trigger the thunk and will continue to behave the same as
before.

Blame Rev:

Reviewers: je, kma, mwilliams, qigao, oyamauchi

CC:

Test Plan:
fast_tests
slow_tests
Verify the thunk is triggered for the hphpi binary
Vierfy the thunk is not triggered for other binaries
Build www and browse the site

Revert Plan:

Differential Revision: 340844
  • Loading branch information
paroski authored and macvicar committed Oct 18, 2011
1 parent 8ebcef2 commit 39a8fcf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bin/run.mk
Expand Up @@ -22,6 +22,10 @@ endif

-include sep_extensions.mk

ifdef HPHPI_THUNK
CPPFLAGS += -DTHUNK_FILENAME='"/.hphpi-thunk"'
endif

CPPFLAGS += -I. $(SEP_EXTENSION_INCLUDE_PATHS)
LIBS = $(SEP_EXTENSION_LIBS) $(HPHP_LIB)/libhphp_runtime.a $(ALL_LIBS)

Expand Down
3 changes: 3 additions & 0 deletions src/compiler/analysis/analysis_result.cpp
Expand Up @@ -4571,6 +4571,9 @@ void AnalysisResult::outputCPPMain() {
cg_printf("\n");
cg_printf("#ifndef HPHP_BUILD_LIBRARY\n");
cg_indentBegin("int main(int argc, char** argv) {\n");
cg_indentBegin("#ifdef THUNK_FILENAME\n");
cg_printf("DO_THUNK(THUNK_FILENAME, argv);\n");
cg_indentEnd("#endif\n");
cg_printf("return HPHP::execute_program(argc, argv);\n");
cg_indentEnd("}\n");
cg_printf("#endif\n");
Expand Down
3 changes: 2 additions & 1 deletion src/hphpi/Makefile
Expand Up @@ -15,7 +15,8 @@ all: $(HPHPI)

$(HPHPI): $(HPHP) $(PHP_FILES)
@echo "Compiling hphpi..."
$(V)$(if $(OUT_TOP),HPHP_LIB=$(LIB_DIR)) $(HPHP) \
$(V)$(if $(OUT_TOP),HPHP_LIB=$(LIB_DIR)) HPHPI_THUNK=1 \
$(HPHP) \
-t cpp -f exe --input-dir . \
-i $(PHP_FILES) -o $(OUT_DIR)gen \
-vEnableEval=2 --log=1 \
Expand Down
6 changes: 6 additions & 0 deletions src/runtime/base/macros.h
Expand Up @@ -451,6 +451,12 @@ do { \
} \
} while(0) \

#define DO_THUNK(thunkFilename, argv) { \
if (strlen(thunkFilename) > 0) { \
execv(thunkFilename, argv); \
} \
}

//////////////////////////////////////////////////////////////////////////////
}

Expand Down

0 comments on commit 39a8fcf

Please sign in to comment.