Comments (9)
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);
}
from ppci.
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?
from ppci.
If you want to implement syscalls, I would checkout this sample: https://github.com/windelbouwman/ppci/blob/master/examples/linux64/hello-make/hello.c
from ppci.
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.
from ppci.
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.
from ppci.
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 ret
we would have the break point given by the system, so sbrk would work with this value to give the start memory address when called inside a malloc implementation.
from ppci.
Cool! Nicely done!!
from ppci.
I also took the liberty to change some file structures inside librt/libc
, I guess you will check if it is ok when reviewing the PR. I've never submitted a PR before, should I do something w.r.t CI/CD?
from ppci.
Closed by #114
from ppci.
Related Issues (20)
- ppci-cc: binary operators & | ^ and unary ~ & not supported in initializer constants
- ppci-cc: cannot take the address of a function static variable for initializing a function static variable
- ppci-ld: linker imports too many modules from the libraries
- ppci-cc: ++ and -- should work for floating point types HOT 2
- ppci-cc: conditional operator does not work with struct/union types
- pcci-cc: handling of array type of unknown size
- ppci-cc: initializing a global enum variable is not possible HOT 2
- ppci-cc: cannot compile combined struct assignment
- ppci-cc: switch/case statements should be better tested in the front-end HOT 1
- Tool to compile IR to machine code? HOT 1
- Hashing for IR Nodes HOT 2
- Translating to ppci assembly HOT 7
- Pass pointer HOT 1
- Compiling and running a simple GC
- Reading section failed HOT 1
- c parser crash in stdlib.h HOT 1
- Evaluation of constant expression in preprocessing directives may produce incorrect results
- Missing diagnostics: "invalid constant"
- ARM clarification
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ppci.