Git Product home page Git Product logo

Comments (9)

darleybarreto avatar darleybarreto commented on June 12, 2024 2

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.

windelbouwman avatar windelbouwman commented on June 12, 2024 1

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.

windelbouwman avatar windelbouwman commented on June 12, 2024 1

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.

windelbouwman avatar windelbouwman commented on June 12, 2024 1

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.

darleybarreto avatar darleybarreto commented on June 12, 2024

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.

darleybarreto avatar darleybarreto commented on June 12, 2024

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.

windelbouwman avatar windelbouwman commented on June 12, 2024

Cool! Nicely done!!

from ppci.

darleybarreto avatar darleybarreto commented on June 12, 2024

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.

darleybarreto avatar darleybarreto commented on June 12, 2024

Closed by #114

from ppci.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.