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
Implementation of sbrk #113
Comments
I'm not sure how to do that, but you could use a linker script to do so? From the memory map you could define a symbol and use that in an assembly level implementation of sbrk. I'm not sure what you want to achieve, do you want to implement your own sbrk function? |
I want to implement malloc, so we could allocate arbitrary objects inside ppci (for unix based systems with brk similar syscalls). The "easy" way would be to implement brk syscall and sbrk wrapper, then malloc using sbrk. |
If you want to implement syscalls, I would checkout this sample: https://github.com/windelbouwman/ppci/blob/master/examples/linux64/hello-make/hello.c |
Oh yeah, I have seen this one, and I altered the implementation of do_inline_asm, so one can get the return of a syscall in a variable like this: long syscall(long nr, long a, long b, long c)
{
long ret;
asm(
"mov rax, %0 \n"
"mov rdi, %1 \n"
"mov rsi, %2 \n"
"mov rdx, %3 \n"
"syscall \n"
: "=r" (ret)
: "r" (nr), "r" (a), "r" (b), "r" (c)
: "rax", "rdi", "rsi", "rdx"
);
return ret;
} In |
I worked out the syscalls and made a port of a simple malloc. So now we can do something like this #include <stdio.h>
#include <stdlib.h>
int main(){
int *int_vec = (int*)malloc(10*sizeof(int));
for (int i =0; i < 10; i++){
int_vec[i] = i*i + 2;
}
for (int i =0; i < 10; i++){
printf("%d",int_vec[i]);
}
free(int_vec);
exit(0);
} |
Cool! Nicely done!! |
I also took the liberty to change some file structures inside |
Sure, feel free to create a PR, lets see what happens :). No need to do any CI/CD. If you want, you can run tests locally with tox / pytest as described in the docs, but I guess this is done as well with CI/CD on github. |
Closed by #114 |
In order to implement dynamic allocated str (#91) and more, today I worked on bringing malloc support. I am almost there (I altered the necessary python code for that), the only thing remaining is
sbrk
function, following this implementation I would need to link the information about the end of the free memory on the host. What would be the best way of doing that?The text was updated successfully, but these errors were encountered: