Skip to content

Commit

Permalink
Added test for arguments on stack.
Browse files Browse the repository at this point in the history
  • Loading branch information
yugr committed Mar 20, 2024
1 parent 811e162 commit 887426c
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scripts/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ tests/multiple-dlopens-3/run.sh $ARCH
if ! echo "$ARCH" | grep -q powerpc; then
tests/many-functions/run.sh $ARCH
fi
if ! echo "$ARCH" | grep -q 'mips64\|powerpc'; then
# FIXME: enable for all platforms !
tests/stack-args/run.sh $ARCH
fi
31 changes: 31 additions & 0 deletions tests/stack-args/interposed.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2024 Yury Gribov
*
* The MIT License (MIT)
*
* Use of this source code is governed by MIT license that can be
* found in the LICENSE.txt file.
*/

#include <stdio.h>
#include "interposed.h"

__attribute__((visibility("default")))
void foo(int x0, int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10, int x11, int x12, int x13, int x14, int x15) {
printf("%d ", x0);
printf("%d ", x1);
printf("%d ", x2);
printf("%d ", x3);
printf("%d ", x4);
printf("%d ", x5);
printf("%d ", x6);
printf("%d ", x7);
printf("%d ", x8);
printf("%d ", x9);
printf("%d ", x10);
printf("%d ", x11);
printf("%d ", x12);
printf("%d ", x13);
printf("%d ", x14);
printf("%d\n", x15);
}
15 changes: 15 additions & 0 deletions tests/stack-args/interposed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2024 Yury Gribov
*
* The MIT License (MIT)
*
* Use of this source code is governed by MIT license that can be
* found in the LICENSE.txt file.
*/

#ifndef INTERPOSED_H
#define INTERPOSED_H

extern void foo(int x0, int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10, int x11, int x12, int x13, int x14, int x15);

#endif
15 changes: 15 additions & 0 deletions tests/stack-args/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2024 Yury Gribov
*
* The MIT License (MIT)
*
* Use of this source code is governed by MIT license that can be
* found in the LICENSE.txt file.
*/

#include "interposed.h"

int main() {
foo(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
return 0;
}
41 changes: 41 additions & 0 deletions tests/stack-args/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh

# Copyright 2024 Yury Gribov
#
# The MIT License (MIT)
#
# Use of this source code is governed by MIT license that can be
# found in the LICENSE.txt file.

# This is a simple test for Implib.so functionality.
# Run it like
# ./run.sh ARCH
# where ARCH stands for any supported arch (arm, x86_64, etc., see `implib-gen -h' for full list).
# Note that you may need to install qemu-user for respective platform
# (i386 also needs gcc-multilib).

set -eu

cd $(dirname $0)

if test -n "${1:-}"; then
ARCH="$1"
fi

. ../common.sh

CFLAGS="-g -O2 $CFLAGS"

# Build shlib to test against
$CC $CFLAGS -shared -fPIC interposed.c -o libinterposed.so

# Prepare implib
${PYTHON:-} ../../implib-gen.py -q --target $TARGET libinterposed.so

# Build app
$CC $CFLAGS main.c libinterposed.so.tramp.S libinterposed.so.init.c $LIBS

LD_LIBRARY_PATH=.:${LD_LIBRARY_PATH:-} $INTERP ./a.out > a.out.log
diff test.ref a.out.log

echo SUCCESS
1 change: 1 addition & 0 deletions tests/stack-args/test.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 comments on commit 887426c

Please sign in to comment.