Skip to content

Instantly share code, notes, and snippets.

@krono
Created July 23, 2019 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krono/90be33d3f30c105b7bdddaae84587ddd to your computer and use it in GitHub Desktop.
Save krono/90be33d3f30c105b7bdddaae84587ddd to your computer and use it in GitHub Desktop.
Test the pinning problem
from rpython.rtyper.lltypesystem import rffi
from rpython.translator.tool.cbuild import ExternalCompilationInfo
eci = ExternalCompilationInfo(
post_include_bits=["""
#ifndef __pinningtest_h
#define __pinningtest_h
#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __attribute__((__visibility__("default")))
#endif
#ifdef __cplusplus
extern "C" {
#endif
DLLEXPORT int PinningTest(const char* first, const char* second);
#ifdef __cplusplus
}
#endif
#endif"""],
separate_module_sources=[r"""
#include <stdio.h>
int PinningTest(const char* first, const char* second) {
fprintf(stderr, "First arg: '%s'\nSecond arg: '%s'\n", first, second);
return 0;
}
"""]
)
ll_PinningTest = rffi.llexternal('PinningTest', [rffi.CCHARP, rffi.CCHARP],
rffi.INT, compilation_info=eci)
def entry_point(args):
print "here i am"
A = 'foo'
ll_PinningTest(A, '0')
print "GOT HERE A"
B = 'barf'
ll_PinningTest(B, '1')
print "GOT HERE B1"
print "me gone"
return 0
def target(driver, args):
driver.config.translation.set(gcrootfinder="shadowstack")
return entry_point, None, None
def jitpolicy(self):
from rpython.jit.codewriter.policy import JitPolicy
return JitPolicy()
#
# for convenience
if __name__ == '__main__':
import sys
from rpython.rlib import objectmodel
from rpython.config.translationoption import get_combined_translation_config
assert not objectmodel.we_are_translated()
from rpython.translator.driver import TranslationDriver
driver = TranslationDriver()
driver.config = get_combined_translation_config(translating=False)
if "--" in sys.argv:
idx = sys.argv.index("--")
configargs, args = sys.argv[0:idx], sys.argv[idx:]
else:
configargs, args = [], sys.argv
f, _, _ = target(driver, configargs)
try:
sys.exit(f(args))
except SystemExit:
pass
except:
if hasattr(sys, 'ps1') or not sys.stderr.isatty():
# we are in interactive mode or we don't have a tty-like
# device, so we call the default hook
sys.__excepthook__(type, value, tb)
else:
import pdb, traceback
_type, value, tb = sys.exc_info()
traceback.print_exception(_type, value, tb)
pdb.post_mortem(tb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment