mirror of
https://github.com/Alvin-Zilverstand/bob16.git
synced 2026-12-01 22:21:19 +01:00
;l
This commit is contained in:
1 parent
6dc841f956
commit
3d06f94e48
46 files changed
+5830
-543
No files matched your search
+68
@@ -145,6 +145,74 @@ static inline s64 bob64_app_file_close(s64 handle) {
|
||||
return (s64)rax;
|
||||
}
|
||||
|
||||
/* Transfer a whole app file with bounded streaming syscalls. */
|
||||
static inline s64 bob64_app_file_read_all(const char *name,usize name_length,
|
||||
void *buffer,usize capacity) {
|
||||
if((!buffer&&capacity)||capacity>0x7fffffffffffffffULL)return -22;
|
||||
s64 handle=bob64_app_file_open(name,name_length,BOB64_FILE_OPEN_READ);
|
||||
if(handle<0)return handle;
|
||||
usize total=0;
|
||||
s64 result=0;
|
||||
while(total<capacity) {
|
||||
usize chunk=capacity-total;
|
||||
if(chunk>BOB64_SYSCALL_MAX_BUFFER)chunk=BOB64_SYSCALL_MAX_BUFFER;
|
||||
s64 count=bob64_app_file_read(handle,(u8 *)buffer+total,chunk);
|
||||
if(count<0) {result=count;goto close_file;}
|
||||
if(!count) {result=(s64)total;goto close_file;}
|
||||
if((u64)count>chunk) {result=-5;goto close_file;}
|
||||
total+=(usize)count;
|
||||
}
|
||||
{
|
||||
u8 extra;
|
||||
s64 count=bob64_app_file_read(handle,&extra,1);
|
||||
result=count<0?count:(count?-28:(s64)total);
|
||||
}
|
||||
close_file:
|
||||
if(bob64_app_file_close(handle)<0&&result>=0)result=-5;
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline s64 bob64_app_file_write_all(const char *name,usize name_length,
|
||||
const void *buffer,usize length) {
|
||||
if((!buffer&&length)||length>0x7fffffffffffffffULL)return -22;
|
||||
if(length<=BOB64_SYSCALL_MAX_BUFFER)
|
||||
return bob64_app_write_file(name,name_length,buffer,length);
|
||||
s64 handle=bob64_app_file_open(name,name_length,
|
||||
BOB64_FILE_OPEN_WRITE|BOB64_FILE_OPEN_CREATE|BOB64_FILE_OPEN_TRUNCATE);
|
||||
if(handle<0)return handle;
|
||||
usize total=0;
|
||||
s64 result=0;
|
||||
while(total<length) {
|
||||
usize chunk=length-total;
|
||||
if(chunk>BOB64_SYSCALL_MAX_BUFFER)chunk=BOB64_SYSCALL_MAX_BUFFER;
|
||||
s64 count=bob64_app_file_write(handle,(const u8 *)buffer+total,chunk);
|
||||
if(count<0) {result=count;goto close_file;}
|
||||
if(!count||(u64)count>chunk) {result=-5;goto close_file;}
|
||||
total+=(usize)count;
|
||||
}
|
||||
result=(s64)total;
|
||||
close_file:
|
||||
if(bob64_app_file_close(handle)<0&&result>=0)result=-5;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Run a stored B64E app synchronously and restore this app's syscall context. */
|
||||
static inline s64 bob64_app_run(const char *name,usize name_length,
|
||||
usize argument_count,
|
||||
const char *const *arguments,
|
||||
s64 *exit_status) {
|
||||
register u64 rax __asm__("rax")=BOB64_SYSCALL_RUN_APPLICATION;
|
||||
register u64 rcx __asm__("rcx")=(u64)(uintptr_t)name;
|
||||
register u64 rdx __asm__("rdx")=(u64)name_length;
|
||||
register u64 r8 __asm__("r8")=(u64)(uintptr_t)exit_status;
|
||||
register u64 rsi __asm__("rsi")=(u64)argument_count;
|
||||
register u64 r9 __asm__("r9")=(u64)(uintptr_t)arguments;
|
||||
__asm__ volatile("int $0x80":"+a"(rax):"c"(rcx),"d"(rdx),"r"(r8),
|
||||
"S"(rsi),"r"(r9):
|
||||
"memory","cc");
|
||||
return (s64)rax;
|
||||
}
|
||||
|
||||
/* Kernel-owned windows composite app-owned packed RGB pixel surfaces. */
|
||||
static inline u64 bob64_app_window_create(s32 x,s32 y,u32 width,u32 height) {
|
||||
register u64 rax __asm__("rax")=BOB64_SYSCALL_CREATE_WINDOW;
|
||||
|
||||
Reference in new issue
Block a user