Re: To get memory from another process.
On Tuesday, 7 April 2020 at 21:20:28 UTC, Quantium wrote: Could you advise me how to do these steps on D? Which libs should I import? 1. My programm gets a path to exe file 2. My programm starts that exe file and writes into it 2 commands 3. Programm gets access to exe file memory 4. Programm gets data from process memory and writes it into data.bin file which is in the same directory. As I said, which libs do I need and how to get access to other process memory. Also, can I make this as a driver, but if yes, how to code driver on D? As far I know, you can't access other's program memory in any modern operating system. That's managed and protected by the OS through virtual addressing. What are you trying to do?
Re: To get memory from another process.
On 09/04/2020 4:25 AM, Net wrote: On Tuesday, 7 April 2020 at 21:20:28 UTC, Quantium wrote: Could you advise me how to do these steps on D? Which libs should I import? 1. My programm gets a path to exe file 2. My programm starts that exe file and writes into it 2 commands 3. Programm gets access to exe file memory 4. Programm gets data from process memory and writes it into data.bin file which is in the same directory. As I said, which libs do I need and how to get access to other process memory. Also, can I make this as a driver, but if yes, how to code driver on D? As far I know, you can't access other's program memory in any modern operating system. That's managed and protected by the OS through virtual addressing. Yes you can, in all modern operating systems. It is used for debugging.
Re: Cross-compile for ARM
On Wednesday, 8 April 2020 at 15:52:59 UTC, Severin Teona wrote: Hello, I am working with a NUCLEO_f429zi board, architecure ARMv7e-m and cortex-m4 CPU. I want to cross-compile D code for it from Ubuntu 18.04 LTS Server. My current GCC version is 9. How can I do that? What is the best cross-compiler for that? Have a look at this thread: https://forum.dlang.org/thread/leuxesimcgscjjthp...@forum.dlang.org and my repo at https://bitbucket.org/timosi/minlibd it has not been updated for a while but a version for gdc 9 is almost ready to publish
@safe function with __gshared as default parameter value
``` import std.stdio; @safe: __gshared int gshared = 42; void foo(int i = gshared) { writeln(i); } void main() { foo(); } ``` This currently works; `foo` is `@safe` and prints the value of `gshared`. Changing the call in main to `foo(gshared)` errors. Should it work, and can I expect it to keep working?
Cross-compile for ARM
Hello, I am working with a NUCLEO_f429zi board, architecure ARMv7e-m and cortex-m4 CPU. I want to cross-compile D code for it from Ubuntu 18.04 LTS Server. My current GCC version is 9. How can I do that? What is the best cross-compiler for that?
Re: @safe function with __gshared as default parameter value
On Wednesday, 8 April 2020 at 19:22:11 UTC, jmh530 wrote: On Wednesday, 8 April 2020 at 18:50:16 UTC, data pulverizer wrote: On Wednesday, 8 April 2020 at 16:53:05 UTC, Anonymouse wrote: ``` import std.stdio; @safe: __gshared int gshared = 42; void foo(int i = gshared) { writeln(i); } void main() { foo(); } ``` This currently works; `foo` is `@safe` and prints the value of `gshared`. Changing the call in main to `foo(gshared)` errors. Should it work, and can I expect it to keep working? According to the manual it shouldn't work at all https://dlang.org/spec/function.html#function-safety where it says Safe Functions: "Cannot access __gshared variables.", I don't know why calling as `foo()` works. You still wouldn't be able to manipulate gshared within the function. Though it may still be a problem for @safe... It works with `ref int` too. ``` __gshared int gshared = 42; void foo(ref int i = gshared) @safe { ++i; } void main() { assert(gshared == 42); foo(); assert(gshared == 43); } ```
Re: To get memory from another process.
On Wednesday, 8 April 2020 at 16:25:01 UTC, Net wrote: On Tuesday, 7 April 2020 at 21:20:28 UTC, Quantium wrote: Could you advise me how to do these steps on D? Which libs should I import? 1. My programm gets a path to exe file 2. My programm starts that exe file and writes into it 2 commands 3. Programm gets access to exe file memory 4. Programm gets data from process memory and writes it into data.bin file which is in the same directory. As I said, which libs do I need and how to get access to other process memory. Also, can I make this as a driver, but if yes, how to code driver on D? As far I know, you can't access other's program memory in any modern operating system. That's managed and protected by the OS through virtual addressing. What are you trying to do? Now I know that programm even at Administrator mode cannot do this. Only system permission can do that. Or a driver on a kernel-level (zero level). So now the question is how to code driver, which gets other process' memory on D. Also, I know antiviruses will try to block this driver so I'll test it with no antiviruses and Microsoft Defender off. Or if I'm mistaking anywhere and this is impossible on Windows, is it possible on Linux?
Re: @safe function with __gshared as default parameter value
On Wednesday, 8 April 2020 at 19:29:17 UTC, Anonymouse wrote: ``` __gshared int gshared = 42; void foo(ref int i = gshared) @safe { ++i; } void main() { assert(gshared == 42); foo(); assert(gshared == 43); } ``` Dude, you just broke `@safe`! Lol!
Re: @safe function with __gshared as default parameter value
On Wednesday, 8 April 2020 at 19:29:17 UTC, Anonymouse wrote: [snip] It works with `ref int` too. ``` __gshared int gshared = 42; void foo(ref int i = gshared) @safe { ++i; } void main() { assert(gshared == 42); foo(); assert(gshared == 43); } ``` Well that definitely shouldn't happen. I would file a bug report.
Re: To get memory from another process.
On Wed, Apr 08, 2020 at 08:16:27PM +, Quantium via Digitalmars-d-learn wrote: > On Wednesday, 8 April 2020 at 16:25:01 UTC, Net wrote: [...] > > As far I know, you can't access other's program memory in any modern > > operating system. That's managed and protected by the OS through > > virtual addressing. On Linux, you can access process memory using the virtual file /proc/$pid/mem, where $pid is the process ID. But you need root access for this to work, and you also need to know how the memory is mapped in the process (reading from an unmapped offset will return I/O error). > > What are you trying to do? > > Now I know that programm even at Administrator mode cannot do this. > Only system permission can do that. Or a driver on a kernel-level > (zero level). So now the question is how to code driver, which gets > other process' memory on D. This question has nothing to do with D. You need to know how your OS works, and whether it has an interface that provides the access you want. The programming language cannot give you this, and is also irrelevant as far as performing this operation is concerned; if you have an API that can do this, you can do it in any language. > Also, I know antiviruses will try to block this driver so I'll test it > with no antiviruses and Microsoft Defender off. Or if I'm mistaking > anywhere and this is impossible on Windows, is it possible on Linux? You didn't answer the question. Why are you trying to access another process's memory? Without knowing what you're trying to do, it's hard to give you a more specific answer. T -- Music critic: "That's an imitation fugue!"
Re: Array fill performance differences between for, foreach, slice
In all honesty till now I haven't really thought deeply about memory allocation, I just assumed that malloc, free, and so on where low level operating system functions and that was that. I've heard people in the D community talk about garbage collection, and memory allocation but I didn't think it was something I had to worry about. A lot of the work I do is statistics and data science based, often speed is important, calculations on arrays involve a lot of array instantiation, moving and copying elements and so forth. As far as all that stuff goes the speed of memory operations is important. The fact that I could get those kinds of operations to run faster using D's GC.malloc and different types of iteration is significant. Today it hit me that I actually need to study memory allocation and possibly garbage collection as topics - not so that I can implement a garbage collector, but so that I can write faster code. I know to everyone here that's just basic stuff, but it's a bit of a revelation for me. :-)
Re: @safe function with __gshared as default parameter value
On Wednesday, 8 April 2020 at 18:50:16 UTC, data pulverizer wrote: On Wednesday, 8 April 2020 at 16:53:05 UTC, Anonymouse wrote: ``` import std.stdio; @safe: __gshared int gshared = 42; void foo(int i = gshared) { writeln(i); } void main() { foo(); } ``` This currently works; `foo` is `@safe` and prints the value of `gshared`. Changing the call in main to `foo(gshared)` errors. Should it work, and can I expect it to keep working? According to the manual it shouldn't work at all https://dlang.org/spec/function.html#function-safety where it says Safe Functions: "Cannot access __gshared variables.", I don't know why calling as `foo()` works. You still wouldn't be able to manipulate gshared within the function. Though it may still be a problem for @safe... import std.stdio; __gshared int gshared = 42; @safe void foo(int i = gshared) { i++; writeln(i); } void main() { writeln(gshared); foo(); writeln(gshared); gshared++; writeln(gshared); foo(); writeln(gshared); }
Re: To get memory from another process.
On Wednesday, 8 April 2020 at 20:46:48 UTC, H. S. Teoh wrote: On Wed, Apr 08, 2020 at 08:16:27PM +, Quantium via Digitalmars-d-learn wrote: On Wednesday, 8 April 2020 at 16:25:01 UTC, Net wrote: [...] > As far I know, you can't access other's program memory in > any modern operating system. That's managed and protected > by the OS through virtual addressing. On Linux, you can access process memory using the virtual file /proc/$pid/mem, where $pid is the process ID. But you need root access for this to work, and you also need to know how the memory is mapped in the process (reading from an unmapped offset will return I/O error). > What are you trying to do? Now I know that programm even at Administrator mode cannot do this. Only system permission can do that. Or a driver on a kernel-level (zero level). So now the question is how to code driver, which gets other process' memory on D. This question has nothing to do with D. You need to know how your OS works, and whether it has an interface that provides the access you want. The programming language cannot give you this, and is also irrelevant as far as performing this operation is concerned; if you have an API that can do this, you can do it in any language. Also, I know antiviruses will try to block this driver so I'll test it with no antiviruses and Microsoft Defender off. Or if I'm mistaking anywhere and this is impossible on Windows, is it possible on Linux? You didn't answer the question. Why are you trying to access another process's memory? Without knowing what you're trying to do, it's hard to give you a more specific answer. T I'm trying to do this because I have very special programm that makes some calculations and on every calculation there is a hash in RAM. I need to get a one of hash values from a .bin file, and replace them. I mean hash in RAM of the programm is added to end of .bin file, and one of hashes from that file (I set up sorting algorithm by myself) is in RAM of programm.
Re: @safe function with __gshared as default parameter value
On Wednesday, 8 April 2020 at 16:53:05 UTC, Anonymouse wrote: ``` import std.stdio; @safe: __gshared int gshared = 42; void foo(int i = gshared) { writeln(i); } void main() { foo(); } ``` This currently works; `foo` is `@safe` and prints the value of `gshared`. Changing the call in main to `foo(gshared)` errors. Should it work, and can I expect it to keep working? According to the manual it shouldn't work at all https://dlang.org/spec/function.html#function-safety where it says Safe Functions: "Cannot access __gshared variables.", I don't know why calling as `foo()` works.
Re: @safe function with __gshared as default parameter value
On Wednesday, 8 April 2020 at 19:53:03 UTC, jmh530 wrote: Well that definitely shouldn't happen. I would file a bug report. Filed as https://issues.dlang.org/show_bug.cgi?id=20726
Re: Cross-compile for ARM
On Wednesday, 8 April 2020 at 15:52:59 UTC, Severin Teona wrote: Hello, I am working with a NUCLEO_f429zi board, architecure ARMv7e-m and cortex-m4 CPU. I want to cross-compile D code for it from Ubuntu 18.04 LTS Server. My current GCC version is 9. How can I do that? What is the best cross-compiler for that? I'm heavily biased, but LDC is a cross-compiler by nature. Recent LDC releases can all cross-compile to ARM cpus. https://wiki.dlang.org/Cross-compiling_with_LDC https://wiki.dlang.org/Building_LDC_runtime_libraries Have a look here: https://github.com/JinShil/stm32f42_discovery_demo -Johan