GitLab will be upgraded to the 12.10.14-ce.0 on 28 Sept 2020 at 2.00pm (AEDT) to 2.30pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

runtime_aarch64_sysv.c 1.91 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2017 The Australian National University
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

15 16 17 18 19 20 21 22 23 24 25 26
#ifdef __linux__
// RTLD_DEFAULT is not defined in POSIX. Linux gcc does not define it unless
// _GNU_SOURCE is also defined.
#define _GNU_SOURCE
#endif // __linux__

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <pthread.h>

27 28 29 30 31 32 33 34 35 36
/*
 *         .type   mu_tls,@object          // @mu_tls
        .section        .tbss,"awT",@nobits
        .globl  mu_tls
        .p2align        3
mu_tls:
        .xword  0
        .size   mu_tls, 8

 * */
37 38
__thread void* mu_tls;

39 40


41 42
void set_thread_local(void* thread) {
    // printf("Thread%p: setting mu_tls to %p\n", (void*) pthread_self(), thread);
43 44 45 46 47 48
    //MRS X8, TPIDR_EL0
    //ADD X8, X8, :tprel_hi12:mu_tls
    //ADD X8, X8, :tprel_lo12_nc:mu_tls
    //STR X0, [X8]


49 50 51 52 53
    mu_tls = thread;
}

void* muentry_get_thread_local() {
//    printf("Thread%p: getting mu_tls as %p\n", (void*) pthread_self(), mu_tls);
54 55 56 57 58 59 60
    /*
 * //MRS X8, TPIDR_EL0
    //ADD X8, X8, :tprel_hi12:mu_tls
    //ADD X8, X8, :tprel_lo12_nc:mu_tls
    //LDR X0, [X8]
     *
     * */
61 62 63 64
    return mu_tls;
}

void* resolve_symbol(const char* sym) {
65 66 67
    // MOV X1, X0
    // MOV X0, XZR
    // B dlsym
68 69
    // printf("%s\n", sym);
    return dlsym(RTLD_DEFAULT, sym);
70 71 72 73 74 75 76 77 78 79
}

int32_t mu_retval;

void muentry_set_retval(int32_t x) {
    mu_retval = x;
}

int32_t c_check_result() {
    return mu_retval;
80
}