Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory access issue #1444

Closed
yuhsien-chen opened this issue Mar 29, 2017 · 3 comments
Closed

memory access issue #1444

yuhsien-chen opened this issue Mar 29, 2017 · 3 comments

Comments

@yuhsien-chen
Copy link

yuhsien-chen commented Mar 29, 2017

Hi, I encountered a problem.
When I'm using static library, I store the pointer to function into array.
I meet the situation is when I use loop to traversal it, the dump result was fault.
But, when I enumerate it by index, the result is correct.
like this.

// failed address
a[0] = 0xa8098
a[1] = 0xa8068
a[2] = 0xa8038
a[3] = 0xa8008
a[4] = 0xa7fd8

// expected address
a[0] = 0x40129098
a[1] = 0x40129068
a[2] = 0x40129038
a[3] = 0x40129008
a[4] = 0x40128fd8

My code would like this.

// test.h for prebuilt library libtest.a
extern const testTypeI func1;
extern const testTypeI func2;
extern const testTypeI func3;
extern const testTypeI func4;
extern const testTypeI func5;

// mysdk.h for seperated function define
void some_func(void);

// mysdk.c for seperated function implement
static testTypeI* FUNC[] = {
    &func1,
    &func2,
    &func3,
    &func4,
    &func5
};

void some_func(void) {
    // will dump failure result
    for(i = 0;i < 5;i++) {
        IMSG("FUNC[%d] = %p", i, (void *)FUNC[i]);
    }

    IMSG("===================");

    // will dump correct result
    IMSG("FUNC[0] = %p", (void *)FUNC[0]);
    IMSG("FUNC[1] = %p", (void *)FUNC[1]);
    IMSG("FUNC[2] = %p", (void *)FUNC[2]);
    IMSG("FUNC[3] = %p", (void *)FUNC[3]);
    IMSG("FUNC[4] = %p", (void *)FUNC[4]);
}

// myTA.c for TA command entry
static TEE_Result some_test(uint32_t param_types,
							TEE_Param params[4])
{
    // call func
    some_func();

    return TEE_SUCCESS;
}

By the way, when I combine mysdk.c functions and array definition into myTA.c, it will correct. Why?
Any advice will be appreciated.

@jforissier
Copy link
Contributor

Hi @yuhsien-chen,

It looks like it could be a relocation problem. Are you running with the patch I proposed here: #1399 (comment)? If so, please try the latest optee_os instead (or cherry-pick commit ef53fb0) because my first proposal was incorrect.

@yuhsien-chen
Copy link
Author

@jforissier Thanks, I'll try it soon and report the result.

@yuhsien-chen
Copy link
Author

@jforissier Thanks.
It works fine.
Now I can get correct address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants