Skip to content

Commit d3148bb

Browse files
Merge the follow-up fixes for CI after 36d4828
The libraries linked twice keep their order again, so zlib links, with the runtime once more at the end. An abstract function's RETURN body loads again, a binary op past the last one is refused, and the fuzz target leaves out the std's List recursion. ProcessConcurrentPipeInheritance runs its checks on Linux at last, and GenerationalLargePressure churns on a stack that never held its buffers.
2 parents 36d4828 + 7fdbeb6 commit d3148bb

9 files changed

Lines changed: 58 additions & 14 deletions

File tree

‎Changes.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
libhxcpp 6.0.0 (unreleased)
33
------------------------------------------------------------
44

5-
* Fixed programs that use sys.ssl without sockets failing to link on Linux with an undefined reference to hxcpp_alloc_kind: hxcpp_std, linked a second time after hxcpp_ssl, came after the runtime's second copy. Libraries linked twice are now added again last group first, so the runtime's copy follows the libraries that call into it
5+
* Fixed programs that use sys.ssl without sockets failing to link on Linux with an undefined reference to hxcpp_alloc_kind: hxcpp_std, linked a second time after hxcpp_ssl, came after the runtime's second copy. The runtime is linked once more after all the libraries linked twice, which keep their order
66
* Fixed closing, reading or polling a socket handle that a library made in stock hxcpp's layout, as CrossByte's accept does, reading past the handle: the runtime took its own wrapper's later fields from it, and a close wrote through what followed it in memory. Only the descriptor is read from such a handle, and the runtime's wrapper no longer shares its name, and with it its vtable, with a library's
77
* Fixed a map that two marking threads marked at once being left unable to fold its buckets: the marker counted itself as a walk over the map without a lock, so the count could stay above zero. Marking no longer counts as a walk, as folding only happens after it (follow-up to libhxcpp #204)
88
* Fixed the moving collector storing a moved object's new address as a pointer at an address only 4-byte aligned, which is undefined and which UBSan reported once string data stopped being 8-byte aligned. The address is copied in and out
9+
* Fixed a malformed binary cppia file with an op number past the last op being read as an op, which is undefined. It fails to load with "Unknown op" (libhxcpp #257)
910
* Fixed a malformed cppia file whose function body was some other expression being run as a function. It fails to load with "Function body is not a function" (libhxcpp #257)
1011
* Fixed the fields and text of a Date whose time is not a number, or past what a year in a tm holds, converting the time to whole seconds, which is undefined. Such a time gives the fields of the epoch (libhxcpp #257)
1112
* Fixed the runtime not compiling at API level 500, which Haxe nightly builds use: a cppia module's release function defined only the __run that level 500 removed, and VirtualArray's closures compared arrays with a != that C++20 finds ambiguous

‎src/hx/cppia/CppiaFunction.cpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,10 +1168,12 @@ void CppiaFunction::load(CppiaStream &stream,bool inExpectBody)
11681168
}
11691169
if (inExpectBody)
11701170
{
1171-
// A malformed file can give any expression as the body
1172-
funExpr = dynamic_cast<ScriptCallable *>(createCppiaExpr(stream));
1173-
if (!funExpr)
1171+
// A body is a function, or for an abstract function a bare RETURN. A
1172+
// malformed file can give any other expression
1173+
CppiaExpr *body = createCppiaExpr(stream);
1174+
if (!dynamic_cast<ScriptCallable *>(body) && std::string(body->getName())!="RetVal")
11741175
throw "Function body is not a function";
1176+
funExpr = (ScriptCallable *)body;
11751177
}
11761178
stream.module->creatingFunction = 0;
11771179
}

‎src/hx/cppia/CppiaStream.h‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,28 @@ struct CppiaStream
102102
}
103103

104104

105+
// The largest op: a CppiaOp holds no value past it, so a cast from a
106+
// larger number is undefined
107+
static int maxOp()
108+
{
109+
int result = 0;
110+
#define CPPIA_OP(ident,name,id) if (id>result) result = id;
111+
#include "CppiaOps.inc"
112+
#undef CPPIA_OP
113+
return result;
114+
}
115+
105116
CppiaOp getOp()
106117
{
107118
if (binary)
108-
return (CppiaOp) getInt();
119+
{
120+
static const int limit = maxOp();
121+
// A malformed file can give any number
122+
int op = getInt();
123+
if (op<0 || op>limit)
124+
throw "Unknown op";
125+
return (CppiaOp)op;
126+
}
109127
std::string tok = getAsciiToken();
110128
CppiaOp result = (CppiaOp)opMap[tok];
111129
if (result==0)

‎test/fuzz/Fuzz.hx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ class Fuzz {
356356
static function serializer(b:Bytes) {
357357
if (nesting(b, "aolbqMcwj", "hg") > MAX_NESTING)
358358
return;
359+
// A reference can make a List that holds itself in a few bytes, and the
360+
// std's List.toString has no guard against one: the Unserializer turns
361+
// a class or enum name it was given into a String, so such a List as a
362+
// name prints until the stack overflows, on every target
363+
if (b.toString().indexOf("l") >= 0 && b.toString().indexOf("r") >= 0)
364+
return;
359365
var v1 = attempt(() -> haxe.Unserializer.run(b.toString()));
360366
var s1:String = v1 == null ? null : attempt(() -> serialize(v1));
361367
var v2 = s1 == null ? null : attempt(() -> haxe.Unserializer.run(s1));
445 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wlnri-6hy1h

‎test/regression/GenerationalLargePressure/Main.hx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ class Main {
5151
untyped __cpp__("runJoined({0})", populate);
5252
Gc.run(true);
5353
untyped __cpp__("runJoined({0})", release);
54-
untyped __cpp__("runJoined({0})", churn);
54+
// On the main thread, whose stack never held the buffers: glibc gives a
55+
// new thread the stack of one that ended, and words the populating
56+
// thread left there kept the old buffers alive through the churn
57+
churn();
5558
Sys.stderr().writeString('drops=$drops retained=${Std.int(retained / MB)} MB\n');
5659
Sys.println("large allocation pressure starts collections: " + (drops > 0));
5760
Sys.println("large pressure reclaims released old buffers: " + (retained < 48 * MB));

‎test/regression/ProcessConcurrentPipeInheritance/Main.hx‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,25 @@ static bool hasPipe(int inInode)
8383
closedir(dir);
8484
return found;
8585
}
86+
#else
87+
// The pipe hooks are for Linux, where the program checks for the pipes
88+
static void armHook() { }
89+
static bool hookPaused() { return false; }
90+
static void releaseHook() { }
91+
static ::String hookInode() { return ::String("0"); }
92+
static ::String controlPipe() { return ::String("0"); }
93+
static bool hasPipe(int inInode) { return false; }
8694
#endif
8795
')
8896
class Main {
8997
static function main() {
9098
var args = Sys.args();
91-
#if linux
99+
// Haxe defines no linux, only the C++ build does, so the system is
100+
// asked at run time
92101
if (args.length == 2 && args[0] == "child") {
93102
Sys.print(untyped __cpp__('hasPipe({0})', Std.parseInt(args[1])) ? "inherited" : "excluded");
94103
return;
95104
}
96-
#end
97105
if (Sys.systemName() != "Linux") {
98106
Sys.println("unrelated process pipes excluded from concurrent child: true");
99107
Sys.println("atomic close-on-exec control: true");
@@ -103,7 +111,6 @@ class Main {
103111
}
104112

105113
static function run() {
106-
#if linux
107114
var main = Thread.current();
108115
Thread.create(() -> {
109116
untyped __cpp__('armHook()');
@@ -126,7 +133,6 @@ class Main {
126133
Sys.println("atomic close-on-exec control: " + (child(control) == "excluded"));
127134
untyped __cpp__('releaseHook()');
128135
Thread.readMessage(true);
129-
#end
130136
}
131137

132138
static function child(inode:String):String {

‎tools/hxcpp/BuildTool.hx‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,11 @@ class BuildTool
465465
PathManager.mkdir(mCompiler.mObjDir);
466466

467467
var baseDir = Sys.getCwd();
468-
// Libraries linked a second time, last group first: a later group's
469-
// library can call into an earlier one, as hxcpp_std does into the
470-
// runtime, so the runtime's second copy has to come after the others
468+
// Libraries linked a second time, in the order of their groups, as
469+
// zlib's wrapper comes before the zlib it calls. The runtime goes once
470+
// more after them all: any of them can call into it, as hxcpp_std does
471471
var linkAgain = new Array<String>();
472+
var runtimeAgain:String = null;
472473
for(group in target.mFileGroups)
473474
{
474475
var useCache = CompileCache.hasCache && group.mUseCache;
@@ -706,7 +707,11 @@ class BuildTool
706707
target.mAutoLibs.push(linker.mLastOutName);
707708
// Linux the libraries must be added again if the references were not resolved the firs time
708709
if (group.mAddTwice)
709-
linkAgain.unshift(linker.mLastOutName);
710+
{
711+
linkAgain.push(linker.mLastOutName);
712+
if (group.mId=="runtime")
713+
runtimeAgain = linker.mLastOutName;
714+
}
710715
Profile.pop();
711716
}
712717
else if (nvcc)
@@ -726,6 +731,8 @@ class BuildTool
726731
if (group.mDir!="." && group.mSetImportDir)
727732
Sys.setCwd( baseDir );
728733
}
734+
if (runtimeAgain!=null)
735+
linkAgain.push(runtimeAgain);
729736
for(lib in linkAgain)
730737
target.mLibs.push(lib);
731738

0 commit comments

Comments
 (0)