Skip to content

Commit

Permalink
kernel: pass extended arguments through edi, esi registers, remove st…
Browse files Browse the repository at this point in the history
…ruct arguments

(bug: causes cterm to crash��)
  • Loading branch information
ffwff committed Sep 11, 2019
1 parent 147926b commit f1fc78e
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 264 deletions.
8 changes: 5 additions & 3 deletions src/arch/paging.cr
Original file line number Diff line number Diff line change
Expand Up @@ -415,18 +415,20 @@ module Paging

# userspace address checking
def check_user_addr(addr : UInt64)
# TODO: check for kernel/unmapped pages
pdpt_idx, dir_idx, table_idx, page_idx = page_layer_indexes(addr)

pml4_table = Pointer(PageStructs::PML4Table).new(mt_addr @@pml4_table.address)

return false if pml4_table.value.pdpt[pdpt_idx] == 0u64
pdpt = Pointer(PageStructs::PageDirectoryPointerTable)
.new(mt_addr pml4_table.value.pdpt[pdpt_idx])
return false if pdpt.null?

return false if pdpt.value.dirs[dir_idx] == 0u64
pd = Pointer(PageStructs::PageDirectory).new(mt_addr pdpt.value.dirs[dir_idx])
return false if pd.null?

return false if pd.value.tables[table_idx] == 0u64
pt = Pointer(PageStructs::PageTable).new(mt_addr pd.value.tables[table_idx])
return false if pt.null?

pt.value.pages[page_idx] != 0
end
Expand Down
2 changes: 1 addition & 1 deletion src/fs/impl/consolefs.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private class ConsoleFSNode < VFSNode
def ioctl(request : Int32, data : UInt32) : Int32
case request
when SC_IOCTL_TIOCGWINSZ
unless (ptr = checked_pointer32(IoctlData::Winsize, data)).nil?
unless (ptr = checked_pointer(IoctlData::Winsize, data)).nil?
IoctlHandler.winsize(ptr.not_nil!, Console.width, Console.height, 1, 1)
else
-1
Expand Down
6 changes: 3 additions & 3 deletions src/fs/impl/fbdevfs.cr
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private class FbdevFSNode < VFSNode
def ioctl(request : Int32, data : UInt32) : Int32
case request
when SC_IOCTL_TIOCGWINSZ
unless (ptr = checked_pointer32(IoctlData::Winsize, data)).nil?
unless (ptr = checked_pointer(IoctlData::Winsize, data)).nil?
retval = 0
FbdevState.lock do |state|
retval = IoctlHandler.winsize(ptr.not_nil!, state.width, state.height, 1, 1)
Expand All @@ -74,7 +74,7 @@ private class FbdevFSNode < VFSNode
-1
end
when SC_IOCTL_GFX_BITBLIT
arg = checked_pointer32(FbdevFSData::FbBitBlit, data)
arg = checked_pointer(FbdevFSData::FbBitBlit, data)
arg = if arg.nil?
return -1
else
Expand All @@ -101,7 +101,7 @@ private class FbdevFSNode < VFSNode

# source
source_sz = arg.width * arg.height * 4
source = checked_slice32(arg.source, source_sz)
source = checked_slice(arg.source, source_sz)
return -1 if source.nil?
source = source.not_nil!.to_unsafe

Expand Down
12 changes: 6 additions & 6 deletions src/userspace/addr_sanitizer.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module UserAddressSanitiser
extend self

def checked_pointer32(size, addr) : Void*?
def checked_pointer(size, addr) : Void*?
addr = addr.to_u64
size = size.to_u64
i = addr
Expand All @@ -12,7 +12,7 @@ module UserAddressSanitiser
Pointer(Void).new(addr)
end

def checked_slice32(addr, len) : Slice(UInt8)?
def checked_slice(addr, len) : Slice(UInt8)?
addr = addr.to_u64
len = len.to_u64
i = addr
Expand All @@ -25,16 +25,16 @@ module UserAddressSanitiser

end

macro checked_pointer32(t, addr)
macro checked_pointer(t, addr)
begin
if (ptr = UserAddressSanitiser.checked_pointer32(sizeof({{ t }}), {{ addr }}))
if (ptr = UserAddressSanitiser.checked_pointer(sizeof({{ t }}), {{ addr }}))
ptr.as({{ t }}*)
else
nil
end
end
end

macro checked_slice32(addr, len)
UserAddressSanitiser.checked_slice32({{ addr }}, {{ len }})
macro checked_slice(addr, len)
UserAddressSanitiser.checked_slice({{ addr }}, {{ len }})
end
7 changes: 3 additions & 4 deletions src/userspace/process.cr
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,12 @@ module Multiprocessing
end

def get_fd(i : Int32) : FileDescriptor?
return nil if i > MAX_FD || i < 0
fds[i]
fds[i]?
end

def close_fd(i : Int32) : Bool
return false if i > MAX_FD || i < 0
fds[i]
return false if fds[i]?.nil?
fds[i] = nil
true
end

Expand Down

0 comments on commit f1fc78e

Please sign in to comment.