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
Better boot.S and link script #10
Conversation
To go further, this code only shows let () =
Format.printf "Hello %!" ;
Format.printf "%S%!" Sys.argv.(0) ;
Format.printf "!\n%!" The problem is definitely about the usage of |
It seems that |
I bisected where the Raspberry Pi 4 fails and it seems that: String.unsafe_blit str 0 res 1 len ; fails (only on Raspberry Pi 4). I'm not sure why but I will try to continue to introspect what is going on - note that I tried this code: let string_to_caml_string str =
let str = String.escaped str in
let l = String.length str in
let res = Bytes.make (l + 2) '\"' in
Bytes.blit_string str 0 res 1 l;
Bytes.unsafe_to_string res
let fn0 str =
let _str = String.escaped str in
Format.printf "[+][+] 000\n%!" ;
;;
let fn1 str =
let str = String.escaped str in
Format.printf "[+][+] 000\n%!" ;
let len = String.length str in
Format.printf "[+][+] 001\n%!" ;
let _res = Bytes.make (len + 2) '\"' in
Format.printf "[+][+] 002\n%!" ;
;;
let fn2 str =
let str = String.escaped str in
Format.printf "[+][+] 000\n%!" ;
let len = String.length str in
Format.printf "[+][+] 001\n%!" ;
let res = Bytes.make (len + 2) '\"' in
Format.printf "[+][+] 002\n%!" ;
Bytes.blit_string str 0 res 1 len ;
Format.printf "[+][+] 003\n%!" ;
;;
let () =
Format.printf "[+] 001\n%!" ;
let _res = Bytes.create 0x100 in
Format.printf "[+] 002\n%!" ;
let _str = String.escaped "\000\001\000" in
Format.printf "[+] 003\n%!" ;
let _str = String.length _str in
Format.printf "[+] 004\n%!" ;
let _str = "Hello World!" in
Format.printf "[+] 005\n%!" ;
let _len = String.length _str in
Format.printf "[+] 006\n%!" ;
Bytes.blit_string _str 0 (Bytes.create 0x100) 0 _len ;
Format.printf "[+] 007\n%!" ;
fn0 "gi(l)braltar" ;
Format.printf "[+] 008\n%!" ;
let _res = Bytes.make (_len + 2) '\"' in
Format.printf "[+] 009\n%!" ;
Bytes.blit Bytes.empty 0 _res 0 0 ;
Format.printf "[+] 010\n%!" ;
fn1 "gi(l)braltar" ;
Format.printf "[+] 011\n%!" ;
fn2 "gi(l)braltar" ;
Format.printf "[+] 012\n%!" ;
Format.printf ">>> %s.\n%!" (string_to_caml_string "gi(l)braltar") ;
;; And the output is:
|
The bug is about the implementation of |
…nexistant symbols from the kernel
for (; n; n--) *d++ = *s++; | ||
return dest; | ||
for (; len; len--) *dst++ = *src++; | ||
return dst; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the man page, the memcpy function should return a pointer to the dest address (return v_dst;
). The returned value does not appear to be used here but at least mirage/mirage-crypto@f351442 uses it to ensure aligned memory usage and it may fail there. This is the same for memmove below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will propose a PR to fix that, thanks for this looking.
And btw, there may be some patch that has corrected the pb after this merge because I am currently able to run the example code completely with the original memcpy and memmove functions.
Maybe it is better to keep the same code here as the nolibc in ocaml-freestanding? The memcpy seems to really take care of 32b alignement and permit to copy 4B at a time which can be faster than 1B copy for longs arrays. |
Hmhmm can you open a new issue for that to keep our experiments 👍 |
/cc @TheLortex may be a nicer
boot.S
and link script.However, a bug persists. I think this layout solve the issue about
bss
nicely.The remaining bug is about the
Sys.argv.(0)
and its usage. Indeed, amain.ml
such as:But this code does not show anything: