base_plot( w, x, y, r, g, b ) { BASE[ x + (y * PIXPERLINE) ] = (r << 20) | (g << 10) | b }Note that the above code makes no provision for error checking!
Part B: As given in the problem statement, all windows can be represented by a record with the following field:
plot( w, x, y, r, g, b ) { (* w->plot)( w, x, y, r, g, b ); }Windows contained within the base window could have the following representation, an extension of the representation given above:
sub_plot( w, x, y, r, g, b ) { if ((x > 0) and (y > 0) and (x < w->width) and (y < w-> height) { plot( base, w->basex + x, w->basey + y, r, g, b ) } }This code is only a first-hack at solving the problem, its biggest shortcoming is that it does nothing to prevent a plot operation on a window from overwriting windows contained in that window.
Simple parameters passed in registers will be easy to handle, but if the user runs with the memory management unit turned on, supervisor calls turn off the MMU and the return from trap mechanism turns the MMU back on. As a result, pointers passed by the user (including the user's stack pointer and program counter) will be difficult for the supervisor routine to interpret.
Therefore, the group mechanism must be used to solve the general problem! Consider making one group per file, where that group lists all the users who have special (non-owner and non-public) access to that file. To open a file, the user in question must be a member of the group for that file, and the access requested must correspond to the access allowed by that file for members of that group. This this is short of being universal for two reasons:
First, there is a system-wide constant, ngroups, limiting the number of groups to which a user may belong. Second, all users in a group share the same access rights.
The second shortcoming can be solved only by creating multiple groups for each file. For example, for file f, instead of just fgroup, a list of users with access to f, we will need frgroup, a list of users allowed to read f, fwgroup, a list of users allowed to write f, and frwgroup, a list of users allowed to read and write f. This makes the limit set by ngroups more severe!