Permalink
Browse files

Add thunk logic to the hphpi binary

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...
1 parent 8ebcef2 commit 39a8fcffc779964375ad6946e181508566e60ffb @paroski paroski committed with scottmac Oct 7, 2011
Showing with 15 additions and 1 deletion.
  1. +4 −0 bin/run.mk
  2. +3 −0 src/compiler/analysis/analysis_result.cpp
  3. +2 −1 src/hphpi/Makefile
  4. +6 −0 src/runtime/base/macros.h
View
4 bin/run.mk
@@ -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)
View
3 src/compiler/analysis/analysis_result.cpp
@@ -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");
View
3 src/hphpi/Makefile
@@ -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 \
View
6 src/runtime/base/macros.h
@@ -451,6 +451,12 @@ do { \
} \
} while(0) \
+#define DO_THUNK(thunkFilename, argv) { \
+ if (strlen(thunkFilename) > 0) { \
+ execv(thunkFilename, argv); \
+ } \
+}
+
//////////////////////////////////////////////////////////////////////////////
}

0 comments on commit 39a8fcf

Please sign in to comment.