TheLuaOSProject / Kernel

Kernel for the LuaOS operating system
GNU General Public License v3.0
35 stars 4 forks source link

`var_lookup_local` sometimes faults #24

Open Frityet opened 1 year ago

Frityet commented 1 year ago

Offending code, specifically the if statment

/* Lookup local variable name. */
static BCReg var_lookup_local(FuncState *fs, GCstr *n)
{
  int i;
  for (i = fs->nactvar-1; i >= 0; i--) {
    if (n == strref(var_get(fs->ls, fs, i).name))
      return (BCReg)i;
  }
  return (BCReg)-1;  /* Not found. */
}

Log:

Started LuaOS
[*] start.c:105 2 + 2 = 4
[*] start.c:106 Hello, World!
[*] start.c:108 Initialising GDT
[+] gdt.c:42 Done
[+] start.c:110 Done
[*] start.c:112 Initialising IDT
[+] start.c:114 Done
[*] start.c:117 Initialising memory
[*] start.c:119   Magazines...
[+] start.c:121   Done
[*] start.c:123   Kernel memory allocator...
[+] start.c:125   Done
[+] start.c:127 Done
[*] start.c:137 Initialising APIC
[*] start.c:147   Found entry with ID 0
[+] start.c:151   Found LAPIC at core 0 (address: 0xFFFF80007FB7802C)
[*] start.c:152     Processor ID: 0
[*] start.c:153     APIC ID: 0
[*] start.c:154     Flags: 1
[*] start.c:147   Found entry with ID 0
[+] start.c:151   Found LAPIC at core 1 (address: 0xFFFF80007FB78034)
[*] start.c:152     Processor ID: 1
[*] start.c:153     APIC ID: 1
[*] start.c:154     Flags: 1
[*] start.c:147   Found entry with ID 1
[*] start.c:147   Found entry with ID 2
[*] start.c:147   Found entry with ID 2
[*] start.c:147   Found entry with ID 2
[*] start.c:147   Found entry with ID 2
[*] start.c:147   Found entry with ID 2
[*] start.c:147   Found entry with ID 4
[+] start.c:159 Done
[*] start.c:161 Initalising LAPIC
[*] start.c:163 LAPIC base: 0xFFFF8000FEE00000
[+] start.c:164 Done
[*] start.c:171 Initialising scheduler
[+] start.c:173 Done
[*] idt.c:63 CPU Info
[*] idt.c:64 RAX: 0x0000000000000202 | RBX: 0x0000700000211EA0 | RCX: 0xB4458A00000B3CE8 | RDX: 0x00000000000C0000
[*] idt.c:65 RSI: 0x0000000000000000 | RDI: 0xFFFF80007FE2F8D0 | RSP: 0xFFFF80007FE2F720 | RBP: 0xFFFF80007FE2F720
[*] idt.c:66 R8:  0x0000000000000000 | R9:  0x0000000000000000 | R10: 0x0000000000000000 | R11: 0xFFFFFFFFFFFFFFF7
[*] idt.c:67 R12: 0xFFFF80007E4FB000 | R13: 0xFFFFFFFF8005190F | R14: 0x0000700000212328 | R15: 0x0000000000000000
[*] idt.c:68 RIP: 0xFFFFFFFF800338FA | RFL: 0x0000000000000286 | ERR: 0x0000000000000000 | ISR: 0x000000000000000D
[-] idt.c:80 unexpected interrupt!

Possible causes:

Frityet commented 1 year ago

Another exception from a different part of LuaJIT, specifically from the return hashgcref(t, key->gcr).

/* Hash an arbitrary key and return its anchor position in the hash table. */
static Node *hashkey(const GCtab *t, cTValue *key)
{
  lj_assertX(!tvisint(key), "attempt to hash integer");
  if (tvisstr(key))
    return hashstr(t, strV(key));
  else if (tvisnum(key))
    return hashnum(t, key);
  else if (tvisbool(key))
    return hashmask(t, boolV(key));
  else
    return hashgcref(t, key->gcr);
  /* Only hash 32 bits of lightuserdata on a 64 bit CPU. Good enough? */
}

Log:

[+] start.c:104 
Started LuaOS
[*] start.c:105 2 + 2 = 4
[*] start.c:106 Hello, World!
[*] start.c:108 Initialising GDT
[+] gdt.c:42 Done
[+] start.c:110 Done
[*] start.c:112 Initialising IDT
[+] start.c:114 Done
[*] start.c:117 Initialising memory
[*] start.c:119   Magazines...
[+] start.c:121   Done
[*] start.c:123   Kernel memory allocator...
[+] start.c:125   Done
[+] start.c:127 Done
[*] start.c:137 Initialising APIC
[*] rsdp.c:42   XSDT not supported on this machine; using RSDT
[*] start.c:147   Found entry with ID 0
[+] start.c:151   Found LAPIC at core 0 (address: 0xFFFF80007FFE223A)
[*] start.c:152     Processor ID: 0
[*] start.c:153     APIC ID: 0
[*] start.c:154     Flags: 1
[*] start.c:147   Found entry with ID 0
[+] start.c:151   Found LAPIC at core 1 (address: 0xFFFF80007FFE2242)
[*] start.c:152     Processor ID: 1
[*] start.c:153     APIC ID: 1
[*] start.c:154     Flags: 1
[*] start.c:147   Found entry with ID 1
[*] start.c:147   Found entry with ID 2
[*] start.c:147   Found entry with ID 2
[*] start.c:147   Found entry with ID 2
[*] start.c:147   Found entry with ID 2
[*] start.c:147   Found entry with ID 2
[*] start.c:147   Found entry with ID 4
[+] start.c:159 Done
[*] start.c:161 Initalising LAPIC
[*] start.c:163 LAPIC base: 0xFFFF8000FEE00000
[+] start.c:164 Done
[*] start.c:171 Initialising scheduler
[+] start.c:173 Done
[*] idt.c:63 CPU Info
[*] idt.c:64 RAX: 0x0000000000000000 | RBX: 0x0000700000454EA0 | RCX: 0x0000700000457A00 | RDX: 0xFFFF80007FF683A8
[*] idt.c:65 RSI: 0xFFFF80007FF683A8 | RDI: 0x0000700000457A00 | RSP: 0xFFFF80007FF68338 | RBP: 0xFFFF80007FF68340
[*] idt.c:66 R8:  0x0000000000000000 | R9:  0x0000000000000000 | R10: 0x0000000000000008 | R11: 0xFFFFFFFFFFFFFFF7
[*] idt.c:67 R12: 0xFFFF80007F892000 | R13: 0xFFFFFFFF8005190F | R14: 0x0000700000455328 | R15: 0x0000000000000000
[*] idt.c:68 RIP: 0xFFFFFFFF80043C3E | RFL: 0x0000000000000202 | ERR: 0x0000000000000000 | ISR: 0x000000000000000E
[-] idt.c:80 unexpected interrupt!