Changeset e3c762cd in mainline for generic/src


Ignore:
Timestamp:
2006-05-05T11:59:19Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
de07bcf
Parents:
22cf454d
Message:

Complete implementation of copy_from_uspace() and copy_to_uspace()
for amd64 and ia32. Other architectures still compile and run,
but need to implement their own assembly-only memcpy(), memcpy_from_uspace(),
memcpy_to_uspace() and their failover parts. For these architectures
only dummy implementations are provided.

Location:
generic/src
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • generic/src/ddi/ddi.c

    r22cf454d re3c762cd  
    4141#include <security/cap.h>
    4242#include <mm/frame.h>
    43 #include <mm/page.h>
    4443#include <mm/as.h>
    4544#include <synch/spinlock.h>
     45#include <syscall/copy.h>
    4646#include <arch.h>
    4747#include <align.h>
     
    184184{
    185185        ddi_memarg_t arg;
    186        
    187         copy_from_uspace(&arg, uspace_mem_arg, sizeof(ddi_memarg_t));
     186        int rc;
     187       
     188        rc = copy_from_uspace(&arg, uspace_mem_arg, sizeof(ddi_memarg_t));
     189        if (rc != 0)
     190                return (__native) rc;
     191               
    188192        return (__native) ddi_physmem_map((task_id_t) arg.task_id, ALIGN_DOWN((__address) arg.phys_base, FRAME_SIZE),
    189193                                          ALIGN_DOWN((__address) arg.virt_base, PAGE_SIZE), (count_t) arg.pages,
     
    200204{
    201205        ddi_ioarg_t arg;
    202        
    203         copy_from_uspace(&arg, uspace_io_arg, sizeof(ddi_ioarg_t));
     206        int rc;
     207       
     208        rc = copy_from_uspace(&arg, uspace_io_arg, sizeof(ddi_ioarg_t));
     209        if (rc != 0)
     210                return (__native) rc;
     211               
    204212        return (__native) ddi_iospace_enable((task_id_t) arg.task_id, (__address) arg.ioaddr, (size_t) arg.size);
    205213}
  • generic/src/ipc/irq.c

    r22cf454d re3c762cd  
    4848#include <ipc/irq.h>
    4949#include <atomic.h>
     50#include <syscall/copy.h>
    5051
    5152typedef struct {
     
    121122        irq_code_t *code;
    122123        irq_cmd_t *ucmds;
     124        int rc;
    123125
    124126        code = malloc(sizeof(*code), 0);
    125         copy_from_uspace(code, ucode, sizeof(*code));
     127        rc = copy_from_uspace(code, ucode, sizeof(*code));
     128        if (rc != 0) {
     129                free(code);
     130                return NULL;
     131        }
    126132       
    127133        if (code->cmdcount > IRQ_MAX_PROG_SIZE) {
     
    131137        ucmds = code->cmds;
    132138        code->cmds = malloc(sizeof(code->cmds[0]) * (code->cmdcount), 0);
    133         copy_from_uspace(code->cmds, ucmds, sizeof(code->cmds[0]) * (code->cmdcount));
     139        rc = copy_from_uspace(code->cmds, ucmds, sizeof(code->cmds[0]) * (code->cmdcount));
     140        if (rc != 0) {
     141                free(code->cmds);
     142                free(code);
     143                return NULL;
     144        }
    134145
    135146        return code;
  • generic/src/ipc/sysipc.c

    r22cf454d re3c762cd  
    2929#include <arch.h>
    3030#include <proc/task.h>
    31 
     31#include <proc/thread.h>
    3232#include <errno.h>
    33 #include <mm/page.h>
    3433#include <memstr.h>
    3534#include <debug.h>
     
    3938#include <ipc/ipcrsc.h>
    4039#include <arch/interrupt.h>
    41 
    4240#include <print.h>
    43 #include <arch.h>
    44 #include <proc/thread.h>
     41#include <syscall/copy.h>
    4542
    4643#define GET_CHECK_PHONE(phone,phoneid,err) { \
     
    229226        phone_t *phone;
    230227        int res;
     228        int rc;
    231229
    232230        ipc_call_static_init(&call);
    233         copy_from_uspace(&call.data.args, &question->args, sizeof(call.data.args));
     231        rc = copy_from_uspace(&call.data.args, &question->args, sizeof(call.data.args));
     232        if (rc != 0)
     233                return (__native) rc;
    234234
    235235        GET_CHECK_PHONE(phone, phoneid, return ENOENT);
     
    241241                IPC_SET_RETVAL(call.data, res);
    242242
    243         STRUCT_TO_USPACE(&reply->args, &call.data.args);
     243        rc = STRUCT_TO_USPACE(&reply->args, &call.data.args);
     244        if (rc != 0)
     245                return rc;
    244246
    245247        return 0;
     
    298300        phone_t *phone;
    299301        int res;
     302        int rc;
    300303
    301304        if (check_call_limit())
     
    305308
    306309        call = ipc_call_alloc(0);
    307         copy_from_uspace(&call->data.args, &data->args, sizeof(call->data.args));
     310        rc = copy_from_uspace(&call->data.args, &data->args, sizeof(call->data.args));
     311        if (rc != 0)
     312                return (__native) rc;
    308313        if (!(res=request_preprocess(call)))
    309314                ipc_call(phone, call);
     
    394399        ipc_data_t saved_data;
    395400        int saveddata = 0;
     401        int rc;
    396402
    397403        call = get_call(callid);
     
    403409                saveddata = 1;
    404410        }
    405         copy_from_uspace(&call->data.args, &data->args,
     411        rc = copy_from_uspace(&call->data.args, &data->args,
    406412                         sizeof(call->data.args));
     413        if (rc != 0)
     414                return rc;
    407415
    408416        answer_preprocess(call, saveddata ? &saved_data : NULL);
  • generic/src/mm/as.c

    r22cf454d re3c762cd  
    5858#include <adt/btree.h>
    5959#include <proc/task.h>
     60#include <proc/thread.h>
    6061#include <arch/asm.h>
    6162#include <panic.h>
     
    6970#include <arch/types.h>
    7071#include <typedefs.h>
     72#include <syscall/copy.h>
     73#include <arch/interrupt.h>
    7174
    7275as_operations_t *as_operations = NULL;
     
    478481 *
    479482 * @param page Faulting page.
    480  *
    481  * @return 0 on page fault, 1 on success.
    482  */
    483 int as_page_fault(__address page)
     483 * @param istate Pointer to interrupted state.
     484 *
     485 * @return 0 on page fault, 1 on success or 2 if the fault was caused by copy_to_uspace() or copy_from_uspace().
     486 */
     487int as_page_fault(__address page, istate_t *istate)
    484488{
    485489        pte_t *pte;
     
    497501                 */
    498502                spinlock_unlock(&AS->lock);
    499                 return 0;
     503                goto page_fault;
    500504        }
    501505
     
    507511                spinlock_unlock(&area->lock);
    508512                spinlock_unlock(&AS->lock);
    509                 return 0;               
     513                goto page_fault;               
    510514        }
    511515
     
    555559        spinlock_unlock(&area->lock);
    556560        spinlock_unlock(&AS->lock);
    557         return 1;
     561        return AS_PF_OK;
     562
     563page_fault:
     564        if (!THREAD)
     565                return AS_PF_FAULT;
     566       
     567        if (THREAD->in_copy_from_uspace) {
     568                THREAD->in_copy_from_uspace = false;
     569                istate_set_retaddr(istate, (__address) &memcpy_from_uspace_failover_address);
     570        } else if (THREAD->in_copy_to_uspace) {
     571                THREAD->in_copy_to_uspace = false;
     572                istate_set_retaddr(istate, (__address) &memcpy_to_uspace_failover_address);
     573        } else {
     574                return AS_PF_FAULT;
     575        }
     576
     577        return AS_PF_DEFER;
    558578}
    559579
     
    885905{
    886906        as_area_acptsnd_arg_t arg;
    887        
    888         copy_from_uspace(&arg, uspace_accept_arg, sizeof(as_area_acptsnd_arg_t));
     907        int rc;
     908       
     909        rc = copy_from_uspace(&arg, uspace_accept_arg, sizeof(as_area_acptsnd_arg_t));
     910        if (rc != 0)
     911                return rc;
    889912       
    890913        if (!arg.size)
     
    907930{
    908931        as_area_acptsnd_arg_t arg;
    909        
    910         copy_from_uspace(&arg, uspace_send_arg, sizeof(as_area_acptsnd_arg_t));
     932        int rc;
     933       
     934        rc = copy_from_uspace(&arg, uspace_send_arg, sizeof(as_area_acptsnd_arg_t));
     935        if (rc != 0)
     936                return rc;
    911937
    912938        if (!arg.size)
  • generic/src/mm/slab.c

    r22cf454d re3c762cd  
    176176                slab = data + fsize - sizeof(*slab);
    177177        }
    178                
     178       
    179179        /* Fill in slab structures */
    180180        for (i=0; i < (1 << cache->order); i++)
     
    278278                /* Allow recursion and reclaiming
    279279                 * - this should work, as the slab control structures
    280                  *   are small and do not need to allocte with anything
    281                  *   other ten frame_alloc when they are allocating,
     280                 *   are small and do not need to allocate with anything
     281                 *   other than frame_alloc when they are allocating,
    282282                 *   that's why we should get recursion at most 1-level deep
    283283                 */
     
    880880
    881881        ASSERT(_slab_initialized);
    882         ASSERT( size && size <= (1 << SLAB_MAX_MALLOC_W));
     882        ASSERT(size && size <= (1 << SLAB_MAX_MALLOC_W));
    883883       
    884884        if (size < (1 << SLAB_MIN_MALLOC_W))
     
    890890}
    891891
    892 
    893892void free(void *obj)
    894893{
  • generic/src/printf/vsnprintf.c

    r22cf454d re3c762cd  
    4040
    4141/** Write string to given buffer.
    42  * Write at most data->size characters including trailing zero. According to C99 has snprintf to return number
     42 * Write at most data->size characters including trailing zero. According to C99, snprintf() has to return number
    4343 * of characters that would have been written if enough space had been available. Hence the return value is not
    44  * number of really printed characters but size of input string. Number of really used characters
     44 * number of really printed characters but size of the input string. Number of really used characters
    4545 * is stored in data->len.
    4646 * @param str source string to print
     
    9191        return printf_core(fmt, &ps, ap);
    9292}
    93 
    94 
  • generic/src/proc/task.c

    r22cf454d re3c762cd  
    4949#include <print.h>
    5050#include <elf.h>
    51 
     51#include <syscall/copy.h>
    5252
    5353#ifndef LOADED_PROG_STACK_PAGES_NO
     
    171171 * @param uspace_task_id Userspace address of 8-byte buffer where to store current task ID.
    172172 *
    173  * @return Always returns 0.
     173 * @return 0 on success or an error code from @ref errno.h.
    174174 */
    175175__native sys_task_get_id(task_id_t *uspace_task_id)
     
    179179         * remains constant for the lifespan of the task.
    180180         */
    181         copy_to_uspace(uspace_task_id, &TASK->taskid, sizeof(TASK->taskid));
    182 
    183         return 0;
     181        return (__native) copy_to_uspace(uspace_task_id, &TASK->taskid, sizeof(TASK->taskid));
    184182}
    185183
  • generic/src/proc/thread.c

    r22cf454d re3c762cd  
    6161#include <debug.h>
    6262#include <main/uinit.h>
     63#include <syscall/copy.h>
     64#include <errno.h>
    6365
    6466char *thread_states[] = {"Invalid", "Running", "Sleeping", "Ready", "Entering", "Exiting"}; /**< Thread states */
     
    304306        t->sleep_queue = NULL;
    305307        t->timeout_pending = 0;
     308
     309        t->in_copy_from_uspace = false;
     310        t->in_copy_to_uspace = false;
    306311       
    307312        t->rwlock_holder_type = RWLOCK_NONE;
     
    463468        uspace_arg_t *kernel_uarg;
    464469        __u32 tid;
    465 
    466         copy_from_uspace(namebuf, uspace_name, THREAD_NAME_BUFLEN);
     470        int rc;
     471
     472        rc = copy_from_uspace(namebuf, uspace_name, THREAD_NAME_BUFLEN);
     473        if (rc != 0)
     474                return (__native) rc;
    467475
    468476        kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0);
    469         copy_from_uspace(kernel_uarg, uspace_uarg, sizeof(uspace_arg_t));
     477        rc = copy_from_uspace(kernel_uarg, uspace_uarg, sizeof(uspace_arg_t));
     478        if (rc != 0) {
     479                free(kernel_uarg);
     480                return (__native) rc;
     481        }
    470482
    471483        if ((t = thread_create(uinit, kernel_uarg, TASK, 0, namebuf))) {
     
    477489        }
    478490
    479         return (__native) -1;
     491        return (__native) ENOMEM;
    480492}
    481493
  • generic/src/smp/ipi.c

    r22cf454d re3c762cd  
    4444 * @param ipi Message to broadcast.
    4545 *
    46  * @bugs The decision whether to actually send the IPI must be based
    47  *       on a different criterion. The current version has
    48  *       problems when some of the detected CPUs are marked
    49  *       disabled in machine configuration.
     46 * @bug The decision whether to actually send the IPI must be based
     47 *      on a different criterion. The current version has
     48 *      problems when some of the detected CPUs are marked
     49 *      disabled in machine configuration.
    5050 */
    5151void ipi_broadcast(int ipi)
  • generic/src/synch/waitq.c

    r22cf454d re3c762cd  
    3131 * @brief       Wait queue.
    3232 *
    33  * Wait queue is the basic synchronization primitive upon all
     33 * Wait queue is the basic synchronization primitive upon which all
    3434 * other synchronization primitives build.
    3535 *
Note: See TracChangeset for help on using the changeset viewer.