1 /* See COPYRIGHT for copyright information. */
7 #include <ros/common.h>
8 #include <arch/types.h>
11 #include <arch/console.h>
29 #include <colored_caches.h>
30 #include <hashtable.h>
35 #include <arsc_server.h>
39 #ifdef __CONFIG_NETWORKING__
40 #include <arch/nic_common.h>
41 extern int (*send_frame)(const char *CT(len) data, size_t len);
42 extern unsigned char device_mac[6];
46 int systrace_flags = 0;
47 struct systrace_record *systrace_buffer = 0;
48 uint32_t systrace_bufidx = 0;
49 size_t systrace_bufsize = 0;
50 struct proc *systrace_procs[MAX_NUM_TRACED] = {0};
51 spinlock_t systrace_lock = SPINLOCK_INITIALIZER;
53 /* Not enforcing the packing of systrace_procs yet, but don't rely on that */
54 static bool proc_is_traced(struct proc *p)
56 for (int i = 0; i < MAX_NUM_TRACED; i++)
57 if (systrace_procs[i] == p)
62 /* Helper to finish a syscall, signalling if appropriate */
63 static void finish_sysc(struct syscall *sysc, struct proc *p)
65 /* Atomically turn on the LOCK and SC_DONE flag. The lock tells userspace
66 * we're messing with the flags and to not proceed. We use it instead of
67 * CASing with userspace. We need the atomics since we're racing with
68 * userspace for the event_queue registration. The 'lock' tells userspace
69 * to not muck with the flags while we're signalling. */
70 atomic_or(&sysc->flags, SC_K_LOCK | SC_DONE);
71 __signal_syscall(sysc, p);
72 atomic_and(&sysc->flags, ~SC_K_LOCK);
75 /* Helper that "finishes" the current async syscall. This should be used when
76 * we are calling a function in a syscall that might not return and won't be
77 * able to use the normal syscall return path, such as proc_yield() and
78 * resource_req(). Call this from within syscall.c (I don't want it global).
80 * It is possible for another user thread to see the syscall being done early -
81 * they just need to be careful with the weird proc management calls (as in,
82 * don't trust an async fork).
84 * *sysc is in user memory, and should be pinned (TODO: UMEM). There may be
85 * issues with unpinning this if we never return. */
86 static void finish_current_sysc(int retval)
88 struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
89 assert(pcpui->cur_sysc);
90 pcpui->cur_sysc->retval = retval;
91 finish_sysc(pcpui->cur_sysc, pcpui->cur_proc);
94 /* Callable by any function while executing a syscall (or otherwise, actually).
96 void set_errno(int errno)
98 struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
100 pcpui->cur_sysc->err = errno;
103 /************** Utility Syscalls **************/
105 static int sys_null(void)
110 /* Diagnostic function: blocks the kthread/syscall, to help userspace test its
111 * async I/O handling. */
112 static int sys_block(struct proc *p, unsigned int usec)
114 struct timer_chain *tchain = &per_cpu_info[core_id()].tchain;
115 struct alarm_waiter a_waiter;
116 init_awaiter(&a_waiter, 0);
117 /* Note printing takes a few ms, so your printds won't be perfect. */
118 printd("[kernel] sys_block(), sleeping at %llu\n", read_tsc());
119 set_awaiter_rel(&a_waiter, usec);
120 set_alarm(tchain, &a_waiter);
121 sleep_on_awaiter(&a_waiter);
122 printd("[kernel] sys_block(), waking up at %llu\n", read_tsc());
126 // Writes 'val' to 'num_writes' entries of the well-known array in the kernel
127 // address space. It's just #defined to be some random 4MB chunk (which ought
128 // to be boot_alloced or something). Meant to grab exclusive access to cache
129 // lines, to simulate doing something useful.
130 static int sys_cache_buster(struct proc *p, uint32_t num_writes,
131 uint32_t num_pages, uint32_t flags)
132 { TRUSTEDBLOCK /* zra: this is not really part of the kernel */
133 #define BUSTER_ADDR 0xd0000000L // around 512 MB deep
134 #define MAX_WRITES 1048576*8
136 #define INSERT_ADDR (UINFO + 2*PGSIZE) // should be free for these tests
137 uint32_t* buster = (uint32_t*)BUSTER_ADDR;
138 static spinlock_t buster_lock = SPINLOCK_INITIALIZER;
140 page_t* a_page[MAX_PAGES];
142 /* Strided Accesses or Not (adjust to step by cachelines) */
144 if (flags & BUSTER_STRIDED) {
149 /* Shared Accesses or Not (adjust to use per-core regions)
150 * Careful, since this gives 8MB to each core, starting around 512MB.
151 * Also, doesn't separate memory for core 0 if it's an async call.
153 if (!(flags & BUSTER_SHARED))
154 buster = (uint32_t*)(BUSTER_ADDR + core_id() * 0x00800000);
156 /* Start the timer, if we're asked to print this info*/
157 if (flags & BUSTER_PRINT_TICKS)
158 ticks = start_timing();
160 /* Allocate num_pages (up to MAX_PAGES), to simulate doing some more
161 * realistic work. Note we don't write to these pages, even if we pick
162 * unshared. Mostly due to the inconvenience of having to match up the
163 * number of pages with the number of writes. And it's unnecessary.
166 spin_lock(&buster_lock);
167 for (int i = 0; i < MIN(num_pages, MAX_PAGES); i++) {
168 upage_alloc(p, &a_page[i],1);
169 page_insert(p->env_pgdir, a_page[i], (void*)INSERT_ADDR + PGSIZE*i,
171 page_decref(a_page[i]);
173 spin_unlock(&buster_lock);
176 if (flags & BUSTER_LOCKED)
177 spin_lock(&buster_lock);
178 for (int i = 0; i < MIN(num_writes, MAX_WRITES); i=i+stride)
179 buster[i] = 0xdeadbeef;
180 if (flags & BUSTER_LOCKED)
181 spin_unlock(&buster_lock);
184 spin_lock(&buster_lock);
185 for (int i = 0; i < MIN(num_pages, MAX_PAGES); i++) {
186 page_remove(p->env_pgdir, (void*)(INSERT_ADDR + PGSIZE * i));
187 page_decref(a_page[i]);
189 spin_unlock(&buster_lock);
193 if (flags & BUSTER_PRINT_TICKS) {
194 ticks = stop_timing(ticks);
195 printk("%llu,", ticks);
200 static int sys_cache_invalidate(void)
208 /* sys_reboot(): called directly from dispatch table. */
210 /* Print a string to the system console. */
211 static ssize_t sys_cputs(struct proc *p, const char *DANGEROUS string,
215 t_string = user_strdup_errno(p, string, strlen);
218 printk("%.*s", strlen, t_string);
219 user_memdup_free(p, t_string);
220 return (ssize_t)strlen;
223 // Read a character from the system console.
224 // Returns the character.
225 static uint16_t sys_cgetc(struct proc *p)
229 // The cons_getc() primitive doesn't wait for a character,
230 // but the sys_cgetc() system call does.
231 while ((c = cons_getc()) == 0)
237 /* Returns the id of the cpu this syscall is executed on. */
238 static uint32_t sys_getcpuid(void)
243 // TODO: Temporary hack until thread-local storage is implemented on i386 and
244 // this is removed from the user interface
245 static size_t sys_getvcoreid(struct proc *p)
247 return proc_get_vcoreid(p, core_id());
250 /************** Process management syscalls **************/
252 /* Returns the calling process's pid */
253 static pid_t sys_getpid(struct proc *p)
258 /* Creates a process from the file 'path'. The process is not runnable by
259 * default, so it needs it's status to be changed so that the next call to
260 * schedule() will try to run it. TODO: take args/envs from userspace. */
261 static int sys_proc_create(struct proc *p, char *path, size_t path_l,
266 struct file *program;
269 /* Copy in the path. Consider putting an upper bound on path_l. */
270 t_path = user_strdup_errno(p, path, path_l);
273 program = do_file_open(t_path, 0, 0);
274 user_memdup_free(p, t_path);
276 return -1; /* presumably, errno is already set */
277 /* TODO: need to split the proc creation, since you must load after setting
278 * args/env, since auxp gets set up there. */
279 //new_p = proc_create(program, 0, 0);
280 if (proc_alloc(&new_p, current))
282 /* Set the argument stuff needed by glibc */
283 if (memcpy_from_user_errno(p, new_p->procinfo->argp, pi->argp,
286 if (memcpy_from_user_errno(p, new_p->procinfo->argbuf, pi->argbuf,
289 if (load_elf(new_p, program))
291 kref_put(&program->f_kref);
292 /* Connect to stdin, stdout, stderr (part of proc_create()) */
293 assert(insert_file(&new_p->open_files, dev_stdin, 0) == 0);
294 assert(insert_file(&new_p->open_files, dev_stdout, 0) == 1);
295 assert(insert_file(&new_p->open_files, dev_stderr, 0) == 2);
298 proc_decref(new_p); /* give up the reference created in proc_create() */
302 proc_decref(new_p); /* give up the reference created in proc_create() */
304 kref_put(&program->f_kref);
308 /* Makes process PID runnable. Consider moving the functionality to process.c */
309 static error_t sys_proc_run(struct proc *p, unsigned pid)
311 struct proc *target = pid2proc(pid);
316 // note we can get interrupted here. it's not bad.
317 spin_lock(&p->proc_lock);
318 // make sure we have access and it's in the right state to be activated
319 if (!proc_controls(p, target)) {
322 } else if (target->state != PROC_CREATED) {
326 __proc_set_state(target, PROC_RUNNABLE_S);
327 schedule_proc(target);
329 spin_unlock(&p->proc_lock);
334 /* Destroy proc pid. If this is called by the dying process, it will never
335 * return. o/w it will return 0 on success, or an error. Errors include:
336 * - EBADPROC: if there is no such process with pid
337 * - EPERM: if caller does not control pid */
338 static error_t sys_proc_destroy(struct proc *p, pid_t pid, int exitcode)
341 struct proc *p_to_die = pid2proc(pid);
347 if (!proc_controls(p, p_to_die)) {
348 proc_decref(p_to_die);
353 p->exitcode = exitcode;
354 printd("[PID %d] proc exiting gracefully (code %d)\n", p->pid,exitcode);
356 p_to_die->exitcode = exitcode; /* so its parent has some clue */
357 printd("[%d] destroying proc %d\n", p->pid, p_to_die->pid);
359 proc_destroy(p_to_die);
360 /* we only get here if we weren't the one to die */
361 proc_decref(p_to_die);
365 static int sys_proc_yield(struct proc *p, bool being_nice)
367 /* proc_yield() often doesn't return - we need to set the syscall retval
368 * early. If it doesn't return, it expects to eat our reference (for now).
370 finish_current_sysc(0);
372 proc_yield(p, being_nice);
377 static void sys_change_vcore(struct proc *p, uint32_t vcoreid,
378 bool enable_my_notif)
380 struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
381 /* Change to vcore may start the vcore up remotely before we can finish the
382 * async syscall, so we need to finish the sysc and not touch the struct.
383 * Note this sysc has no return value. */
384 finish_sysc(pcpui->cur_sysc, pcpui->cur_proc);
385 pcpui->cur_sysc = 0; /* don't touch sysc again */
386 proc_change_to_vcore(p, vcoreid, enable_my_notif);
387 /* Shouldn't return, to prevent the chance of mucking with cur_sysc.
388 * smp_idle will make sure we run the appropriate cur_tf (which will be the
389 * new vcore for successful calls). */
393 static ssize_t sys_fork(env_t* e)
396 // TODO: right now we only support fork for single-core processes
397 if (e->state != PROC_RUNNING_S) {
402 assert(!proc_alloc(&env, current));
405 env->heap_top = e->heap_top;
407 disable_irqsave(&state); /* protect cur_tf */
408 /* Can't really fork if we don't have a current_tf to fork */
413 env->env_tf = *current_tf;
414 enable_irqsave(&state);
416 /* We need to speculatively say the syscall worked before copying the memory
417 * out, since the 'forked' process's call never actually goes through the
418 * syscall return path, and will never think it is done. This violates a
419 * few things. Just be careful with fork. */
420 finish_current_sysc(0);
422 env->cache_colors_map = cache_colors_map_alloc();
423 for(int i=0; i < llc_cache->num_colors; i++)
424 if(GET_BITMASK_BIT(e->cache_colors_map,i))
425 cache_color_alloc(llc_cache, env->cache_colors_map);
427 duplicate_vmrs(e, env);
429 int copy_page(env_t* e, pte_t* pte, void* va, void* arg)
431 env_t* env = (env_t*)arg;
433 if(PAGE_PRESENT(*pte))
436 if(upage_alloc(env,&pp,0))
438 if(page_insert(env->env_pgdir,pp,va,*pte & PTE_PERM))
443 pagecopy(page2kva(pp),ppn2kva(PTE2PPN(*pte)));
446 assert(PAGE_PAGED_OUT(*pte));
447 /* TODO: (SWAP) will need to either make a copy or CoW/refcnt the
448 * backend store. For now, this PTE will be the same as the
450 panic("Swapping not supported!");
451 pte_t* newpte = pgdir_walk(env->env_pgdir,va,1);
459 /* In general, a forked process should be a fresh process, and we copy over
460 * whatever stuff is needed between procinfo/procdata. */
461 /* Copy over the procinfo argument stuff in case they don't exec */
462 memcpy(env->procinfo->argp, e->procinfo->argp, sizeof(e->procinfo->argp));
463 memcpy(env->procinfo->argbuf, e->procinfo->argbuf,
464 sizeof(e->procinfo->argbuf));
466 /* new guy needs to know about ldt (everything else in procdata is fresh */
467 env->procdata->ldt = e->procdata->ldt;
470 /* for now, just copy the contents of every present page in the entire
472 if (env_user_mem_walk(e, 0, UMAPTOP, ©_page, env)) {
473 proc_destroy(env); /* this is prob what you want, not decref by 2 */
478 clone_files(&e->open_files, &env->open_files);
480 __proc_set_state(env, PROC_RUNNABLE_S);
483 // don't decref the new process.
484 // that will happen when the parent waits for it.
485 // TODO: if the parent doesn't wait, we need to change the child's parent
486 // when the parent dies, or at least decref it
488 printd("[PID %d] fork PID %d\n",e->pid,env->pid);
492 /* Load the binary "path" into the current process, and start executing it.
493 * argv and envp are magically bundled in procinfo for now. Keep in sync with
494 * glibc's sysdeps/ros/execve.c. Once past a certain point, this function won't
495 * return. It assumes (and checks) that it is current. Don't give it an extra
496 * refcnt'd *p (syscall won't do that).
497 * Note: if someone batched syscalls with this call, they could clobber their
498 * old memory (and will likely PF and die). Don't do it... */
499 static int sys_exec(struct proc *p, char *path, size_t path_l,
504 struct file *program;
505 struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
508 /* We probably want it to never be allowed to exec if it ever was _M */
509 if (p->state != PROC_RUNNING_S) {
513 if (p != pcpui->cur_proc) {
517 /* Copy in the path. Consider putting an upper bound on path_l. */
518 t_path = user_strdup_errno(p, path, path_l);
521 disable_irqsave(&state); /* protect cur_tf */
522 /* Can't exec if we don't have a current_tf to restart (if we fail). This
523 * isn't 100% true, but I'm okay with it. */
524 if (!pcpui->cur_tf) {
525 enable_irqsave(&state);
529 /* Preemptively copy out the cur_tf, in case we fail later (easier on cur_tf
530 * if we do this now) */
531 p->env_tf = *pcpui->cur_tf;
532 /* Clear the current_tf. We won't be returning the 'normal' way. Even if
533 * we want to return with an error, we need to go back differently in case
534 * we succeed. This needs to be done before we could possibly block, but
535 * unfortunately happens before the point of no return. */
537 enable_irqsave(&state);
538 /* This could block: */
539 program = do_file_open(t_path, 0, 0);
540 user_memdup_free(p, t_path);
543 /* Set the argument stuff needed by glibc */
544 if (memcpy_from_user_errno(p, p->procinfo->argp, pi->argp,
547 if (memcpy_from_user_errno(p, p->procinfo->argbuf, pi->argbuf,
550 /* This is the point of no return for the process. */
552 /* clear this, so the new program knows to get an LDT */
553 p->procdata->ldt = 0;
556 close_all_files(&p->open_files, TRUE);
557 env_user_mem_free(p, 0, UMAPTOP);
558 if (load_elf(p, program)) {
559 kref_put(&program->f_kref);
560 /* Note this is an inedible reference, but proc_destroy now returns */
562 /* We don't want to do anything else - we just need to not accidentally
563 * return to the user (hence the all_out) */
566 printd("[PID %d] exec %s\n", p->pid, file_name(program));
567 kref_put(&program->f_kref);
569 /* These error and out paths are so we can handle the async interface, both
570 * for when we want to error/return to the proc, as well as when we succeed
571 * and want to start the newly exec'd _S */
573 /* These two error paths are for when we want to restart the process with an
574 * error value (errno is already set). */
575 kref_put(&program->f_kref);
577 finish_current_sysc(-1);
579 /* Here's how we'll restart the new (or old) process: */
580 spin_lock(&p->proc_lock);
581 __unmap_vcore(p, 0); /* VC# keep in sync with proc_run _S */
582 __proc_set_state(p, PROC_RUNNABLE_S);
584 spin_unlock(&p->proc_lock);
586 /* we can't return, since we'd write retvals to the old location of the
587 * syscall struct (which has been freed and is in the old userspace) (or has
588 * already been written to).*/
589 disable_irq(); /* abandon_core/clear_own wants irqs disabled */
590 clear_owning_proc(core_id());
592 smp_idle(); /* will reenable interrupts */
595 static ssize_t sys_trywait(env_t* e, pid_t pid, int* status)
597 struct proc* p = pid2proc(pid);
599 // TODO: this syscall is racy, so we only support for single-core procs
600 if(e->state != PROC_RUNNING_S)
603 // TODO: need to use errno properly. sadly, ROS error codes conflict..
609 if(current->pid == p->ppid)
611 if(p->state == PROC_DYING)
613 memcpy_to_user(e,status,&p->exitcode,sizeof(int));
614 printd("[PID %d] waited for PID %d (code %d)\n",
615 e->pid,p->pid,p->exitcode);
624 else // not a child of the calling process
630 // if the wait succeeded, decref twice
641 /************** Memory Management Syscalls **************/
643 static void *sys_mmap(struct proc *p, uintptr_t addr, size_t len, int prot,
644 int flags, int fd, off_t offset)
646 return mmap(p, addr, len, prot, flags, fd, offset);
649 static intreg_t sys_mprotect(struct proc *p, void *addr, size_t len, int prot)
651 return mprotect(p, (uintptr_t)addr, len, prot);
654 static intreg_t sys_munmap(struct proc *p, void *addr, size_t len)
656 return munmap(p, (uintptr_t)addr, len);
659 static ssize_t sys_shared_page_alloc(env_t* p1,
660 void**DANGEROUS _addr, pid_t p2_id,
661 int p1_flags, int p2_flags
664 printk("[kernel] shared page alloc is deprecated/unimplemented.\n");
668 static int sys_shared_page_free(env_t* p1, void*DANGEROUS addr, pid_t p2)
674 static int sys_resource_req(struct proc *p, int type, unsigned int amt_wanted,
675 unsigned int amt_wanted_min, int flags)
677 /* resource_req returns and we'll eventually finish the sysc later. The
678 * original context may restart on a remote core before we return and
679 * finish, but that's fine thanks to the async kernel interface. */
680 return resource_req(p, type, amt_wanted, amt_wanted_min, flags);
683 /* Untested. Will notify the target on the given vcore, if the caller controls
684 * the target. Will honor the target's wanted/vcoreid. u_ne can be NULL. */
685 static int sys_notify(struct proc *p, int target_pid, unsigned int ev_type,
686 struct event_msg *u_msg)
688 struct event_msg local_msg = {0};
689 struct proc *target = pid2proc(target_pid);
694 if (!proc_controls(p, target)) {
699 /* if the user provided an ev_msg, copy it in and use that */
701 if (memcpy_from_user(p, &local_msg, u_msg, sizeof(struct event_msg))) {
707 send_kernel_event(target, &local_msg, 0);
712 /* Will notify the calling process on the given vcore, independently of WANTED
713 * or advertised vcoreid. If you change the parameters, change pop_ros_tf() */
714 static int sys_self_notify(struct proc *p, uint32_t vcoreid,
715 unsigned int ev_type, struct event_msg *u_msg)
717 struct event_msg local_msg = {0};
719 printd("[kernel] received self notify for vcoreid %d, type %d, msg %08p\n",
720 vcoreid, ev_type, u_msg);
721 /* if the user provided an ev_msg, copy it in and use that */
723 if (memcpy_from_user(p, &local_msg, u_msg, sizeof(struct event_msg))) {
728 /* this will post a message and IPI, regardless of wants/needs/debutantes.*/
729 post_vcore_event(p, &local_msg, vcoreid, EVENT_VCORE_PRIVATE);
730 proc_notify(p, vcoreid);
734 /* This will set a local timer for usec, then shut down the core. There's a
735 * slight race between spinner and halt. For now, the core will wake up for
736 * other interrupts and service them, but will not process routine messages or
737 * do anything other than halt until the alarm goes off. We could just unset
738 * the alarm and return early. On hardware, there are a lot of interrupts that
739 * come in. If we ever use this, we can take a closer look. */
740 static int sys_halt_core(struct proc *p, unsigned int usec)
742 struct timer_chain *tchain = &per_cpu_info[core_id()].tchain;
743 struct alarm_waiter a_waiter;
745 void unblock(struct alarm_waiter *waiter)
749 init_awaiter(&a_waiter, unblock);
750 set_awaiter_rel(&a_waiter, MAX(usec, 100));
751 set_alarm(tchain, &a_waiter);
753 /* Could wake up due to another interrupt, but we want to sleep still. */
755 cpu_halt(); /* slight race between spinner and halt */
758 printd("Returning from halting\n");
762 /************** Platform Specific Syscalls **************/
764 //Read a buffer over the serial port
765 static ssize_t sys_serial_read(env_t* e, char *DANGEROUS _buf, size_t len)
767 printk("[kernel] serial reading is deprecated.\n");
771 #ifdef __CONFIG_SERIAL_IO__
772 char *COUNT(len) buf = user_mem_assert(e, _buf, len, 1, PTE_USER_RO);
773 size_t bytes_read = 0;
775 while((c = serial_read_byte()) != -1) {
776 buf[bytes_read++] = (uint8_t)c;
777 if(bytes_read == len) break;
779 return (ssize_t)bytes_read;
785 //Write a buffer over the serial port
786 static ssize_t sys_serial_write(env_t* e, const char *DANGEROUS buf, size_t len)
788 printk("[kernel] serial writing is deprecated.\n");
791 #ifdef __CONFIG_SERIAL_IO__
792 char *COUNT(len) _buf = user_mem_assert(e, buf, len, 1, PTE_USER_RO);
793 for(int i =0; i<len; i++)
794 serial_send_byte(buf[i]);
801 #ifdef __CONFIG_NETWORKING__
802 // This is not a syscall we want. Its hacky. Here just for syscall stuff until get a stack.
803 static ssize_t sys_eth_read(env_t* e, char *DANGEROUS buf)
810 spin_lock(&packet_buffers_lock);
812 if (num_packet_buffers == 0) {
813 spin_unlock(&packet_buffers_lock);
817 ptr = packet_buffers[packet_buffers_head];
818 len = packet_buffers_sizes[packet_buffers_head];
820 num_packet_buffers--;
821 packet_buffers_head = (packet_buffers_head + 1) % MAX_PACKET_BUFFERS;
823 spin_unlock(&packet_buffers_lock);
825 char* _buf = user_mem_assert(e, buf, len, 1, PTE_U);
827 memcpy(_buf, ptr, len);
837 // This is not a syscall we want. Its hacky. Here just for syscall stuff until get a stack.
838 static ssize_t sys_eth_write(env_t* e, const char *DANGEROUS buf, size_t len)
845 // HACK TO BYPASS HACK
846 int just_sent = send_frame(buf, len);
849 printk("Packet send fail\n");
855 // END OF RECURSIVE HACK
857 char *COUNT(len) _buf = user_mem_assert(e, buf, len, PTE_U);
860 int cur_packet_len = 0;
861 while (total_sent != len) {
862 cur_packet_len = ((len - total_sent) > MTU) ? MTU : (len - total_sent);
863 char dest_mac[6] = APPSERVER_MAC_ADDRESS;
864 char* wrap_buffer = eth_wrap(_buf + total_sent, cur_packet_len, device_mac, dest_mac, APPSERVER_PORT);
865 just_sent = send_frame(wrap_buffer, cur_packet_len + sizeof(struct ETH_Header));
868 return 0; // This should be an error code of its own
873 total_sent += cur_packet_len;
883 static ssize_t sys_eth_get_mac_addr(env_t* e, char *DANGEROUS buf)
886 for (int i = 0; i < 6; i++)
887 buf[i] = device_mac[i];
894 static int sys_eth_recv_check(env_t* e)
896 if (num_packet_buffers != 0)
904 static intreg_t sys_read(struct proc *p, int fd, void *buf, int len)
907 struct file *file = get_file_from_fd(&p->open_files, fd);
912 if (!file->f_op->read) {
913 kref_put(&file->f_kref);
917 /* TODO: (UMEM) currently, read() handles user memcpy issues, but we
918 * probably should user_mem_check and pin the region here, so read doesn't
920 ret = file->f_op->read(file, buf, len, &file->f_pos);
921 kref_put(&file->f_kref);
925 static intreg_t sys_write(struct proc *p, int fd, const void *buf, int len)
928 struct file *file = get_file_from_fd(&p->open_files, fd);
933 if (!file->f_op->write) {
934 kref_put(&file->f_kref);
939 ret = file->f_op->write(file, buf, len, &file->f_pos);
940 kref_put(&file->f_kref);
944 /* Checks args/reads in the path, opens the file, and inserts it into the
945 * process's open file list.
947 * TODO: take the path length */
948 static intreg_t sys_open(struct proc *p, const char *path, size_t path_l,
954 printd("File %s Open attempt\n", path);
955 char *t_path = user_strdup_errno(p, path, path_l);
958 mode &= ~p->fs_env.umask;
959 file = do_file_open(t_path, oflag, mode);
960 user_memdup_free(p, t_path);
963 fd = insert_file(&p->open_files, file, 0); /* stores the ref to file */
964 kref_put(&file->f_kref);
966 warn("File insertion failed");
969 printd("File %s Open, res=%d\n", path, fd);
973 static intreg_t sys_close(struct proc *p, int fd)
975 struct file *file = put_file_from_fd(&p->open_files, fd);
983 /* kept around til we remove the last ufe */
984 #define ufe(which,a0,a1,a2,a3) \
985 frontend_syscall_errno(p,APPSERVER_SYSCALL_##which,\
986 (int)(a0),(int)(a1),(int)(a2),(int)(a3))
988 static intreg_t sys_fstat(struct proc *p, int fd, struct kstat *u_stat)
991 struct file *file = get_file_from_fd(&p->open_files, fd);
996 kbuf = kmalloc(sizeof(struct kstat), 0);
998 kref_put(&file->f_kref);
1002 stat_inode(file->f_dentry->d_inode, kbuf);
1003 kref_put(&file->f_kref);
1004 /* TODO: UMEM: pin the memory, copy directly, and skip the kernel buffer */
1005 if (memcpy_to_user_errno(p, u_stat, kbuf, sizeof(struct kstat))) {
1014 /* sys_stat() and sys_lstat() do nearly the same thing, differing in how they
1015 * treat a symlink for the final item, which (probably) will be controlled by
1016 * the lookup flags */
1017 static intreg_t stat_helper(struct proc *p, const char *path, size_t path_l,
1018 struct kstat *u_stat, int flags)
1021 struct dentry *path_d;
1022 char *t_path = user_strdup_errno(p, path, path_l);
1025 path_d = lookup_dentry(t_path, flags);
1026 user_memdup_free(p, t_path);
1029 kbuf = kmalloc(sizeof(struct kstat), 0);
1032 kref_put(&path_d->d_kref);
1035 stat_inode(path_d->d_inode, kbuf);
1036 kref_put(&path_d->d_kref);
1037 /* TODO: UMEM: pin the memory, copy directly, and skip the kernel buffer */
1038 if (memcpy_to_user_errno(p, u_stat, kbuf, sizeof(struct kstat))) {
1047 /* Follow a final symlink */
1048 static intreg_t sys_stat(struct proc *p, const char *path, size_t path_l,
1049 struct kstat *u_stat)
1051 return stat_helper(p, path, path_l, u_stat, LOOKUP_FOLLOW);
1054 /* Don't follow a final symlink */
1055 static intreg_t sys_lstat(struct proc *p, const char *path, size_t path_l,
1056 struct kstat *u_stat)
1058 return stat_helper(p, path, path_l, u_stat, 0);
1061 intreg_t sys_fcntl(struct proc *p, int fd, int cmd, int arg)
1064 struct file *file = get_file_from_fd(&p->open_files, fd);
1071 retval = insert_file(&p->open_files, file, arg);
1078 retval = p->open_files.fd[fd].fd_flags;
1081 if (arg == FD_CLOEXEC)
1082 file->f_flags |= O_CLOEXEC;
1085 retval = file->f_flags;
1088 /* only allowed to set certain flags. */
1089 arg &= O_FCNTL_FLAGS;
1090 file->f_flags = (file->f_flags & ~O_FCNTL_FLAGS) | arg;
1093 warn("Unsupported fcntl cmd %d\n", cmd);
1095 kref_put(&file->f_kref);
1099 static intreg_t sys_access(struct proc *p, const char *path, size_t path_l,
1103 char *t_path = user_strdup_errno(p, path, path_l);
1106 retval = do_access(t_path, mode);
1107 user_memdup_free(p, t_path);
1108 printd("Access for path: %s retval: %d\n", path, retval);
1116 intreg_t sys_umask(struct proc *p, int mask)
1118 int old_mask = p->fs_env.umask;
1119 p->fs_env.umask = mask & S_PMASK;
1123 intreg_t sys_chmod(struct proc *p, const char *path, size_t path_l, int mode)
1126 char *t_path = user_strdup_errno(p, path, path_l);
1129 retval = do_chmod(t_path, mode);
1130 user_memdup_free(p, t_path);
1138 static intreg_t sys_lseek(struct proc *p, int fd, off_t offset, int whence)
1141 struct file *file = get_file_from_fd(&p->open_files, fd);
1146 ret = file->f_op->llseek(file, offset, whence);
1147 kref_put(&file->f_kref);
1151 intreg_t sys_link(struct proc *p, char *old_path, size_t old_l,
1152 char *new_path, size_t new_l)
1155 char *t_oldpath = user_strdup_errno(p, old_path, old_l);
1156 if (t_oldpath == NULL)
1158 char *t_newpath = user_strdup_errno(p, new_path, new_l);
1159 if (t_newpath == NULL) {
1160 user_memdup_free(p, t_oldpath);
1163 ret = do_link(t_oldpath, t_newpath);
1164 user_memdup_free(p, t_oldpath);
1165 user_memdup_free(p, t_newpath);
1169 intreg_t sys_unlink(struct proc *p, const char *path, size_t path_l)
1172 char *t_path = user_strdup_errno(p, path, path_l);
1175 retval = do_unlink(t_path);
1176 user_memdup_free(p, t_path);
1180 intreg_t sys_symlink(struct proc *p, char *old_path, size_t old_l,
1181 char *new_path, size_t new_l)
1184 char *t_oldpath = user_strdup_errno(p, old_path, old_l);
1185 if (t_oldpath == NULL)
1187 char *t_newpath = user_strdup_errno(p, new_path, new_l);
1188 if (t_newpath == NULL) {
1189 user_memdup_free(p, t_oldpath);
1192 ret = do_symlink(new_path, old_path, S_IRWXU | S_IRWXG | S_IRWXO);
1193 user_memdup_free(p, t_oldpath);
1194 user_memdup_free(p, t_newpath);
1198 intreg_t sys_readlink(struct proc *p, char *path, size_t path_l,
1199 char *u_buf, size_t buf_l)
1203 struct dentry *path_d;
1204 char *t_path = user_strdup_errno(p, path, path_l);
1207 path_d = lookup_dentry(t_path, 0);
1208 user_memdup_free(p, t_path);
1211 symname = path_d->d_inode->i_op->readlink(path_d);
1212 copy_amt = strnlen(symname, buf_l - 1) + 1;
1213 if (memcpy_to_user_errno(p, u_buf, symname, copy_amt)) {
1214 kref_put(&path_d->d_kref);
1218 kref_put(&path_d->d_kref);
1219 printd("READLINK returning %s\n", u_buf);
1223 intreg_t sys_chdir(struct proc *p, const char *path, size_t path_l)
1226 char *t_path = user_strdup_errno(p, path, path_l);
1229 retval = do_chdir(&p->fs_env, t_path);
1230 user_memdup_free(p, t_path);
1238 /* Note cwd_l is not a strlen, it's an absolute size */
1239 intreg_t sys_getcwd(struct proc *p, char *u_cwd, size_t cwd_l)
1243 char *k_cwd = do_getcwd(&p->fs_env, &kfree_this, cwd_l);
1245 return -1; /* errno set by do_getcwd */
1246 if (memcpy_to_user_errno(p, u_cwd, k_cwd, strnlen(k_cwd, cwd_l - 1) + 1))
1252 intreg_t sys_mkdir(struct proc *p, const char *path, size_t path_l, int mode)
1255 char *t_path = user_strdup_errno(p, path, path_l);
1258 mode &= ~p->fs_env.umask;
1259 retval = do_mkdir(t_path, mode);
1260 user_memdup_free(p, t_path);
1264 intreg_t sys_rmdir(struct proc *p, const char *path, size_t path_l)
1267 char *t_path = user_strdup_errno(p, path, path_l);
1270 retval = do_rmdir(t_path);
1271 user_memdup_free(p, t_path);
1275 intreg_t sys_gettimeofday(struct proc *p, int *buf)
1277 static spinlock_t gtod_lock = SPINLOCK_INITIALIZER;
1280 spin_lock(>od_lock);
1283 #if (defined __CONFIG_APPSERVER__)
1284 t0 = ufe(time,0,0,0,0);
1286 // Nanwan's birthday, bitches!!
1289 spin_unlock(>od_lock);
1291 long long dt = read_tsc();
1292 /* TODO: This probably wants its own function, using a struct timeval */
1293 int kbuf[2] = {t0+dt/system_timing.tsc_freq,
1294 (dt%system_timing.tsc_freq)*1000000/system_timing.tsc_freq};
1296 return memcpy_to_user_errno(p,buf,kbuf,sizeof(kbuf));
1299 #define SIZEOF_STRUCT_TERMIOS 60
1300 intreg_t sys_tcgetattr(struct proc *p, int fd, void *termios_p)
1302 int* kbuf = kmalloc(SIZEOF_STRUCT_TERMIOS,0);
1303 int ret = ufe(tcgetattr,fd,PADDR(kbuf),0,0);
1304 if(ret != -1 && memcpy_to_user_errno(p,termios_p,kbuf,SIZEOF_STRUCT_TERMIOS))
1310 intreg_t sys_tcsetattr(struct proc *p, int fd, int optional_actions,
1311 const void *termios_p)
1313 void* kbuf = user_memdup_errno(p,termios_p,SIZEOF_STRUCT_TERMIOS);
1316 int ret = ufe(tcsetattr,fd,optional_actions,PADDR(kbuf),0);
1317 user_memdup_free(p,kbuf);
1321 /* TODO: we don't have any notion of UIDs or GIDs yet, but don't let that stop a
1322 * process from thinking it can do these. The other alternative is to have
1323 * glibc return 0 right away, though someone might want to do something with
1324 * these calls. Someday. */
1325 intreg_t sys_setuid(struct proc *p, uid_t uid)
1330 intreg_t sys_setgid(struct proc *p, gid_t gid)
1335 /************** Syscall Invokation **************/
1337 const static struct sys_table_entry syscall_table[] = {
1338 [SYS_null] = {(syscall_t)sys_null, "null"},
1339 [SYS_block] = {(syscall_t)sys_block, "block"},
1340 [SYS_cache_buster] = {(syscall_t)sys_cache_buster, "buster"},
1341 [SYS_cache_invalidate] = {(syscall_t)sys_cache_invalidate, "wbinv"},
1342 [SYS_reboot] = {(syscall_t)reboot, "reboot!"},
1343 [SYS_cputs] = {(syscall_t)sys_cputs, "cputs"},
1344 [SYS_cgetc] = {(syscall_t)sys_cgetc, "cgetc"},
1345 [SYS_getcpuid] = {(syscall_t)sys_getcpuid, "getcpuid"},
1346 [SYS_getvcoreid] = {(syscall_t)sys_getvcoreid, "getvcoreid"},
1347 [SYS_getpid] = {(syscall_t)sys_getpid, "getpid"},
1348 [SYS_proc_create] = {(syscall_t)sys_proc_create, "proc_create"},
1349 [SYS_proc_run] = {(syscall_t)sys_proc_run, "proc_run"},
1350 [SYS_proc_destroy] = {(syscall_t)sys_proc_destroy, "proc_destroy"},
1351 [SYS_yield] = {(syscall_t)sys_proc_yield, "proc_yield"},
1352 [SYS_change_vcore] = {(syscall_t)sys_change_vcore, "change_vcore"},
1353 [SYS_fork] = {(syscall_t)sys_fork, "fork"},
1354 [SYS_exec] = {(syscall_t)sys_exec, "exec"},
1355 [SYS_trywait] = {(syscall_t)sys_trywait, "trywait"},
1356 [SYS_mmap] = {(syscall_t)sys_mmap, "mmap"},
1357 [SYS_munmap] = {(syscall_t)sys_munmap, "munmap"},
1358 [SYS_mprotect] = {(syscall_t)sys_mprotect, "mprotect"},
1359 [SYS_shared_page_alloc] = {(syscall_t)sys_shared_page_alloc, "pa"},
1360 [SYS_shared_page_free] = {(syscall_t)sys_shared_page_free, "pf"},
1361 [SYS_resource_req] = {(syscall_t)sys_resource_req, "resource_req"},
1362 [SYS_notify] = {(syscall_t)sys_notify, "notify"},
1363 [SYS_self_notify] = {(syscall_t)sys_self_notify, "self_notify"},
1364 [SYS_halt_core] = {(syscall_t)sys_halt_core, "halt_core"},
1365 #ifdef __CONFIG_SERIAL_IO__
1366 [SYS_serial_read] = {(syscall_t)sys_serial_read, "ser_read"},
1367 [SYS_serial_write] = {(syscall_t)sys_serial_write, "ser_write"},
1369 #ifdef __CONFIG_NETWORKING__
1370 [SYS_eth_read] = {(syscall_t)sys_eth_read, "eth_read"},
1371 [SYS_eth_write] = {(syscall_t)sys_eth_write, "eth_write"},
1372 [SYS_eth_get_mac_addr] = {(syscall_t)sys_eth_get_mac_addr, "get_mac"},
1373 [SYS_eth_recv_check] = {(syscall_t)sys_eth_recv_check, "recv_check"},
1375 #ifdef __CONFIG_ARSC_SERVER__
1376 [SYS_init_arsc] = {(syscall_t)sys_init_arsc, "init_arsc"},
1378 [SYS_read] = {(syscall_t)sys_read, "read"},
1379 [SYS_write] = {(syscall_t)sys_write, "write"},
1380 [SYS_open] = {(syscall_t)sys_open, "open"},
1381 [SYS_close] = {(syscall_t)sys_close, "close"},
1382 [SYS_fstat] = {(syscall_t)sys_fstat, "fstat"},
1383 [SYS_stat] = {(syscall_t)sys_stat, "stat"},
1384 [SYS_lstat] = {(syscall_t)sys_lstat, "lstat"},
1385 [SYS_fcntl] = {(syscall_t)sys_fcntl, "fcntl"},
1386 [SYS_access] = {(syscall_t)sys_access, "access"},
1387 [SYS_umask] = {(syscall_t)sys_umask, "umask"},
1388 [SYS_chmod] = {(syscall_t)sys_chmod, "chmod"},
1389 [SYS_lseek] = {(syscall_t)sys_lseek, "lseek"},
1390 [SYS_link] = {(syscall_t)sys_link, "link"},
1391 [SYS_unlink] = {(syscall_t)sys_unlink, "unlink"},
1392 [SYS_symlink] = {(syscall_t)sys_symlink, "symlink"},
1393 [SYS_readlink] = {(syscall_t)sys_readlink, "readlink"},
1394 [SYS_chdir] = {(syscall_t)sys_chdir, "chdir"},
1395 [SYS_getcwd] = {(syscall_t)sys_getcwd, "getcwd"},
1396 [SYS_mkdir] = {(syscall_t)sys_mkdir, "mkdri"},
1397 [SYS_rmdir] = {(syscall_t)sys_rmdir, "rmdir"},
1398 [SYS_gettimeofday] = {(syscall_t)sys_gettimeofday, "gettime"},
1399 [SYS_tcgetattr] = {(syscall_t)sys_tcgetattr, "tcgetattr"},
1400 [SYS_tcsetattr] = {(syscall_t)sys_tcsetattr, "tcsetattr"},
1401 [SYS_setuid] = {(syscall_t)sys_setuid, "setuid"},
1402 [SYS_setgid] = {(syscall_t)sys_setgid, "setgid"}
1405 /* Executes the given syscall.
1407 * Note tf is passed in, which points to the tf of the context on the kernel
1408 * stack. If any syscall needs to block, it needs to save this info, as well as
1411 * This syscall function is used by both local syscall and arsc, and should
1412 * remain oblivious of the caller. */
1413 intreg_t syscall(struct proc *p, uintreg_t sc_num, uintreg_t a0, uintreg_t a1,
1414 uintreg_t a2, uintreg_t a3, uintreg_t a4, uintreg_t a5)
1416 const int max_syscall = sizeof(syscall_table)/sizeof(syscall_table[0]);
1418 uint32_t coreid, vcoreid;
1419 if (systrace_flags & SYSTRACE_ON) {
1420 if ((systrace_flags & SYSTRACE_ALLPROC) || (proc_is_traced(p))) {
1422 vcoreid = proc_get_vcoreid(p, coreid);
1423 if (systrace_flags & SYSTRACE_LOUD) {
1424 printk("[%16llu] Syscall %3d (%12s):(%08p, %08p, %08p, %08p, "
1425 "%08p, %08p) proc: %d core: %d vcore: %d\n", read_tsc(),
1426 sc_num, syscall_table[sc_num].name, a0, a1, a2, a3,
1427 a4, a5, p->pid, coreid, vcoreid);
1429 struct systrace_record *trace;
1430 uintptr_t idx, new_idx;
1432 idx = systrace_bufidx;
1433 new_idx = (idx + 1) % systrace_bufsize;
1434 } while (!atomic_cas_u32(&systrace_bufidx, idx, new_idx));
1435 trace = &systrace_buffer[idx];
1436 trace->timestamp = read_tsc();
1437 trace->syscallno = sc_num;
1444 trace->pid = p->pid;
1445 trace->coreid = coreid;
1446 trace->vcoreid = vcoreid;
1450 if (sc_num > max_syscall || syscall_table[sc_num].call == NULL)
1451 panic("Invalid syscall number %d for proc %x!", sc_num, p);
1453 return syscall_table[sc_num].call(p, a0, a1, a2, a3, a4, a5);
1456 /* Execute the syscall on the local core */
1457 void run_local_syscall(struct syscall *sysc)
1459 struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
1461 /* TODO: (UMEM) assert / pin the memory for the sysc */
1462 user_mem_assert(pcpui->cur_proc, sysc, sizeof(struct syscall),
1463 sizeof(uintptr_t), PTE_USER_RW);
1464 pcpui->cur_sysc = sysc; /* let the core know which sysc it is */
1465 sysc->retval = syscall(pcpui->cur_proc, sysc->num, sysc->arg0, sysc->arg1,
1466 sysc->arg2, sysc->arg3, sysc->arg4, sysc->arg5);
1467 /* Need to re-load pcpui, in case we migrated */
1468 pcpui = &per_cpu_info[core_id()];
1469 finish_sysc(sysc, pcpui->cur_proc);
1470 /* Can unpin (UMEM) at this point */
1471 pcpui->cur_sysc = 0; /* no longer working on sysc */
1474 /* A process can trap and call this function, which will set up the core to
1475 * handle all the syscalls. a.k.a. "sys_debutante(needs, wants)". If there is
1476 * at least one, it will run it directly. */
1477 void prep_syscalls(struct proc *p, struct syscall *sysc, unsigned int nr_syscs)
1480 /* Careful with pcpui here, we could have migrated */
1483 /* For all after the first call, send ourselves a KMSG (TODO). */
1485 warn("Only one supported (Debutante calls: %d)\n", nr_syscs);
1486 /* Call the first one directly. (we already checked to make sure there is
1488 run_local_syscall(sysc);
1491 /* Call this when something happens on the syscall where userspace might want to
1492 * get signaled. Passing p, since the caller should know who the syscall
1493 * belongs to (probably is current).
1495 * You need to have SC_K_LOCK set when you call this. */
1496 void __signal_syscall(struct syscall *sysc, struct proc *p)
1498 struct event_queue *ev_q;
1499 struct event_msg local_msg;
1500 /* User sets the ev_q then atomically sets the flag (races with SC_DONE) */
1501 if (atomic_read(&sysc->flags) & SC_UEVENT) {
1502 rmb(); /* read the ev_q after reading the flag */
1505 memset(&local_msg, 0, sizeof(struct event_msg));
1506 local_msg.ev_type = EV_SYSCALL;
1507 local_msg.ev_arg3 = sysc;
1508 send_event(p, ev_q, &local_msg, 0);
1513 /* Syscall tracing */
1514 static void __init_systrace(void)
1516 systrace_buffer = kmalloc(MAX_SYSTRACES*sizeof(struct systrace_record), 0);
1517 if (!systrace_buffer)
1518 panic("Unable to alloc a trace buffer\n");
1519 systrace_bufidx = 0;
1520 systrace_bufsize = MAX_SYSTRACES;
1521 /* Note we never free the buffer - it's around forever. Feel free to change
1522 * this if you want to change the size or something dynamically. */
1525 /* If you call this while it is running, it will change the mode */
1526 void systrace_start(bool silent)
1528 static bool init = FALSE;
1529 spin_lock_irqsave(&systrace_lock);
1534 systrace_flags = silent ? SYSTRACE_ON : SYSTRACE_ON | SYSTRACE_LOUD;
1535 spin_unlock_irqsave(&systrace_lock);
1538 int systrace_reg(bool all, struct proc *p)
1541 spin_lock_irqsave(&systrace_lock);
1543 printk("Tracing syscalls for all processes\n");
1544 systrace_flags |= SYSTRACE_ALLPROC;
1547 for (int i = 0; i < MAX_NUM_TRACED; i++) {
1548 if (!systrace_procs[i]) {
1549 printk("Tracing syscalls for process %d\n", p->pid);
1550 systrace_procs[i] = p;
1556 spin_unlock_irqsave(&systrace_lock);
1560 void systrace_stop(void)
1562 spin_lock_irqsave(&systrace_lock);
1564 for (int i = 0; i < MAX_NUM_TRACED; i++)
1565 systrace_procs[i] = 0;
1566 spin_unlock_irqsave(&systrace_lock);
1569 /* If you registered a process specifically, then you need to dereg it
1570 * specifically. Or just fully stop, which will do it for all. */
1571 int systrace_dereg(bool all, struct proc *p)
1573 spin_lock_irqsave(&systrace_lock);
1575 printk("No longer tracing syscalls for all processes.\n");
1576 systrace_flags &= ~SYSTRACE_ALLPROC;
1578 for (int i = 0; i < MAX_NUM_TRACED; i++) {
1579 if (systrace_procs[i] == p) {
1580 systrace_procs[i] = 0;
1581 printk("No longer tracing syscalls for process %d\n", p->pid);
1585 spin_unlock_irqsave(&systrace_lock);
1589 /* Regardless of locking, someone could be writing into the buffer */
1590 void systrace_print(bool all, struct proc *p)
1592 spin_lock_irqsave(&systrace_lock);
1593 /* if you want to be clever, you could make this start from the earliest
1594 * timestamp and loop around. Careful of concurrent writes. */
1595 for (int i = 0; i < systrace_bufsize; i++)
1596 if (systrace_buffer[i].timestamp)
1597 printk("[%16llu] Syscall %3d (%12s):(%08p, %08p, %08p, %08p, %08p,"
1598 "%08p) proc: %d core: %d vcore: %d\n",
1599 systrace_buffer[i].timestamp,
1600 systrace_buffer[i].syscallno,
1601 syscall_table[systrace_buffer[i].syscallno].name,
1602 systrace_buffer[i].arg0,
1603 systrace_buffer[i].arg1,
1604 systrace_buffer[i].arg2,
1605 systrace_buffer[i].arg3,
1606 systrace_buffer[i].arg4,
1607 systrace_buffer[i].arg5,
1608 systrace_buffer[i].pid,
1609 systrace_buffer[i].coreid,
1610 systrace_buffer[i].vcoreid);
1611 spin_unlock_irqsave(&systrace_lock);
1614 void systrace_clear_buffer(void)
1616 spin_lock_irqsave(&systrace_lock);
1617 memset(systrace_buffer, 0, sizeof(struct systrace_record) * MAX_SYSTRACES);
1618 spin_unlock_irqsave(&systrace_lock);