larsbrinkhoff / lbForth

Self-hosting metacompiled Forth, bootstrapping from a few lines of C; targets Linux, Windows, ARM, RISC-V, 68000, PDP-11, asm.js.
GNU General Public License v3.0
427 stars 113 forks source link

calling windows system calls #50

Open vigilancetech-com opened 7 years ago

vigilancetech-com commented 7 years ago

Is there currently a high level way to call system calls?

I look in io.fth and see you setting up the system calls but you only do them from assembly below.

For example, in FreeForth there is the word:

lib:` ( @ # <name> -- ; a n -- funEntry ) loads the dynamic-link-library
  with filename starting at address "@" for "#" bytes, and defines a word
  which will lookup in this library for the function matching the name
  starting at address "a" for "n" bytes, and if found will return its entry,
  for use with "#call" or "fun:".
  If the library is not found, or if later a function is not found,
  an exception is thrown with corresponding error message.
  : lib:` :` #lib lit` #fun ' call, ;` ;
  see also: lib: #call fun: libc k32  ff.boot

and:

#call ( argN ... arg1 N funEntry -- funResult ) calls the library function
  with entry at "funEntry", which consumes "N" arguments from DATAstack and
  returns a single result on top of DATAstack. The N arguments must be pushed
  on DATAstack in the same order as in C, i.e. C-prototype (see Linux man or
  Windows win32.hlp) rightmost argument first, leftmost last.
larsbrinkhoff commented 7 years ago

Is there currently a high level way to call system calls?

No, there isn't. Yes, it would be nice to have.

Note that there's a difference between system calls and library calls. The former use the Linux ABI, and the latter use the C ABI.

vigilancetech-com commented 7 years ago

What about library calls into Windows?

larsbrinkhoff commented 7 years ago

The Windows port does some contortions to call the kernel32 APIs. I think the same method applies to all dlls?

vigilancetech-com commented 7 years ago

I don't know much but I don't see anything different when calling kernel32 as other dlls. Can you tell me what the 80 # int, in write-file in the windows io.fth is all about? I thought that only applied to linux syscalls.

larsbrinkhoff commented 7 years ago

That should be a bug. I probably used the Linux io.fth for the Windows port but forgot about write-file.

I don't know why that passes the tests!