Commit f94bff79 authored by Russ Cox's avatar Russ Cox

cmd/dist: zero output variables on entry to goc2c functions

Zeroing the outputs makes sure that during function calls
in those functions we do not let the garbage collector
treat uninitialized values as pointers.

The garbage collector may still see uninitialized values
if a preemption occurs during the function prologue,
before the zeroing has had a chance to run.

This reduces the number of 'bad pointer' messages when
that runtime check is enabled, but it doesn't fix all of them,
so the check is still disabled.

It will also avoid leaks, although I doubt any of these were
particularly serious.

LGTM=iant, khr
R=iant, khr
CC=golang-codereviews
https://golang.org/cl/80850044
parent ef3c0e7e
......@@ -524,6 +524,7 @@ write_6g_func_header(char *package, char *name, struct params *params,
int paramwid, struct params *rets)
{
int first, n;
struct params *p;
bwritef(output, "void\n");
if(!contains(name, "·"))
......@@ -546,6 +547,24 @@ write_6g_func_header(char *package, char *name, struct params *params,
write_params(rets, &first);
bwritef(output, ")\n{\n");
for (p = rets; p != nil; p = p->next) {
if(streq(p->name, "..."))
continue;
if(streq(p->type, "Slice"))
bwritef(output, "\t%s.array = 0;\n\t%s.len = 0;\n\t%s.cap = 0;\n", p->name, p->name, p->name);
else if(streq(p->type, "String"))
bwritef(output, "\t%s.str = 0;\n\t%s.len = 0;\n", p->name, p->name);
else if(streq(p->type, "Eface"))
bwritef(output, "\t%s.type = 0;\n\t%s.data = 0;\n", p->name, p->name);
else if(streq(p->type, "Iface"))
bwritef(output, "\t%s.tab = 0;\n\t%s.data = 0;\n", p->name, p->name);
else if(streq(p->type, "Complex128"))
bwritef(output, "\t%s.real = 0;\n\t%s.imag = 0;\n", p->name, p->name);
else
bwritef(output, "\t%s = 0;\n", p->name);
bwritef(output, "\tFLUSH(&%s);\n", p->name);
}
}
/* Write a 6g function trailer. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment