00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __LSEOS_CORE_H__
00011 #define __LSEOS_CORE_H__ 1
00012 #include <libc.h>
00013 #include <conven/queue.h>
00014 #include <conven/bpt.h>
00015 #ifdef __USE_OLD_AREA_API__
00016 # define __AREA_OLD_CODE__
00017 #endif
00018 #include <area.h>
00019
00023 struct s_idt
00024 {
00025 paddr_t pa;
00026 vaddr_t va;
00027 int limit;
00028 };
00029
00033 struct s_core_info
00034 {
00035 struct s_idt idt[MAX_CPUS];
00036 vaddr_t vgdt;
00037 paddr_t pgdt;
00038 int32_t gdt_limit;
00039 };
00040
00044 #define CR3_SELF ((u_int)-1)
00045 #define CR3_SYSTEM ((u_int)-2)
00050 struct s_runqop
00051 {
00052 int op;
00053 #define RUNQOP_RUN 1
00054 #define RUNQOP_ASRELE 2
00055 #define RUNQOP_TCBRELE 3
00057 union
00058 {
00059 struct
00060 {
00061 pid_t pid;
00062 u_int sel;
00063 } run;
00064
00065 struct
00066 {
00067 pid_t pid;
00068 } tcbrele;
00069
00070 struct
00071 {
00072 asid_t asid;
00073 } asrele;
00074
00075 } u;
00076 };
00077
00078 #define ASID_MINE -1LL
00080 #define PRSV_ANY ((paddr_t)-1)
00082 #define VRSV_ANY ((paddr_t)-1)
00083 #define VRSV_ANYNOTFIRSTMEG ((paddr_t)-2)
00084 //#define VRSV_ANYNOTNULL ((paddr_t)-3)
00089 #define MODE_UNDEF 0
00091 #define VMODE_RSV 4
00092 #define VMODE_VMAP 5
00094 #define KMODE_RSV 8
00096 #define PMODE_RSV 16
00097 #define PMODE_SHARED_RW 17
00098 #define PMODE_SHARED_RO 18
00100 #define VMODEOPT_PERSISTENT_MAP (1u<<0)
00102 #define PMODEOPT_AGGREGATE (1u<<0)
00103 #define PMODEOPT_PERSISTENT (1u<<1)
00104 #define PMODEOPT_SYSTEM (1u<<2)
00105 #define PMODEOPT_USER_READ (1u<<3)
00106 #define PMODEOPT_USER_WRITE (1u<<4)
00107 #define PMODEOPT_GROUP_READ (1u<<5)
00108 #define PMODEOPT_GROUP_WRITE (1u<<6)
00109 #define PMODEOPT_OTHER_READ (1u<<7)
00110 #define PMODEOPT_OTHER_WRITE (1u<<8)
00111 #define PMODEOPT_ALL_READ \
00112 (PMODEOPT_USER_READ|PMODEOPT_GROUP_READ|PMODEOPT_OTHER_READ)
00113 #define PMODEOPT_ALL_WRITE \
00114 (PMODEOPT_USER_WRITE|PMODEOPT_GROUP_WRITE|PMODEOPT_OTHER_WRITE)
00115
00119 #define KTYPE_UNDEF 0
00120 #define KTYPE_REC 1
00121 #define KTYPE_ASPACE 2
00122 #define KTYPE_TCB 3
00123 #define KTYPE_MEM 4
00125 enum
00126 {
00127 SHARED_RW,
00128 SHARED_RO,
00129 };
00130
00134 #define VUNMAP_NOALLOC (1<<0u)
00139 #define PRELE_DONTCLEAN (1<<0u)
00140 #define PRELE_NOALLOC (1<<1u)
00141 #define PRELE_NOASIDCHECK (1<<2u)
00142 #define PRELE_FORCE (1<<3u)
00143 #define PRELE_AGGREGATE (1<<4u)
00148 #define KRELE_NOALLOC (1<<0u)
00149 #define KRELE_NOASIDCHECK (1<<1u)
00154 #define VRELE_NOALLOC (1<<0u)
00159 #define ASREG_BPT (1<<0u)
00164 struct s_memdef
00165 {
00166 asid_t asid;
00167 u_int32_t addr;
00168 u_int32_t nb_pgs;
00169 #define SPACE_SELF ((asid_t)-1)
00170 #define SPACE_KERN ((asid_t)-2)
00171 #define SPACE_PHYS ((asid_t)-3)
00172 #define SPACE_SYS0 ((asid_t)-4)
00173 #define SPACE_SYS1 ((asid_t)-5)
00174 u_int32_t space;
00175 u_int32_t mode;
00176 u_int32_t modeopts;
00177 u_int32_t uid;
00178 u_int32_t gid;
00179 u_int32_t refcnt;
00180 };
00181 #define MEMDEF_RM_ONLY (1u<<0)
00182 #define MEMDEF_VIRT_ONLY (1u<<1)
00184
00185 #define ASF_RUNQ (1<<0u)
00186 #define ASF_PROTECTED (1<<1u)
00188 #define AS_EXPORT \
00189 asid_t asid; \
00190 pid_t pid; \
00191 uid_t uid; \
00192 u_int32_t flags; \
00193 u_int32_t exec_pc;\
00194 u_int32_t exec_sp;\
00195 u_int32_t exec_fp;\
00196 int refcnt;
00198 struct s_as_export
00199 {
00200 AS_EXPORT;
00201 };
00202
00203 typedef struct s_as_export t_as;
00204
00205 #ifdef __KERNEL__
00206 RUNQ_HEAD(s_as_runq, s_as_full);
00207 LIST_HEAD(s_as_list, s_as_full);
00208
00209 struct s_as_full
00210 {
00211 AS_EXPORT;
00212
00213 #define AS_MAGIC 0xcafebabe
00214 u_int32_t magic;
00215
00216 LIST_ENTRY(s_as_full) list_ht;
00217 RUNQ_ENTRY(s_as_full) runq;
00219 kaddr_t ka; \
00220 paddr_t pa; \
00221 paddr_t pgdir; \
00222
00223 t_area_set area_set;
00224 };
00225 #endif
00226
00230 #define ASOP_ATTACH 0
00231 #define ASOP_DETACH 1
00232 #define ASOP_NDATTACH 2
00237 struct rlimit
00238 {
00239 rlim_t rlim_cur;
00240 rlim_t rlim_max;
00241 };
00242
00246 #define RLIMIT_CPU 0
00247 #define RLIMIT_FSIZE 1
00248 #define RLIMIT_DATA 2
00249 #define RLIMIT_STACK 3
00250 #define RLIMIT_CORE 4
00251 #define RLIMIT_RSS 5
00252 #define RLIMIT_MEMLOCK 6
00253 #define RLIMIT_NPROC 7
00254 #define RLIMIT_NOFILE 8
00256 #define RLIM_NLIMITS 9
00258 #define RLIM_INFINITY (~((u_quad_t)1 << 63))
00259 #define RLIM_SAVED_MAX RLIM_INFINITY
00260 #define RLIM_SAVED_CUR RLIM_INFINITY
00265 #define F_OK 0
00266 #define X_OK 0x01
00267 #define W_OK 0x02
00268 #define R_OK 0x04
00273 #define SEEK_SET 0
00274 #define SEEK_CUR 1
00275 #define SEEK_END 2
00280 #define PT_TRACE_ME 0
00281 #define PT_READ_I 1
00282 #define PT_READ_D 2
00283 #define PT_WRITE_I 4
00284 #define PT_WRITE_D 5
00285 #define PT_CONTINUE 7
00286 #define PT_KILL 8
00287 #define PT_ATTACH 9
00288 #define PT_DETACH 10
00289 #define PT_IO 11
00291
00292
00293
00294 struct ptrace_io_desc
00295 {
00296 int piod_op;
00297 void *piod_offs;
00298 void *piod_addr;
00299 size_t piod_len;
00300 };
00301
00302 struct s_iomap
00303 {
00304 #define IO_SETSIZE 65536
00305 #define NBITS (sizeof (u_long) * NBBY)
00306 u_long masks[HOWMANY(IO_SETSIZE, NBITS)];
00307 };
00308
00309 #define IO_CLR(n, p) ((p)->masks[(n)/NBITS] &= ~(1 << ((n) % NBITS)))
00310 #define IO_SET(n, p) ((p)->masks[(n)/NBITS] |= (1 << ((n) % NBITS)))
00311 #define IO_ISSET(n, p) ((p)->masks[(n)/NBITS] & (1 << ((n) % NBITS)))
00312
00313 #define PRIORITY_DFLT 0
00314
00315 struct s_sigctx
00316 {
00317 vaddr_t eip;
00318 vaddr_t esp;
00319 t_tss tss;
00320 sigset_t o_sigmask;
00321 sigset_t sigmask;
00322 int restore;
00323 int code;
00324 u_int32_t flags;
00325 #define SIGF_TRIGGERED (1<<1u)
00326 #define SIGF_IGN (1<<2u)
00327 #define SIGF_NODFL (1<<3u)
00328 u_int32_t sa_flags;
00329 vaddr_t addr;
00330 };
00331
00335 struct s_usig
00336 {
00337 int sig;
00339 sigset_t pausemask;
00340 sigset_t sigmask;
00341 sigset_t sigpending;
00343 struct s_sigctx sigctxs[SIGMAX];
00344 #define SIGCTX(Usig, Sig) ((Usig)->sigctxs[(Sig)-1])
00345 };
00346
00347 struct s_ucred
00348 {
00349 uid_t uid;
00350 gid_t gid;
00351 uid_t ruid;
00352 gid_t rgid;
00353 #define NGROUPS 16
00354 gid_t groups[NGROUPS];
00355 };
00356
00357 struct s_ustat
00358 {
00359 u_int64_t elect;
00360 };
00361
00362 #define MAXTCBNAME 15
00363
00364
00365 #define OFF_CPU -1
00366 #define UNDEF_CPU -2
00368
00369 #define CPU_ANY -1
00371
00372 #define TCBS_IDLE 0
00373 #define TCBS_RUN 1
00374 #define TCBS_SLEEP 2
00375 #define TCBS_STOP 3
00376 #define TCBS_ZOMBIE 4
00377 #define TCBS_DEAD 5
00379
00380 #define TCBC_UNDEF 0
00381 #define TCBC_SCHED 1
00382 #define TCBC_SERVICE 2
00383 #define TCBC_REALTIME 3
00384 #define TCBC_KERNEL 4
00385
00386
00387 #define TCBF_ONPROC (1<<0u)
00388 #define TCBF_TRACED (1<<1u)
00389 #define TCBF_SIGNALABLE (1<<2u)
00390 #define TCBF_RUNQ (1<<3u)
00391 #define TCBF_IOMAP (1<<4u)
00392 #define TCBF_PAUSEMASK (1<<5u)
00393 #define TCBF_WAITINFO (1<<6u)
00394 #define TCBF_PTRACED (1<<7u)
00395 #define TCBF_WAITDONE (1<<8u)
00396 #define TCBF_COLLECTDONE (1<<9u)
00398 #define TCB_EXPORT \
00399 t_tss tss; \
00400 u_int sel; \
00401 pid_t pid; \
00402 pid_t ppid; \
00403 pid_t pgid; \
00404 asid_t asid; \
00405 char name[MAXTCBNAME + 1];\
00406 int priority; \
00407 int cpu; \
00408 int cpu_spec; \
00409 u_int32_t status; \
00410 u_int32_t class; \
00411 u_int32_t flags; \
00412 u_int32_t wstatus; \
00413 u_int sq_gate; \
00414 struct s_ucred ucred; \
00415 struct s_ustat ustat;
00417 struct s_tcb_export
00418 {
00419 TCB_EXPORT;
00420 };
00421
00422 typedef struct s_tcb_export t_tcb;
00423
00424 #ifdef __KERNEL__
00425 RUNQ_HEAD(s_tcb_runq, s_tcb_full);
00426 LIST_HEAD(s_tcb_list, s_tcb_full);
00427
00428 struct s_tcb_full
00429 {
00430 TCB_EXPORT;
00431
00432 #define TCB_MAGIC 0x42434445
00433 int magic; \
00434
00435 LIST_ENTRY(s_tcb_full) list;
00436 LIST_ENTRY(s_tcb_full) list_ht;
00437 RUNQ_ENTRY(s_tcb_full) runq;
00439 int sizepg;
00440 #define TCBSIG_SIZEPG(IomapPresent) \
00441 (ROUNDUP(ROUNDUP(sizeof (struct s_tcb_full), 4) + \
00442 ((IomapPresent)? sizeof (struct s_iomap) : 0) +\
00443 sizeof (struct s_usig), PAGESIZE)/PAGESIZE)
00444
00445 #define TCBNOSIG_SIZEPG(IomapPresent) \
00446 (ROUNDUP(ROUNDUP(sizeof (struct s_tcb_full), 4) + \
00447 ((IomapPresent)? sizeof (struct s_iomap) : 0), PAGESIZE)/PAGESIZE)
00448
00449 paddr_t pa;
00450 kaddr_t ka;
00452 union savefpu fpu;
00453 struct s_usig *usig;
00454
00455
00456
00457 };
00458
00459 # define TCB_INIT(Tcb, Pid, Sel) \
00460 (Tcb)->tss.link = 0; \
00461 (Tcb)->tss.es = (Tcb)->tss.ss = \
00462 (Tcb)->tss.ds = (Tcb)->tss.fs = \
00463 (Tcb)->tss.gs = \
00464 GSEL((ISRING(Sel) == 0 ? GDATA_IDXSEL : GUDATA_IDXSEL), \
00465 (ISRING(Sel) == 0 ? RING0 : RING3)); \
00466 (Tcb)->tss.cs = \
00467 GSEL((ISRING(Sel) == 0 ? GCODE_IDXSEL : GUCODE_IDXSEL), \
00468 (ISRING(Sel) == 0 ? RING0 : RING3)); \
00469 (Tcb)->tss.cr3 = 0; \
00470 (Tcb)->tss.eip = 0; \
00471 (Tcb)->tss.ebp = 0; \
00472 (Tcb)->tss.esp = 0; \
00473 (Tcb)->tss.eflags = 0; \
00474 (Tcb)->tss.ldts = 0; \
00475 (Tcb)->tss.debugtrap = 0; \
00476 (Tcb)->tss.iomapbase = ROUNDUP(sizeof (struct s_tcb_full), 4); \
00477 (Tcb)->tss.ss0 = 0; \
00478 (Tcb)->tss.esp0 = 0; \
00479 (Tcb)->tss.ss1 = 0; \
00480 (Tcb)->tss.esp1 = 0; \
00481 (Tcb)->tss.ss2 = 0; \
00482 (Tcb)->tss.esp2 = 0; \
00483 strncpy((Tcb)->name, "", MAXTCBNAME); \
00484 (Tcb)->magic = TCB_MAGIC; \
00485 (Tcb)->sizepg = 1; \
00486 (Tcb)->pa = (paddr_t)-1; \
00487 (Tcb)->sel = (Sel); \
00488 (Tcb)->pid = (Pid); \
00489 (Tcb)->ppid = 0LL; \
00490 (Tcb)->pgid = 1LL; \
00491 (Tcb)->asid = NO_ASID; \
00492 (Tcb)->cpu_spec = 0; \
00493 (Tcb)->cpu = UNDEF_CPU; \
00494 (Tcb)->ucred.uid = (Tcb)->ucred.gid = 0; \
00495 bzero(&(Tcb)->ustat, sizeof ((Tcb)->ustat)); \
00496 (Tcb)->status = TCBS_IDLE; \
00497 (Tcb)->class = TCBC_UNDEF; \
00498 (Tcb)->flags = 0u; \
00499 (Tcb)->wstatus = 0; \
00500 (Tcb)->usig = NULL;
00501 #endif
00502
00503
00504
00505
00506 #define BSTRAP_PID ((pid_t)0LL)
00507 #define KERNEL_PID ((pid_t)1LL)
00508 #define KERNEL_ASID ((asid_t)0LL)
00509 #define NO_ASID ((asid_t)-1LL)
00510
00514 struct s_procdef
00515 {
00516 u_int32_t flags;
00517 #define PROCDEF_ONGDT (1<<0u)
00518 struct s_tcb_export tcb;
00519 union descriptor desc;
00520 };
00521
00522
00523
00524
00525
00526 #define _W_INT(w) (*(int *)(void *)&(w))
00527 #define WCOREFLAG 0200
00528 #define _WSTATUS(x) (_W_INT(x) & 0177)
00529 #define _WSTOPPED 0177
00530 #define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED)
00531 #define WSTOPSIG(x) ((int)(((unsigned int)_W_INT(x)) >> 8) & 0xff)
00532 #define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)
00533 #define WTERMSIG(x) (_WSTATUS(x))
00534 #define WIFEXITED(x) (_WSTATUS(x) == 0)
00535 #define WEXITSTATUS(x) ((int)(((unsigned int)_W_INT(x)) >> 8) & 0xff)
00536 #define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG)
00537 #define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
00538 #define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED)
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549 #define WNOHANG 0x00000001
00550 #define WUNTRACED 0x00000002
00551
00552 #define WALTSIG 0x00000004
00553
00554
00555 #define WALLSIG 0x00000008
00556
00557
00558
00559
00560
00561
00562
00563
00564 union wait
00565 {
00566 int w_status;
00567
00568
00569
00570 struct
00571 {
00572 #if BYTE_ORDER == LITTLE_ENDIAN
00573 unsigned int w_Termsig:7,
00574 w_Coredump:1,
00575 w_Retcode:8,
00576 w_Filler:16;
00577 #endif
00578 #if BYTE_ORDER == BIG_ENDIAN
00579 unsigned int w_Filler:16,
00580 w_Retcode:8,
00581 w_Coredump:1,
00582 w_Termsig:7;
00583 #endif
00584 } w_T;
00585
00586
00587
00588
00589
00590 struct
00591 {
00592 #if BYTE_ORDER == LITTLE_ENDIAN
00593 unsigned int w_Stopval:8,
00594 w_Stopsig:8,
00595 w_Filler:16;
00596 #endif
00597 #if BYTE_ORDER == BIG_ENDIAN
00598 unsigned int w_Filler:16,
00599 w_Stopsig:8,
00600 w_Stopval:8;
00601 #endif
00602 } w_S;
00603 };
00604 #define w_termsig w_T.w_Termsig
00605 #define w_coredump w_T.w_Coredump
00606 #define w_retcode w_T.w_Retcode
00607 #define w_stopval w_S.w_Stopval
00608 #define w_stopsig w_S.w_Stopsig
00609
00610 #define WSTOPPED _WSTOPPED
00611
00612 struct rusage
00613 {
00614 int dummy;
00615 };
00616
00617 #define SET_SYS_RETURN(Tcb, Val, Errno, Suberrno) \
00618 do {\
00619 (Tcb)->tss.eax = (Val);\
00620 (Tcb)->tss.ebx = (Errno);\
00621 (Tcb)->tss.ecx = (Suberrno);\
00622 } while (0)
00623
00624 #define SYS_RETURN(Tcb, Val, Errno, Suberrno) \
00625 do {\
00626 SET_SYS_RETURN((Tcb), (Val), (Errno), (Suberrno));\
00627 return ;\
00628 } while (0)
00629
00630 #define SYS_ARG1(Tcb) ((Tcb)->tss.ebx)
00631 #define SYS_ARG2(Tcb) ((Tcb)->tss.ecx)
00632 #define SYS_ARG3(Tcb) ((Tcb)->tss.edx)
00633 #define SYS_ARG4(Tcb) ((Tcb)->tss.esi)
00634 #define SYS_ARG5(Tcb) ((Tcb)->tss.edi)
00635
00636 #include <core/main.h>
00637 #include <core/suberrno.h>
00638 #include <core/coresrv.h>
00639 #include <core/core_tcb.h>
00640 #include <core/core_mem.h>
00641 #include <core/core_sig.h>
00642 #include <core/core_cred.h>
00643 #include <core/trap.h>
00644 #include <core/pgflt.h>
00645 #include <core/dblflt.h>
00646 #include <core/stray.h>
00647 #include <core/breakpoint.h>
00648 #include <core/npx.h>
00649 #include <core/syscall.h>
00650 #include <core/syscallargs.h>
00651 #include <core/vm86.h>
00652
00653 #ifdef __LSEOS_RELEASE_SPECIFIC__
00654 static __inline
00655 int __sfulltcb2(pid_t pid, struct s_tcb_full *tcb_returned)
00656 {
00657 int retval;
00658
00659 CORE_SYSCALL5(retval, SYSCORE___SFULLTCB2,
00660 QUAD_HIGH(pid), QUAD_LOW(pid),
00661 (int)tcb_returned,
00662 0, 0);
00663
00664 return (retval);
00665 }
00666
00667 static __inline
00668 int __sfulllink(struct s_tcb_full *tcb_returned)
00669 {
00670 int retval;
00671
00672 CORE_SYSCALL5(retval, SYSCORE___SFULLLINK,
00673 (int)tcb_returned,
00674 0, 0, 0, 0);
00675
00676 return (retval);
00677 }
00678
00679 static __inline
00680 int __sfullas(asid_t asid, struct s_as_full *aspace_returned)
00681 {
00682 int retval;
00683
00684 CORE_SYSCALL5(retval, SYSCORE___SFULLAS,
00685 QUAD_HIGH(asid), QUAD_LOW(asid),
00686 (int)aspace_returned,
00687 0, 0);
00688
00689 return (retval);
00690 }
00691 #endif
00692
00693 #endif