6422 - size-of for handles
This commit is contained in:
parent
429cebf3e4
commit
583a966d3e
|
@ -100,7 +100,7 @@ void check_flags(int reg) {
|
|||
|
||||
void check_mode(int reg) {
|
||||
if (Reg[reg].u != 0600) {
|
||||
cerr << HEXWORD << EIP << ": SubX is oblivious to file permissions; register " << reg << " must be 0.\n";
|
||||
cerr << HEXWORD << EIP << ": SubX is oblivious to file permissions; register " << reg << " must be 0x180.\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,19 +18,24 @@ open: # filename: (addr array byte), write?: boolean, out: (addr handle buffere
|
|||
8b/-> *ecx 2/r32/edx
|
||||
42/increment-edx
|
||||
# var s/esi: (stream size)
|
||||
29/subtract-from %esp 0/r32/eax
|
||||
50/push-eax # size
|
||||
29/subtract-from %esp 2/r32/edx
|
||||
52/push-edx # size
|
||||
68/push 0/imm32/read
|
||||
68/push 0/imm32/write
|
||||
89/<- %esi 4/r32/esp
|
||||
# copy filename and a final null character
|
||||
(clear-stream %esi)
|
||||
(write %esi %ecx)
|
||||
# spill edx
|
||||
52/push-edx
|
||||
# var fd/ecx: fd = open(filename)
|
||||
8d/copy-address *(esi+0xc) 3/r32/ebx
|
||||
8b/-> *(ebp+0xc) 1/r32/ecx/flags
|
||||
ba/copy-to-edx 0x180/imm32/permissions
|
||||
e8/call syscall_open/disp32
|
||||
89/<- %ecx 0/r32/eax
|
||||
# restore edx
|
||||
5a/pop-to-edx
|
||||
# allocate a buffered-file
|
||||
(allocate Heap 0x1010 *(ebp+0x10)) # file-buffer-size + 16 for other fields
|
||||
# var out-addr/edi: (addr buffered-file)
|
||||
|
|
11
apps/mu.subx
11
apps/mu.subx
|
@ -7943,10 +7943,17 @@ size-of-type-id: # t: type-id -> result/eax: int
|
|||
89/<- %ecx 4/r32/esp
|
||||
# eax = t
|
||||
8b/-> *(ebp+8) 0/r32/eax
|
||||
# if v is a literal, return 0
|
||||
# if t is a literal, return 0
|
||||
3d/compare-eax-and 0/imm32
|
||||
74/jump-if-= $size-of-type-id:end/disp8 # eax changes type from type-id to int
|
||||
# if v has a user-defined type, return its size
|
||||
# if t is a handle, return 8
|
||||
3d/compare-eax-and 4/imm32/handle
|
||||
{
|
||||
75/jump-if-!= break/disp8
|
||||
b8/copy-to-eax 8/imm32
|
||||
eb/jump $size-of-type-id:end/disp8 # eax changes type from type-id to int
|
||||
}
|
||||
# if t is a user-defined type, return its size
|
||||
# TODO: support non-atom type
|
||||
(find-typeinfo %eax %ecx)
|
||||
{
|
||||
|
|
|
@ -14,8 +14,16 @@ $main-body: {
|
|||
{
|
||||
break-if-<=
|
||||
var filename/edx: (addr addr array byte) <- index args 1
|
||||
var in: (handle buffered-file)
|
||||
{
|
||||
var addr-in/eax: (addr handle buffered-file) <- address in
|
||||
open *filename, 0, addr-in
|
||||
}
|
||||
var in-addr/eax: (addr buffered-file) <- lookup in
|
||||
print-string "filename: "
|
||||
print-string *filename
|
||||
print-string ": "
|
||||
print-int32-to-screen in-addr
|
||||
print-string "\n"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ syscall_write: # fd/ebx: int, buf/ecx: addr, size/edx: int -> nbytes-or-error/e
|
|||
c3/return
|
||||
|
||||
# http://man7.org/linux/man-pages/man2/open.2.html
|
||||
syscall_open: # filename/ebx: (addr kernel-string), flags/ecx: int -> fd-or-error/eax: int
|
||||
syscall_open: # filename/ebx: (addr kernel-string), flags/ecx: int, dummy=0x180/edx -> fd-or-error/eax: int
|
||||
b8/copy-to-eax 5/imm32
|
||||
cd/syscall 0x80/imm8
|
||||
c3/return
|
||||
|
|
Loading…
Reference in New Issue