diff --git a/.github/workflows/MemLayoutGen.yaml b/.github/workflows/MemLayoutGen.yaml new file mode 100644 index 00000000..c233d8f5 --- /dev/null +++ b/.github/workflows/MemLayoutGen.yaml @@ -0,0 +1,42 @@ +name: MemLayout Info Generating +on: + pull_request: +jobs: + test: + runs-on: ${{ matrix.os }} + continue-on-error: true + strategy: + matrix: + version: + - '1.3.1' + - '1.4.2' + - '1.5.3' + - '1.5.4' + - '1.6.1' + os: + - ubuntu-latest + - windows-latest + - macOS-latest + arch: + - x64 + - x86 + exclude: + - os: macOS-latest + arch: x86 + steps: + - name: Set up MinGW + uses: egor-tensin/setup-mingw@v2 + with: + platform: i686 + cc: 1 + if: ${{ matrix.os == 'windows-latest' && matrix.arch == 'x86' }} + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - run: julia .github/workflows/tasklayout/memlayout.jl + - uses: EndBug/add-and-commit@v7 + with: + add: 'src/memlayout' + author_name: GitHub Actions diff --git a/.github/workflows/Testing.yaml b/.github/workflows/Testing.yaml index 8d6d66e7..fa17a364 100644 --- a/.github/workflows/Testing.yaml +++ b/.github/workflows/Testing.yaml @@ -7,7 +7,7 @@ on: jobs: test: runs-on: ${{ matrix.os }} - continue-on-error: ${{ matrix.version == 'nightly' }} + continue-on-error: true # ${{ matrix.version == 'nightly' }} strategy: matrix: version: diff --git a/.github/workflows/tasklayout/memlayout.cpp b/.github/workflows/tasklayout/memlayout.cpp new file mode 100644 index 00000000..6004eb9e --- /dev/null +++ b/.github/workflows/tasklayout/memlayout.cpp @@ -0,0 +1,138 @@ +/** + * linux64: g++ -I $JULIA_HOME/include/julia/ memlayout.cpp -o memlayout + * linux32: apt-get install g++-multilib + * g++ -march=pentium4 -m32 -I $JULIA_HOME/include/julia/ memlayout.cpp -o memlayout + * macOS: g++ -std=c++11 -I $JULIA_APP/Contents/Resources/julia/include/julia/ memlayout.cpp -o memlayout + * win64: g++ -I $JULIA_HOME/include/julia/ memlayout.cpp -o memlayout + * win32: g++ -I $JULIA_HOME/include/julia/ memlayout.cpp -o memlayout + **/ + +#include +#include +#include +#include + +#include + +#include "julia.h" + +std::string jl_ver(std::string sep=".") { + std::ostringstream oss; + oss << JULIA_VERSION_MAJOR << sep + << JULIA_VERSION_MINOR << sep + << JULIA_VERSION_PATCH; + return oss.str(); +} + +std::string platform() { +#ifdef _WIN32 +#ifdef _WIN64 + return "windows-x86_64"; +#endif + return "windows-x86"; +#endif +#ifdef __APPLE__ + return "darwin-x86_64"; +#endif +#ifdef __linux__ +#ifdef __x86_64 + return "linux-x86_64"; +#else + return "linux-x86"; +#endif +#endif +} + +std::map task_field_offsets() { + std::map data; + +#define field_info(f) data[#f] = offsetof(jl_task_t, f) + + field_info(next); // 131 142 153 154 160 170 + field_info(queue); // 131 142 153 154 160 170 + field_info(tls); // 131 142 153 154 160 170 + field_info(donenotify); // 131 142 153 154 160 170 + field_info(result); // 131 142 153 154 160 170 + +#if JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR < 6 + field_info(state); // 131 142 153 154 + field_info(exception); // 131 142 153 154 + field_info(backtrace); // 131 142 153 154 +#endif + + field_info(logstate); // 131 142 153 154 160 170 + field_info(start); // 131 142 153 154 160 170 + field_info(sticky); // 131 142 153 154 160 170 + +#if JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR > 5 + field_info(_state); // 160 170 + field_info(_isexception); // 160 170 +#endif + +#if JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR > 6 + field_info(rngState0); // 170 + field_info(rngState1); // 170 + field_info(rngState2); // 170 + field_info(rngState3); // 170 +#endif + + // hidden state + field_info(gcstack); // 131 142 153 154 160 170 + +#if JULIA_VERSION_MAJOR == 1 && \ + (JULIA_VERSION_MINOR > 6 || JULIA_VERSION_MINOR < 5 || \ + (JULIA_VERSION_MINOR == 5 && JULIA_VERSION_PATCH < 4)) + field_info(world_age); // 131 142 153 170 +#endif + +#if JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR > 6 + field_info(ptls); // 170 +#endif + field_info(tid); // 131 142 153 154 160 170 + field_info(prio); // 131 142 153 154 160 170 + field_info(excstack); // 131 142 153 154 160 170 + field_info(eh); // 131 142 153 154 160 170 + field_info(ctx); // 131 142 153 154 160 170 + +#if JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR < 6 + field_info(locks); // 131 142 153 154 + field_info(timing_stack); // 131 142 153 154 +#endif + // field_info(copy_stack_ctx); + +#if defined(JL_TSAN_ENABLED) + field_info(tsan_state); // 170 +#endif + + field_info(stkbuf); // 131 142 153 154 160 170 + field_info(bufsz); // 131 142 153 154 160 170 + // field_info(copy_stack); + // field_info(started); + +#undef field_info + data["copy_stack"] = offsetof(jl_task_t, bufsz) + sizeof(size_t); + data["sizeof_ctx"] = sizeof(((jl_task_t*)0)->ctx); + // data["sizeof_stack_ctx"] = sizeof(((jl_task_t*)0)->copy_stack_ctx); + data["tls_base_context"] = offsetof(struct _jl_tls_states_t, base_ctx); + // data["tls_copy_stack_ctx"] = offsetof(struct _jl_tls_states_t, copy_stack_ctx); + return data; +} + +int main() { + std::ofstream ofs(platform() +"-v" + jl_ver("_") + ".jl", std::ofstream::out); + + ofs << "ALL_TASK_OFFSETS[(" + << '"' << platform() << '"' << ", " + << "v\"" << jl_ver() <<"\"" + <<")] = Dict(\n"; + ofs << " :END => " << sizeof(jl_task_t) << ",\n"; + + std::map data = task_field_offsets(); + for(auto kv: data) { + ofs << " :" << kv.first << " => " << kv.second << ",\n"; + } + ofs << ")\n"; + + ofs.close(); + return 0; +} diff --git a/.github/workflows/tasklayout/memlayout.jl b/.github/workflows/tasklayout/memlayout.jl new file mode 100644 index 00000000..78ec9ae5 --- /dev/null +++ b/.github/workflows/tasklayout/memlayout.jl @@ -0,0 +1,32 @@ +const ARCH = @static if string(Sys.ARCH)[1] == 'i' + "x86" +else + string(Sys.ARCH) +end + +const PLATFORM = @static if Sys.islinux() + "linux-" * ARCH +elseif Sys.iswindows() + "windows-" * ARCH +elseif Sys.isapple() + "darwin-" * ARCH +end + +OUTPUT = "$(PLATFORM)-v$(VERSION.major)_$(VERSION.minor)_$(VERSION.patch).jl" +OUTPUT_DEST = joinpath("src/memlayout", OUTPUT) + +isfile(OUTPUT_DEST) && exit(0) + +const PROJECT_DIR = (@__DIR__) |> dirname |> dirname |> dirname +const INCLUDE = joinpath(dirname(Sys.BINDIR), "include/julia") +const OPTIONS = if string(Sys.ARCH)[1] == 'i' + Sys.islinux() && run(`sudo apt-get install g++-multilib -y`) + ["-std=c++11","-march=pentium4", "-m32", "-static-libgcc", "-static-libstdc++"] +else + ["-std=c++11"] +end + +run(`g++ $(OPTIONS) -I$(INCLUDE) $(PROJECT_DIR)/.github/workflows/tasklayout/memlayout.cpp -o memlayout-gen.exe`) +run(`./memlayout-gen.exe`) + +isfile(OUTPUT) && Base.Filesystem.mv(OUTPUT, OUTPUT_DEST) diff --git a/Project.toml b/Project.toml index 75bccfc5..9ee5aa26 100644 --- a/Project.toml +++ b/Project.toml @@ -6,17 +6,18 @@ repo = "https://github.com/TuringLang/Libtask.jl.git" version = "0.5.3" [deps] +Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" Libtask_jll = "3ae2931a-708c-5973-9c38-ccf7496fb450" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [compat] -Libtask_jll = "0.4" +Libtask_jll = "0.5.1" julia = "1.3" [extras] -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] test = ["Test", "BenchmarkTools"] diff --git a/src/Libtask.jl b/src/Libtask.jl index e647e65d..22897916 100644 --- a/src/Libtask.jl +++ b/src/Libtask.jl @@ -1,9 +1,19 @@ module Libtask +using Libdl using Libtask_jll export CTask, consume, produce, TArray, tzeros, tfill, TRef +function __init__() + @static if VERSION < v"1.6.0" + push!(Libdl.DL_LOAD_PATH, + Libtask_jll.get_libtask_julia_path() |> dirname) + Libdl.dlopen(Libtask_jll.libtask_julia_path) + end +end + +include("memlayout/main.jl") include("ctask.jl") include("tarray.jl") include("tref.jl") diff --git a/src/ctask.jl b/src/ctask.jl index 8665c7b5..a3e6a754 100644 --- a/src/ctask.jl +++ b/src/ctask.jl @@ -49,7 +49,18 @@ function enable_stack_copying(t::Task) if istaskfailed(t) error("only runnable or finished tasks' stack can be copied.") end - return ccall((:jl_enable_stack_copying, libtask_julia), Any, (Any,), t)::Task + # return ccall((:jl_enable_stack_copying, libtask_julia), + # Any, (Any,), t)::Task + copy_stack = internal_getfield(t, :copy_stack, Int32) + if copy_stack == 0 + internal_setfield(t, :copy_stack, Int32(1)) + internal_setfield(t, :bufsz, Csize_t(0)) + ccall((:jl_reset_task_ctx, libtask_julia), + Cvoid, (Any, Csize_t, Csize_t, Csize_t), + t, TASK_OFFSETS[:ctx], TASK_OFFSETS[:sizeof_ctx], + TASK_OFFSETS[:tls_base_context]) + end + return t end """ @@ -101,7 +112,30 @@ function Base.copy(ctask::CTask) error("only runnable or finished tasks can be copied.") end - newtask = ccall((:jl_clone_task, libtask_julia), Any, (Any,), task)::Task + # memory copy + # newtask = ccall((:jl_clone_task, libtask_julia), Any, (Any,), task)::Task + newtask = ccall((:jl_clone_task_opaque, libtask_julia), + Any, (Any, Csize_t), task, TASK_OFFSETS[:END])::Task + internal_setfield(newtask, :exception, nothing) + internal_setfield(newtask, :backtrace, nothing) + internal_setfield(newtask, :tls, nothing) + internal_setfield(newtask, :result, nothing) + internal_setfield(newtask, :donenotify, nothing) + internal_setfield(newtask, :excstack, C_NULL) + internal_setfield(newtask, :ptls, C_NULL) + internal_setfield(newtask, :gcstack, C_NULL) + + if haskey(TASK_OFFSETS, :stkbuf) && haskey(TASK_OFFSETS, :bufsz) + old_stkbuf = internal_getfield(task, :stkbuf, Ptr) + if old_stkbuf != C_NULL + internal_setfield(task, :bufsz, Csize_t(0)) + else + internal_setfield(newtask, :stkbuf, C_NULL) + end + internal_setfield(newtask, :bufsz, Csize_t(0)) + end + memset(newtask, 0, :locks) + # memory copy done task.storage[:n_copies] = 1 + n_copies(task) newtask.storage = copy(task.storage) diff --git a/src/memlayout/darwin-x86_64-v1_3_1.jl b/src/memlayout/darwin-x86_64-v1_3_1.jl new file mode 100644 index 00000000..f154b529 --- /dev/null +++ b/src/memlayout/darwin-x86_64-v1_3_1.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("darwin-x86_64", v"1.3.1")] = Dict( + :END => 568, + :backtrace => 56, + :bufsz => 248, + :copy_stack => 256, + :ctx => 84, + :donenotify => 32, + :eh => 264, + :exception => 48, + :excstack => 280, + :gcstack => 272, + :locks => 304, + :logstate => 64, + :next => 0, + :prio => 298, + :queue => 8, + :result => 40, + :sizeof_ctx => 152, + :start => 72, + :state => 24, + :sticky => 80, + :stkbuf => 240, + :tid => 296, + :timing_stack => 560, + :tls => 16, + :tls_base_context => 6664, + :world_age => 288, +) diff --git a/src/memlayout/darwin-x86_64-v1_4_2.jl b/src/memlayout/darwin-x86_64-v1_4_2.jl new file mode 100644 index 00000000..82c858ed --- /dev/null +++ b/src/memlayout/darwin-x86_64-v1_4_2.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("darwin-x86_64", v"1.4.2")] = Dict( + :END => 568, + :backtrace => 56, + :bufsz => 248, + :copy_stack => 256, + :ctx => 84, + :donenotify => 32, + :eh => 264, + :exception => 48, + :excstack => 280, + :gcstack => 272, + :locks => 304, + :logstate => 64, + :next => 0, + :prio => 298, + :queue => 8, + :result => 40, + :sizeof_ctx => 152, + :start => 72, + :state => 24, + :sticky => 80, + :stkbuf => 240, + :tid => 296, + :timing_stack => 560, + :tls => 16, + :tls_base_context => 6664, + :world_age => 288, +) diff --git a/src/memlayout/darwin-x86_64-v1_5_3.jl b/src/memlayout/darwin-x86_64-v1_5_3.jl new file mode 100644 index 00000000..6d5bc272 --- /dev/null +++ b/src/memlayout/darwin-x86_64-v1_5_3.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("darwin-x86_64", v"1.5.3")] = Dict( + :END => 568, + :backtrace => 56, + :bufsz => 248, + :copy_stack => 256, + :ctx => 84, + :donenotify => 32, + :eh => 264, + :exception => 48, + :excstack => 280, + :gcstack => 272, + :locks => 304, + :logstate => 64, + :next => 0, + :prio => 298, + :queue => 8, + :result => 40, + :sizeof_ctx => 152, + :start => 72, + :state => 24, + :sticky => 80, + :stkbuf => 240, + :tid => 296, + :timing_stack => 560, + :tls => 16, + :tls_base_context => 6672, + :world_age => 288, +) diff --git a/src/memlayout/darwin-x86_64-v1_5_4.jl b/src/memlayout/darwin-x86_64-v1_5_4.jl new file mode 100644 index 00000000..ec6ddd4e --- /dev/null +++ b/src/memlayout/darwin-x86_64-v1_5_4.jl @@ -0,0 +1,27 @@ +ALL_TASK_OFFSETS[("darwin-x86_64", v"1.5.4")] = Dict( + :END => 560, + :backtrace => 56, + :bufsz => 248, + :copy_stack => 256, + :ctx => 84, + :donenotify => 32, + :eh => 264, + :exception => 48, + :excstack => 280, + :gcstack => 272, + :locks => 296, + :logstate => 64, + :next => 0, + :prio => 290, + :queue => 8, + :result => 40, + :sizeof_ctx => 152, + :start => 72, + :state => 24, + :sticky => 80, + :stkbuf => 240, + :tid => 288, + :timing_stack => 552, + :tls => 16, + :tls_base_context => 6672, +) diff --git a/src/memlayout/darwin-x86_64-v1_6_1.jl b/src/memlayout/darwin-x86_64-v1_6_1.jl new file mode 100644 index 00000000..cc4892eb --- /dev/null +++ b/src/memlayout/darwin-x86_64-v1_6_1.jl @@ -0,0 +1,24 @@ +ALL_TASK_OFFSETS[("darwin-x86_64", v"1.6.1")] = Dict( + :END => 264, + :_isexception => 58, + :_state => 56, + :bufsz => 240, + :copy_stack => 248, + :ctx => 80, + :donenotify => 24, + :eh => 72, + :excstack => 64, + :gcstack => 256, + :logstate => 40, + :next => 0, + :prio => 62, + :queue => 8, + :result => 32, + :sizeof_ctx => 152, + :start => 48, + :sticky => 57, + :stkbuf => 232, + :tid => 60, + :tls => 16, + :tls_base_context => 6680, +) diff --git a/src/memlayout/linux-x86-v1_3_1.jl b/src/memlayout/linux-x86-v1_3_1.jl new file mode 100644 index 00000000..66461532 --- /dev/null +++ b/src/memlayout/linux-x86-v1_3_1.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("linux-x86", v"1.3.1")] = Dict( + :END => 364, + :backtrace => 28, + :bufsz => 204, + :copy_stack => 208, + :ctx => 44, + :donenotify => 16, + :eh => 212, + :exception => 24, + :excstack => 220, + :gcstack => 216, + :locks => 232, + :logstate => 32, + :next => 0, + :prio => 230, + :queue => 4, + :result => 20, + :sizeof_ctx => 156, + :start => 36, + :state => 12, + :sticky => 40, + :stkbuf => 200, + :tid => 228, + :timing_stack => 360, + :tls => 8, + :tls_base_context => 3404, + :world_age => 224, +) diff --git a/src/memlayout/linux-x86-v1_4_2.jl b/src/memlayout/linux-x86-v1_4_2.jl new file mode 100644 index 00000000..fa408f34 --- /dev/null +++ b/src/memlayout/linux-x86-v1_4_2.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("linux-x86", v"1.4.2")] = Dict( + :END => 364, + :backtrace => 28, + :bufsz => 204, + :copy_stack => 208, + :ctx => 44, + :donenotify => 16, + :eh => 212, + :exception => 24, + :excstack => 220, + :gcstack => 216, + :locks => 232, + :logstate => 32, + :next => 0, + :prio => 230, + :queue => 4, + :result => 20, + :sizeof_ctx => 156, + :start => 36, + :state => 12, + :sticky => 40, + :stkbuf => 200, + :tid => 228, + :timing_stack => 360, + :tls => 8, + :tls_base_context => 3404, + :world_age => 224, +) diff --git a/src/memlayout/linux-x86-v1_5_3.jl b/src/memlayout/linux-x86-v1_5_3.jl new file mode 100644 index 00000000..a6da71f9 --- /dev/null +++ b/src/memlayout/linux-x86-v1_5_3.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("linux-x86", v"1.5.3")] = Dict( + :END => 364, + :backtrace => 28, + :bufsz => 204, + :copy_stack => 208, + :ctx => 44, + :donenotify => 16, + :eh => 212, + :exception => 24, + :excstack => 220, + :gcstack => 216, + :locks => 232, + :logstate => 32, + :next => 0, + :prio => 230, + :queue => 4, + :result => 20, + :sizeof_ctx => 156, + :start => 36, + :state => 12, + :sticky => 40, + :stkbuf => 200, + :tid => 228, + :timing_stack => 360, + :tls => 8, + :tls_base_context => 3408, + :world_age => 224, +) diff --git a/src/memlayout/linux-x86-v1_5_4.jl b/src/memlayout/linux-x86-v1_5_4.jl new file mode 100644 index 00000000..80d2bd9a --- /dev/null +++ b/src/memlayout/linux-x86-v1_5_4.jl @@ -0,0 +1,27 @@ +ALL_TASK_OFFSETS[("linux-x86", v"1.5.4")] = Dict( + :END => 360, + :backtrace => 28, + :bufsz => 204, + :copy_stack => 208, + :ctx => 44, + :donenotify => 16, + :eh => 212, + :exception => 24, + :excstack => 220, + :gcstack => 216, + :locks => 228, + :logstate => 32, + :next => 0, + :prio => 226, + :queue => 4, + :result => 20, + :sizeof_ctx => 156, + :start => 36, + :state => 12, + :sticky => 40, + :stkbuf => 200, + :tid => 224, + :timing_stack => 356, + :tls => 8, + :tls_base_context => 3408, +) diff --git a/src/memlayout/linux-x86-v1_6_1.jl b/src/memlayout/linux-x86-v1_6_1.jl new file mode 100644 index 00000000..8d04faee --- /dev/null +++ b/src/memlayout/linux-x86-v1_6_1.jl @@ -0,0 +1,24 @@ +ALL_TASK_OFFSETS[("linux-x86", v"1.6.1")] = Dict( + :END => 216, + :_isexception => 30, + :_state => 28, + :bufsz => 204, + :copy_stack => 208, + :ctx => 44, + :donenotify => 12, + :eh => 40, + :excstack => 36, + :gcstack => 212, + :logstate => 20, + :next => 0, + :prio => 34, + :queue => 4, + :result => 16, + :sizeof_ctx => 156, + :start => 24, + :sticky => 29, + :stkbuf => 200, + :tid => 32, + :tls => 8, + :tls_base_context => 3412, +) diff --git a/src/memlayout/linux-x86-v1_8_0.jl b/src/memlayout/linux-x86-v1_8_0.jl new file mode 100644 index 00000000..e681843b --- /dev/null +++ b/src/memlayout/linux-x86-v1_8_0.jl @@ -0,0 +1,30 @@ +ALL_TASK_OFFSETS[("linux-x86", v"1.8.0")] = Dict( + :END => 256, + :_isexception => 30, + :_state => 28, + :bufsz => 248, + :copy_stack => 252, + :ctx => 88, + :donenotify => 12, + :eh => 84, + :excstack => 80, + :gcstack => 64, + :logstate => 20, + :next => 0, + :prio => 78, + :ptls => 72, + :queue => 4, + :result => 16, + :rngState0 => 32, + :rngState1 => 40, + :rngState2 => 48, + :rngState3 => 56, + :sizeof_ctx => 156, + :start => 24, + :sticky => 29, + :stkbuf => 244, + :tid => 76, + :tls => 8, + :tls_base_context => 3416, + :world_age => 68, +) diff --git a/src/memlayout/linux-x86_64-v1_3_1.jl b/src/memlayout/linux-x86_64-v1_3_1.jl new file mode 100644 index 00000000..cca19241 --- /dev/null +++ b/src/memlayout/linux-x86_64-v1_3_1.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("linux-x86_64", v"1.3.1")] = Dict( + :END => 616, + :backtrace => 56, + :bufsz => 296, + :copy_stack => 304, + :ctx => 88, + :donenotify => 32, + :eh => 312, + :exception => 48, + :excstack => 328, + :gcstack => 320, + :locks => 352, + :logstate => 64, + :next => 0, + :prio => 346, + :queue => 8, + :result => 40, + :sizeof_ctx => 200, + :start => 72, + :state => 24, + :sticky => 80, + :stkbuf => 288, + :tid => 344, + :timing_stack => 608, + :tls => 16, + :tls_base_context => 6640, + :world_age => 336, +) diff --git a/src/memlayout/linux-x86_64-v1_4_2.jl b/src/memlayout/linux-x86_64-v1_4_2.jl new file mode 100644 index 00000000..6a1cc083 --- /dev/null +++ b/src/memlayout/linux-x86_64-v1_4_2.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("linux-x86_64", v"1.4.2")] = Dict( + :END => 616, + :backtrace => 56, + :bufsz => 296, + :copy_stack => 304, + :ctx => 88, + :donenotify => 32, + :eh => 312, + :exception => 48, + :excstack => 328, + :gcstack => 320, + :locks => 352, + :logstate => 64, + :next => 0, + :prio => 346, + :queue => 8, + :result => 40, + :sizeof_ctx => 200, + :start => 72, + :state => 24, + :sticky => 80, + :stkbuf => 288, + :tid => 344, + :timing_stack => 608, + :tls => 16, + :tls_base_context => 6640, + :world_age => 336, +) diff --git a/src/memlayout/linux-x86_64-v1_5_3.jl b/src/memlayout/linux-x86_64-v1_5_3.jl new file mode 100644 index 00000000..2e92d6d7 --- /dev/null +++ b/src/memlayout/linux-x86_64-v1_5_3.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("linux-x86_64", v"1.5.3")] = Dict( + :END => 616, + :backtrace => 56, + :bufsz => 296, + :copy_stack => 304, + :ctx => 88, + :donenotify => 32, + :eh => 312, + :exception => 48, + :excstack => 328, + :gcstack => 320, + :locks => 352, + :logstate => 64, + :next => 0, + :prio => 346, + :queue => 8, + :result => 40, + :sizeof_ctx => 200, + :start => 72, + :state => 24, + :sticky => 80, + :stkbuf => 288, + :tid => 344, + :timing_stack => 608, + :tls => 16, + :tls_base_context => 6648, + :world_age => 336, +) diff --git a/src/memlayout/linux-x86_64-v1_5_4.jl b/src/memlayout/linux-x86_64-v1_5_4.jl new file mode 100644 index 00000000..505955d0 --- /dev/null +++ b/src/memlayout/linux-x86_64-v1_5_4.jl @@ -0,0 +1,27 @@ +ALL_TASK_OFFSETS[("linux-x86_64", v"1.5.4")] = Dict( + :END => 608, + :backtrace => 56, + :bufsz => 296, + :copy_stack => 304, + :ctx => 88, + :donenotify => 32, + :eh => 312, + :exception => 48, + :excstack => 328, + :gcstack => 320, + :locks => 344, + :logstate => 64, + :next => 0, + :prio => 338, + :queue => 8, + :result => 40, + :sizeof_ctx => 200, + :start => 72, + :state => 24, + :sticky => 80, + :stkbuf => 288, + :tid => 336, + :timing_stack => 600, + :tls => 16, + :tls_base_context => 6648, +) diff --git a/src/memlayout/linux-x86_64-v1_6_1.jl b/src/memlayout/linux-x86_64-v1_6_1.jl new file mode 100644 index 00000000..adbe2774 --- /dev/null +++ b/src/memlayout/linux-x86_64-v1_6_1.jl @@ -0,0 +1,24 @@ +ALL_TASK_OFFSETS[("linux-x86_64", v"1.6.1")] = Dict( + :END => 312, + :_isexception => 58, + :_state => 56, + :bufsz => 288, + :copy_stack => 296, + :ctx => 80, + :donenotify => 24, + :eh => 72, + :excstack => 64, + :gcstack => 304, + :logstate => 40, + :next => 0, + :prio => 62, + :queue => 8, + :result => 32, + :sizeof_ctx => 200, + :start => 48, + :sticky => 57, + :stkbuf => 280, + :tid => 60, + :tls => 16, + :tls_base_context => 6656, +) diff --git a/src/memlayout/linux-x86_64-v1_8_0.jl b/src/memlayout/linux-x86_64-v1_8_0.jl new file mode 100644 index 00000000..6b2a97ce --- /dev/null +++ b/src/memlayout/linux-x86_64-v1_8_0.jl @@ -0,0 +1,30 @@ +ALL_TASK_OFFSETS[("linux-x86_64", v"1.8.0")] = Dict( + :END => 368, + :_isexception => 58, + :_state => 56, + :bufsz => 352, + :copy_stack => 360, + :ctx => 144, + :donenotify => 24, + :eh => 136, + :excstack => 128, + :gcstack => 96, + :logstate => 40, + :next => 0, + :prio => 122, + :ptls => 112, + :queue => 8, + :result => 32, + :rngState0 => 64, + :rngState1 => 72, + :rngState2 => 80, + :rngState3 => 88, + :sizeof_ctx => 200, + :start => 48, + :sticky => 57, + :stkbuf => 344, + :tid => 120, + :tls => 16, + :tls_base_context => 6656, + :world_age => 104, +) diff --git a/src/memlayout/main.jl b/src/memlayout/main.jl new file mode 100644 index 00000000..169cc93a --- /dev/null +++ b/src/memlayout/main.jl @@ -0,0 +1,106 @@ +const ALL_TASK_OFFSETS = + Dict{Tuple{String, VersionNumber}, Dict{Symbol, Int}}() + + +include("linux-x86-v1_3_1.jl") +include("linux-x86-v1_4_2.jl") +include("linux-x86-v1_5_3.jl") +include("linux-x86-v1_5_4.jl") +include("linux-x86-v1_6_1.jl") +include("linux-x86-v1_8_0.jl") + +include("linux-x86_64-v1_3_1.jl") +include("linux-x86_64-v1_4_2.jl") +include("linux-x86_64-v1_5_3.jl") +include("linux-x86_64-v1_5_4.jl") +include("linux-x86_64-v1_6_1.jl") +include("linux-x86_64-v1_8_0.jl") + +include("darwin-x86_64-v1_3_1.jl") +include("darwin-x86_64-v1_4_2.jl") +include("darwin-x86_64-v1_5_3.jl") +include("darwin-x86_64-v1_5_4.jl") +include("darwin-x86_64-v1_6_1.jl") + +include("windows-x86-v1_3_1.jl") +include("windows-x86-v1_4_2.jl") +include("windows-x86-v1_5_3.jl") +include("windows-x86-v1_5_4.jl") +include("windows-x86-v1_6_1.jl") + +include("windows-x86_64-v1_3_1.jl") +include("windows-x86_64-v1_4_2.jl") +include("windows-x86_64-v1_5_3.jl") +include("windows-x86_64-v1_5_4.jl") +include("windows-x86_64-v1_6_1.jl") + +const ARCH = @static if string(Sys.ARCH)[1] == 'i' + "x86" +else + string(Sys.ARCH) +end + +const PLATFORM = @static if Sys.islinux() + "linux-" * ARCH +elseif Sys.iswindows() + "windows-" * ARCH +elseif Sys.isapple() + "darwin-" * ARCH +end + +function find_offsets() + candi = [v for (p, v) in keys(ALL_TASK_OFFSETS) if p == PLATFORM] + sort!(candi) + candi = [v for v in candi if v <= VERSION] + isempty(candi) && error("No suitable offsets") + ALL_TASK_OFFSETS[(PLATFORM, candi[end])] +end + +const TASK_OFFSETS = find_offsets() + +## utilities + +# getter +function internal_getfield(task, field, ::Type{Ptr}) + ccall((:jl_getfield_ptr, libtask_julia), + Ptr{Cvoid}, (Any, Csize_t), + task, TASK_OFFSETS[field]) +end + +function internal_getfield(task, field, ::Type{Int32}) + ccall((:jl_getfield_int32_t, libtask_julia), + Int32, (Any, Csize_t), task, TASK_OFFSETS[field]) +end + +# setter +function internal_setfield(task, field, ::Nothing) + haskey(TASK_OFFSETS, field) && ccall( + (:jl_setfield_nothing, libtask_julia), + Any, (Any, Csize_t), task, TASK_OFFSETS[field]) +end + +function internal_setfield(task, field, p::Ptr{Nothing}) + p == C_NULL || error("this function is only for setting NULL value") + haskey(TASK_OFFSETS, field) && ccall( + (:jl_setfield_null, libtask_julia), + Any, (Any, Csize_t), task, TASK_OFFSETS[field]) +end + +function internal_setfield(task, field, val::Csize_t) + ccall((:jl_setfield_size_t, libtask_julia), + Any, (Any, Csize_t, Csize_t), + task, TASK_OFFSETS[field], val) +end + +function internal_setfield(task, field, val::Int32) + ccall((:jl_setfield_int32_t, libtask_julia), + Any, (Any, Csize_t, Int32), + task, TASK_OFFSETS[field], val) +end + +function memset(task, val, offset_field; end_field=:END) + haskey(TASK_OFFSETS, offset_field) && ccall( + (:jl_memset, libtask_julia), + Cvoid, (Any, Csize_t, Csize_t, Int), + task, TASK_OFFSETS[offset_field], TASK_OFFSETS[end_field], val) +end diff --git a/src/memlayout/windows-x86-v1_3_1.jl b/src/memlayout/windows-x86-v1_3_1.jl new file mode 100644 index 00000000..6fe2d316 --- /dev/null +++ b/src/memlayout/windows-x86-v1_3_1.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("windows-x86", v"1.3.1")] = Dict( + :END => 280, + :backtrace => 28, + :bufsz => 120, + :copy_stack => 124, + :ctx => 44, + :donenotify => 16, + :eh => 128, + :exception => 24, + :excstack => 136, + :gcstack => 132, + :locks => 148, + :logstate => 32, + :next => 0, + :prio => 146, + :queue => 4, + :result => 20, + :sizeof_ctx => 72, + :start => 36, + :state => 12, + :sticky => 40, + :stkbuf => 116, + :tid => 144, + :timing_stack => 276, + :tls => 8, + :tls_base_context => 3352, + :world_age => 140, +) diff --git a/src/memlayout/windows-x86-v1_4_2.jl b/src/memlayout/windows-x86-v1_4_2.jl new file mode 100644 index 00000000..1f502163 --- /dev/null +++ b/src/memlayout/windows-x86-v1_4_2.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("windows-x86", v"1.4.2")] = Dict( + :END => 280, + :backtrace => 28, + :bufsz => 120, + :copy_stack => 124, + :ctx => 44, + :donenotify => 16, + :eh => 128, + :exception => 24, + :excstack => 136, + :gcstack => 132, + :locks => 148, + :logstate => 32, + :next => 0, + :prio => 146, + :queue => 4, + :result => 20, + :sizeof_ctx => 72, + :start => 36, + :state => 12, + :sticky => 40, + :stkbuf => 116, + :tid => 144, + :timing_stack => 276, + :tls => 8, + :tls_base_context => 3352, + :world_age => 140, +) diff --git a/src/memlayout/windows-x86-v1_5_3.jl b/src/memlayout/windows-x86-v1_5_3.jl new file mode 100644 index 00000000..7c73b7a8 --- /dev/null +++ b/src/memlayout/windows-x86-v1_5_3.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("windows-x86", v"1.5.3")] = Dict( + :END => 280, + :backtrace => 28, + :bufsz => 120, + :copy_stack => 124, + :ctx => 44, + :donenotify => 16, + :eh => 128, + :exception => 24, + :excstack => 136, + :gcstack => 132, + :locks => 148, + :logstate => 32, + :next => 0, + :prio => 146, + :queue => 4, + :result => 20, + :sizeof_ctx => 72, + :start => 36, + :state => 12, + :sticky => 40, + :stkbuf => 116, + :tid => 144, + :timing_stack => 276, + :tls => 8, + :tls_base_context => 3356, + :world_age => 140, +) diff --git a/src/memlayout/windows-x86-v1_5_4.jl b/src/memlayout/windows-x86-v1_5_4.jl new file mode 100644 index 00000000..53f9c6dc --- /dev/null +++ b/src/memlayout/windows-x86-v1_5_4.jl @@ -0,0 +1,27 @@ +ALL_TASK_OFFSETS[("windows-x86", v"1.5.4")] = Dict( + :END => 276, + :backtrace => 28, + :bufsz => 120, + :copy_stack => 124, + :ctx => 44, + :donenotify => 16, + :eh => 128, + :exception => 24, + :excstack => 136, + :gcstack => 132, + :locks => 144, + :logstate => 32, + :next => 0, + :prio => 142, + :queue => 4, + :result => 20, + :sizeof_ctx => 72, + :start => 36, + :state => 12, + :sticky => 40, + :stkbuf => 116, + :tid => 140, + :timing_stack => 272, + :tls => 8, + :tls_base_context => 3356, +) diff --git a/src/memlayout/windows-x86-v1_6_1.jl b/src/memlayout/windows-x86-v1_6_1.jl new file mode 100644 index 00000000..2b1f3750 --- /dev/null +++ b/src/memlayout/windows-x86-v1_6_1.jl @@ -0,0 +1,24 @@ +ALL_TASK_OFFSETS[("windows-x86", v"1.6.1")] = Dict( + :END => 132, + :_isexception => 30, + :_state => 28, + :bufsz => 120, + :copy_stack => 124, + :ctx => 44, + :donenotify => 12, + :eh => 40, + :excstack => 36, + :gcstack => 128, + :logstate => 20, + :next => 0, + :prio => 34, + :queue => 4, + :result => 16, + :sizeof_ctx => 72, + :start => 24, + :sticky => 29, + :stkbuf => 116, + :tid => 32, + :tls => 8, + :tls_base_context => 3360, +) diff --git a/src/memlayout/windows-x86_64-v1_3_1.jl b/src/memlayout/windows-x86_64-v1_3_1.jl new file mode 100644 index 00000000..1669f3f8 --- /dev/null +++ b/src/memlayout/windows-x86_64-v1_3_1.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("windows-x86_64", v"1.3.1")] = Dict( + :END => 704, + :backtrace => 56, + :bufsz => 376, + :copy_stack => 384, + :ctx => 96, + :donenotify => 32, + :eh => 392, + :exception => 48, + :excstack => 408, + :gcstack => 400, + :locks => 432, + :logstate => 64, + :next => 0, + :prio => 426, + :queue => 8, + :result => 40, + :sizeof_ctx => 272, + :start => 72, + :state => 24, + :sticky => 80, + :stkbuf => 368, + :tid => 424, + :timing_stack => 688, + :tls => 16, + :tls_base_context => 6608, + :world_age => 416, +) diff --git a/src/memlayout/windows-x86_64-v1_4_2.jl b/src/memlayout/windows-x86_64-v1_4_2.jl new file mode 100644 index 00000000..504caa71 --- /dev/null +++ b/src/memlayout/windows-x86_64-v1_4_2.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("windows-x86_64", v"1.4.2")] = Dict( + :END => 704, + :backtrace => 56, + :bufsz => 376, + :copy_stack => 384, + :ctx => 96, + :donenotify => 32, + :eh => 392, + :exception => 48, + :excstack => 408, + :gcstack => 400, + :locks => 432, + :logstate => 64, + :next => 0, + :prio => 426, + :queue => 8, + :result => 40, + :sizeof_ctx => 272, + :start => 72, + :state => 24, + :sticky => 80, + :stkbuf => 368, + :tid => 424, + :timing_stack => 688, + :tls => 16, + :tls_base_context => 6608, + :world_age => 416, +) diff --git a/src/memlayout/windows-x86_64-v1_5_3.jl b/src/memlayout/windows-x86_64-v1_5_3.jl new file mode 100644 index 00000000..07d4ebae --- /dev/null +++ b/src/memlayout/windows-x86_64-v1_5_3.jl @@ -0,0 +1,28 @@ +ALL_TASK_OFFSETS[("windows-x86_64", v"1.5.3")] = Dict( + :END => 704, + :backtrace => 56, + :bufsz => 376, + :copy_stack => 384, + :ctx => 96, + :donenotify => 32, + :eh => 392, + :exception => 48, + :excstack => 408, + :gcstack => 400, + :locks => 432, + :logstate => 64, + :next => 0, + :prio => 426, + :queue => 8, + :result => 40, + :sizeof_ctx => 272, + :start => 72, + :state => 24, + :sticky => 80, + :stkbuf => 368, + :tid => 424, + :timing_stack => 688, + :tls => 16, + :tls_base_context => 6608, + :world_age => 416, +) diff --git a/src/memlayout/windows-x86_64-v1_5_4.jl b/src/memlayout/windows-x86_64-v1_5_4.jl new file mode 100644 index 00000000..446c1396 --- /dev/null +++ b/src/memlayout/windows-x86_64-v1_5_4.jl @@ -0,0 +1,27 @@ +ALL_TASK_OFFSETS[("windows-x86_64", v"1.5.4")] = Dict( + :END => 688, + :backtrace => 56, + :bufsz => 376, + :copy_stack => 384, + :ctx => 96, + :donenotify => 32, + :eh => 392, + :exception => 48, + :excstack => 408, + :gcstack => 400, + :locks => 424, + :logstate => 64, + :next => 0, + :prio => 418, + :queue => 8, + :result => 40, + :sizeof_ctx => 272, + :start => 72, + :state => 24, + :sticky => 80, + :stkbuf => 368, + :tid => 416, + :timing_stack => 680, + :tls => 16, + :tls_base_context => 6608, +) diff --git a/src/memlayout/windows-x86_64-v1_6_1.jl b/src/memlayout/windows-x86_64-v1_6_1.jl new file mode 100644 index 00000000..6640becd --- /dev/null +++ b/src/memlayout/windows-x86_64-v1_6_1.jl @@ -0,0 +1,24 @@ +ALL_TASK_OFFSETS[("windows-x86_64", v"1.6.1")] = Dict( + :END => 384, + :_isexception => 58, + :_state => 56, + :bufsz => 360, + :copy_stack => 368, + :ctx => 80, + :donenotify => 24, + :eh => 72, + :excstack => 64, + :gcstack => 376, + :logstate => 40, + :next => 0, + :prio => 62, + :queue => 8, + :result => 32, + :sizeof_ctx => 272, + :start => 48, + :sticky => 57, + :stkbuf => 352, + :tid => 60, + :tls => 16, + :tls_base_context => 6624, +)