소스 검색

* Better error reporting and argument passing from/to the bytecode.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/research@2287 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 16 년 전
부모
커밋
36f563a01c
2개의 변경된 파일67개의 추가작업 그리고 37개의 파일을 삭제
  1. +14
    -7
      2008-displacement/main-cpushare
  2. +53
    -30
      2008-displacement/main.c

+ 14
- 7
2008-displacement/main-cpushare 파일 보기

@@ -17,6 +17,7 @@ if len(sys.argv) < 4:
print 'Usage: %s <buy_order.cpu> -<mode> [image list]' % (sys.argv[0],)
sys.exit(-1)
mode = sys.argv[2][1]
done = 0
source = sys.argv[3:]
result = [False] * len(source)

@@ -34,13 +35,19 @@ class buy_state_machine_class(object):
def start(self):
global todo, source
if todo >= len(source):
return # We're finished... FIXME: a process is stuck
return # We're finished... FIXME: is the transaction kept stuck?
self.index = todo
todo += 1
gd.gdMaxColors = 256 * 256 * 256
im = gd.image(source[self.index])
# Send mode
self.protocol.sendString(PROTO_SECCOMP_FORWARD + mode)
# Send argument count
self.protocol.sendString(PROTO_SECCOMP_FORWARD + chr(3))
# Send arguments
msg = chr(3)
msg += "bytecode\0"
msg += "-1\0"
msg += source[self.index] + "\0"
self.protocol.sendString(PROTO_SECCOMP_FORWARD + msg)
# Send image size
(self.w, self.h) = (w, h) = im.size()
print 'sending %s (%dx%d)' % (source[self.index], w, h)
@@ -64,13 +71,13 @@ class buy_state_machine_class(object):
self.answer += data
if ord(self.answer[-1]) != 0:
return
global result
global done, result
result[self.index] = self.answer[:-1]
print self.answer[:-1],
self.protocol.sendString(PROTO_SECCOMP_SUCCESS)
# the PROTO_SECCOMP_SUCCESS probably won't have a chance
# to go out but it doesn't matter because we'll disconnect
# not just this but all other seccomp state machines too
done += 1
if done < len(source):
return
from twisted.internet import reactor
reactor.stop()
elif control == PROTO_SECCOMP_SIGNAL:


+ 53
- 30
2008-displacement/main.c 파일 보기

@@ -39,14 +39,26 @@ void sighandler(int signal)

void bytecode(unsigned char * mem, int heap_size, int stack_size)
{
char mode[] = "-0";
char *argv[] = { "program", mode, "arg" };
char args[10][1024];
char *argv[] = { args[0], args[1], args[2], args[3], args[4],
args[5], args[6], args[7], args[8], args[9] };
int i, argc;
char c;

if(sys_read(0, mode + 1, 1) != 1)
if(sys_read(0, &c, 1) != 1)
sys_exit(-5);
argc = (unsigned char)c;

for(i = 0; i < argc; i++)
{
char *p = argv[i];
do
if(sys_read(0, p, 1) != 1)
sys_exit(-5);
while(*p++);
}

main(sizeof(argv)/sizeof(*argv), argv);
main(argc, argv);

c = 0;
if(sys_write(1, &c, 1) != 1)
@@ -80,10 +92,8 @@ static int myatoi(const char *str)
sys_write(1, b + 1, (int)(buf + 127 - b)); \
} while(0)

static void msg(const char *f, ...)
static void out(FILE *stream, const char *f, va_list args)
{
va_list args;
va_start(args, f);
#ifdef BYTECODE
static char const *hex2char = "0123456789abcdef";

@@ -141,22 +151,18 @@ static void msg(const char *f, ...)
}
else if(f[0] == 'g')
{
double g = va_arg(args, double), h = 9.9f;
int i;
if(g < 0.f)
{
sys_write(1, "-", 1);
g = -g;
}
double g = va_arg(args, double), h = 0.0000001;
int i = g;
WRITE_INT(i, 10);
for(i = 0; i < 7; i++)
{
sys_write(1, hex2char + (int)g, 1);
if(i == 0)
sys_write(1, ".", 1);
g = (g - (int)g) * 10;
h = h / 10.f;
h *= 10;
if(g < h)
break;
if(i == 0)
sys_write(1, ".", 1);
sys_write(1, hex2char + (int)g, 1);
}
}
else if(f[0] == 'p')
@@ -196,9 +202,24 @@ static void msg(const char *f, ...)
}
}
#else
vprintf(f, args);
fflush(stdout);
vfprintf(stream, f, args);
fflush(stream);
#endif
}

static void err(const char *f, ...)
{
va_list args;
va_start(args, f);
out(stderr, f, args);
va_end(args);
}

static void msg(const char *f, ...)
{
va_list args;
va_start(args, f);
out(stdout, f, args);
va_end(args);
}

@@ -752,7 +773,7 @@ static double *dbs(double const *src, double const *orig,
changes++;
}

fprintf(stderr, "did %i changes\n", changes);
err("did %i changes\n", changes);

if(changes == 0)
break;
@@ -828,13 +849,15 @@ static double *merge(double const *im1, double const *im2, double t)

static void usage(char *argv[])
{
fprintf(stderr, "Usage: %s <mode> [ARGS...]\n", argv[0]);
fprintf(stderr, "Allowed modes:\n");
fprintf(stderr, " -1 <src> raster FS displacement study on src\n");
fprintf(stderr, " -2 <src1> <src2> raster FS displacement study on blends of src1 and src2\n");
fprintf(stderr, " -3 <src> quick (a,b,c,d) ED kernel analysis on src\n");
fprintf(stderr, " -4 <src> exhaustive (a,b,c,d) ED kernel analysis on src\n");
fprintf(stderr, " -5 <src> exhaustive displacement study on src\n");
msg("Usage: %s <mode> [ARGS...]\n", argv[0]);
msg("Allowed modes:\n");
msg(" -1 <src> raster FS displacement study on src\n");
msg(" -2 <src1> <src2> raster FS displacement study on blends of src1 and src2\n");
msg(" -3 <src> quick (a,b,c,d) ED kernel analysis on src\n");
msg(" -4 <src> exhaustive (a,b,c,d) ED kernel analysis on src\n");
msg(" -5 <src> exhaustive displacement study on src\n");
msg(" -6 <src> restrained (a,b,c,d) ED kernel analysis on src\n");
msg(" -7 <src> restrained displacement study on src\n");
}

int main(int argc, char *argv[])
@@ -844,14 +867,14 @@ int main(int argc, char *argv[])

if(argc < 2)
{
fprintf(stderr, "%s: too few arguments\n", argv[0]);
err("%s: too few arguments\n", argv[0]);
usage(argv);
return EXIT_FAILURE;
}

if(argv[1][0] != '-' || !(mode = atoi(argv[1] + 1)))
{
fprintf(stderr, "%s: invalid mode `%s'\n", argv[0], argv[1]);
err("%s: invalid mode `%s'\n", argv[0], argv[1]);
usage(argv);
return EXIT_FAILURE;
}


불러오는 중...
취소
저장